-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update BlazorWebView Device Tests to have longer timesouts and more retries #21318
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
911c75d
WIP: Update BlazorWebView Device Tests to use newer handle test base …
Eilon 8ade2a6
Remove unused IDisposable interface
Eilon d92ca97
Increase timeouts, and add more retries
Eilon 534826e
Remove unused test base class code
Eilon 2cec24c
Remove a lot of unused stuff
Eilon File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/BlazorWebView/tests/MauiDeviceTests/ApplicationStub.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace Microsoft.Maui.DeviceTests.Stubs | ||
{ | ||
public class ApplicationStub : Application | ||
{ | ||
Window _window; | ||
|
||
public ApplicationStub() : base() | ||
{ | ||
} | ||
|
||
public void SetWindow(Window window) => _window = window; | ||
|
||
protected override Window CreateWindow(IActivationState activationState) | ||
{ | ||
return _window ?? base.CreateWindow(activationState); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/BlazorWebView/tests/MauiDeviceTests/ControlsDeviceTestExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.DeviceTests.Stubs; | ||
using Microsoft.Maui.Handlers; | ||
using Microsoft.Maui.Hosting; | ||
using Microsoft.Maui.LifecycleEvents; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public static class ControlsDeviceTestExtensions | ||
{ | ||
public static MauiAppBuilder ConfigureTestBuilder(this MauiAppBuilder mauiAppBuilder) | ||
{ | ||
return | ||
mauiAppBuilder | ||
.ConfigureLifecycleEvents(lifecycle => | ||
{ | ||
#if IOS || MACCATALYST | ||
lifecycle | ||
.AddiOS(iOS => iOS | ||
.OpenUrl((app, url, options) => | ||
ApplicationModel.Platform.OpenUrl(app, url, options)) | ||
.ContinueUserActivity((application, userActivity, completionHandler) => | ||
ApplicationModel.Platform.ContinueUserActivity(application, userActivity, completionHandler)) | ||
.PerformActionForShortcutItem((application, shortcutItem, completionHandler) => | ||
ApplicationModel.Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler))); | ||
#elif WINDOWS | ||
lifecycle | ||
.AddWindows(windows => | ||
{ | ||
windows | ||
.OnLaunched((app, e) => | ||
ApplicationModel.Platform.OnLaunched(e)); | ||
windows | ||
.OnActivated((window, e) => | ||
ApplicationModel.Platform.OnActivated(window, e)); | ||
}); | ||
#endif | ||
}) | ||
.ConfigureMauiHandlers(handlers => | ||
{ | ||
handlers.AddHandler(typeof(Editor), typeof(EditorHandler)); | ||
handlers.AddHandler(typeof(VerticalStackLayout), typeof(LayoutHandler)); | ||
handlers.AddHandler(typeof(Controls.ContentPage), typeof(PageHandler)); | ||
#if WINDOWS | ||
handlers.AddHandler(typeof(MauiAppNewWindowStub), typeof(ApplicationHandler)); | ||
#endif | ||
}); | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/BlazorWebView/tests/MauiDeviceTests/ControlsHandlerTestBase.Android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Android.Content; | ||
using Android.OS; | ||
using Android.Views; | ||
using AndroidX.AppCompat.App; | ||
using AndroidX.AppCompat.Widget; | ||
using AndroidX.Fragment.App; | ||
using Microsoft.Maui.Platform; | ||
using ALayoutInflater = Android.Views.LayoutInflater; | ||
using AView = Android.Views.View; | ||
using AViewGroup = Android.Views.ViewGroup; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public partial class ControlsHandlerTestBase | ||
{ | ||
Task SetupWindowForTests<THandler>(IWindow window, Func<Task> runTests, IMauiContext mauiContext = null) | ||
where THandler : class, IElementHandler | ||
{ | ||
mauiContext ??= MauiContext; | ||
return InvokeOnMainThreadAsync(async () => | ||
{ | ||
AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup; | ||
var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context); | ||
var viewFragment = new WindowTestFragment(MauiContext, window); | ||
|
||
try | ||
{ | ||
linearLayoutCompat.Id = AView.GenerateViewId(); | ||
rootView.AddView(linearLayoutCompat); | ||
|
||
await viewFragment.FinishedLoading; | ||
await runTests.Invoke(); | ||
} | ||
finally | ||
{ | ||
window.Handler?.DisconnectHandler(); | ||
|
||
rootView.RemoveView(linearLayoutCompat); | ||
|
||
await viewFragment.FinishedDestroying; | ||
|
||
// Unset the Support Action bar if the calling code has set the support action bar | ||
if (MauiContext.Context.GetActivity() is AppCompatActivity aca) | ||
{ | ||
aca.SetSupportActionBar(null); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
class WindowTestFragment : Fragment | ||
{ | ||
TaskCompletionSource<bool> _taskCompletionSource = new TaskCompletionSource<bool>(); | ||
readonly IMauiContext _mauiContext; | ||
readonly IWindow _window; | ||
|
||
public IMauiContext ScopedMauiContext { get; set; } | ||
|
||
public Task FinishedLoading => _taskCompletionSource.Task; | ||
|
||
public Task FinishedDestroying => _taskCompletionSource.Task; | ||
|
||
public FakeActivityRootView FakeActivityRootView { get; set; } | ||
|
||
public WindowTestFragment(IMauiContext mauiContext, IWindow window) | ||
{ | ||
_mauiContext = mauiContext; | ||
_window = window; | ||
} | ||
|
||
public static IMauiContext MakeScoped(IMauiContext mauiContext, | ||
LayoutInflater layoutInflater = null, | ||
FragmentManager fragmentManager = null, | ||
Android.Content.Context context = null, | ||
bool registerNewNavigationRoot = false) | ||
{ | ||
var scopedContext = new MauiContext(mauiContext.Services); | ||
|
||
if (registerNewNavigationRoot) | ||
{ | ||
if (fragmentManager == null) | ||
throw new InvalidOperationException("If you're creating a new Navigation Root you need to use a new Fragment Manager"); | ||
} | ||
|
||
return scopedContext; | ||
} | ||
|
||
public override AView OnCreateView(ALayoutInflater inflater, AViewGroup container, Bundle savedInstanceState) | ||
{ | ||
ScopedMauiContext = MakeScoped(_mauiContext, layoutInflater: inflater, fragmentManager: ChildFragmentManager, registerNewNavigationRoot: true); | ||
var handler = _window.ToHandler(ScopedMauiContext); | ||
|
||
FakeActivityRootView = new FakeActivityRootView(ScopedMauiContext.Context); | ||
FakeActivityRootView.LayoutParameters = new LinearLayoutCompat.LayoutParams(AViewGroup.LayoutParams.MatchParent, AViewGroup.LayoutParams.MatchParent); | ||
|
||
return FakeActivityRootView; | ||
} | ||
} | ||
|
||
public class FakeActivityRootView : FitWindowsFrameLayout | ||
{ | ||
public FakeActivityRootView(Context context) : base(context) | ||
{ | ||
Id = AView.GenerateViewId(); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/BlazorWebView/tests/MauiDeviceTests/ControlsHandlerTestBase.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.DeviceTests.Stubs; | ||
using Microsoft.Maui.Platform; | ||
using WWindow = Microsoft.UI.Xaml.Window; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public partial class ControlsHandlerTestBase | ||
{ | ||
Task SetupWindowForTests<THandler>(IWindow window, Func<Task> runTests, IMauiContext mauiContext = null) | ||
where THandler : class, IElementHandler | ||
{ | ||
mauiContext ??= MauiContext; | ||
return InvokeOnMainThreadAsync(async () => | ||
{ | ||
var appStub = new MauiAppNewWindowStub(window); | ||
|
||
WWindow newWindow = null; | ||
try | ||
{ | ||
ApplicationExtensions.CreatePlatformWindow(UI.Xaml.Application.Current, appStub, new Handlers.OpenWindowRequest()); | ||
newWindow = window.Handler.PlatformView as WWindow; | ||
await runTests.Invoke(); | ||
} | ||
finally | ||
{ | ||
window.Handler?.DisconnectHandler(); | ||
await Task.Delay(10); | ||
newWindow?.Close(); | ||
appStub.Handler?.DisconnectHandler(); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file and the next few files (AppStub, ControlHandlerTestBase, etc.) are copied from the MAUI Controls DeviceTests, but I then removed anything that wasn't needed by the BlazorWebView tests (it was too hard to get it to compile, and too hard to directly reuse the types).