-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update BlazorWebView Device Tests to have longer timesouts and more r…
…etries (#21318) * WIP: Update BlazorWebView Device Tests to use newer handle test base classes * Remove unused IDisposable interface * Increase timeouts, and add more retries * Remove unused test base class code * Remove a lot of unused stuff
- Loading branch information
Showing
17 changed files
with
262 additions
and
220 deletions.
There are no files selected for viewing
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 | ||
}); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/BlazorWebView/tests/MauiDeviceTests/ControlsHandlerTestBase.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,21 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Hosting; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public partial class ControlsHandlerTestBase : HandlerTestBase | ||
{ | ||
protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) | ||
{ | ||
mauiAppBuilder.Services.AddSingleton<IApplication>((_) => new Application()); | ||
return mauiAppBuilder.ConfigureTestBuilder(); | ||
} | ||
|
||
protected THandler CreateHandler<THandler>(IElement view) | ||
where THandler : IElementHandler, new() | ||
{ | ||
return CreateHandler<THandler>(view, MauiContext); | ||
} | ||
} | ||
} |
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
20 changes: 0 additions & 20 deletions
20
src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.Android.cs
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.Windows.cs
This file was deleted.
Oops, something went wrong.
90 changes: 0 additions & 90 deletions
90
src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.cs
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.iOS.cs
This file was deleted.
Oops, something went wrong.
114 changes: 114 additions & 0 deletions
114
src/BlazorWebView/tests/MauiDeviceTests/MauiAppNewWindowStub.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,114 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Maui.ApplicationModel; | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace Microsoft.Maui.DeviceTests.Stubs | ||
{ | ||
class MauiAppNewWindowStub : IApplication | ||
{ | ||
readonly IWindow _window; | ||
Window Window => _window as Window; | ||
|
||
MauiWinUIWindow _plaformWindow; | ||
IElementHandler _handler; | ||
|
||
public MauiAppNewWindowStub(IWindow window) | ||
{ | ||
_window = window; | ||
Window.HandlerChanged += OnWindowHandlerChanged; | ||
} | ||
|
||
void OnWindowHandlerChanged(object sender, EventArgs e) | ||
{ | ||
if (_window.Handler?.PlatformView is not MauiWinUIWindow platformWindow) | ||
return; | ||
|
||
if (_plaformWindow is null) | ||
{ | ||
_plaformWindow = platformWindow; | ||
InvokeWindowCreated(); | ||
_plaformWindow.Activated += OnActivated; | ||
_plaformWindow.Closed += OnClosed; | ||
} | ||
} | ||
|
||
public IReadOnlyList<IWindow> Windows => new List<IWindow>() { _window }; | ||
|
||
public IElementHandler Handler | ||
{ | ||
get => _handler; | ||
set | ||
{ | ||
_handler = value; | ||
|
||
if (value is not null) | ||
{ | ||
InvokeWindowCreated(); | ||
} | ||
} | ||
} | ||
|
||
void InvokeWindowCreated() | ||
{ | ||
if (Window is null && _window is not null) | ||
{ | ||
_window.Created(); | ||
} | ||
} | ||
|
||
void InvokeWindowDestroying() | ||
{ | ||
if (Window is null) | ||
{ | ||
_window.Destroying(); | ||
} | ||
} | ||
|
||
void OnClosed(object sender, UI.Xaml.WindowEventArgs args) | ||
{ | ||
if (_plaformWindow is not null) | ||
{ | ||
_plaformWindow.Activated -= OnActivated; | ||
_plaformWindow.Closed -= OnClosed; | ||
_plaformWindow = null; | ||
InvokeWindowDestroying(); | ||
} | ||
} | ||
|
||
void OnActivated(object sender, UI.Xaml.WindowActivatedEventArgs args) | ||
{ | ||
if (args.WindowActivationState != UI.Xaml.WindowActivationState.Deactivated) | ||
{ | ||
if (Window is null) | ||
{ | ||
_window.Activated(); | ||
} | ||
} | ||
} | ||
|
||
public IElement Parent => null; | ||
|
||
public AppTheme UserAppTheme { get; set; } | ||
|
||
public void CloseWindow(IWindow window) | ||
{ | ||
Handler?.Invoke(nameof(IApplication.CloseWindow), window); | ||
} | ||
|
||
public IWindow CreateWindow(IActivationState activationState) | ||
{ | ||
return _window; | ||
} | ||
|
||
public void OpenWindow(IWindow window) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void ThemeChanged() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.