Skip to content

Commit

Permalink
[net7.0] Consolidate handlertestbase (#11445)
Browse files Browse the repository at this point in the history
* Consolidate HandlerTestBase code

* - remove classes from blazor tests

* - register correct ApplicationStub

* - use default mauiprogram

* - move stubs back

* - move more stubs back

* - remove frame related fix updates

* - fix viewhandler

* Update ViewHandler.cs

* - move all core specific tests to new project

* - add shared to blazor tests

* - fix build errors

* - comment out Tizen

* - fix font registration

* - scope dokdo registration to test

* - just set WxH if measure are still infinity

* - comment out search bar tests

Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
  • Loading branch information
github-actions[bot] and PureWeen committed Nov 17, 2022
1 parent 91734a8 commit 27c1ee6
Show file tree
Hide file tree
Showing 145 changed files with 866 additions and 784 deletions.
9 changes: 5 additions & 4 deletions Microsoft.Maui-mac.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
"src\\Core\\maps\\src\\Maps.csproj",
"src\\Core\\src\\Core.csproj",
"src\\Core\\tests\\Benchmarks\\Core.Benchmarks.csproj",
"src\\Core\\tests\\DeviceTests.Shared\\Core.DeviceTests.Shared.csproj",
"src\\Core\\tests\\DeviceTests\\Core.DeviceTests.csproj",
"src\\Core\\tests\\UnitTests\\Core.UnitTests.csproj",
"src\\Graphics\\src\\Graphics\\Graphics.csproj",
"src\\Graphics\\src\\Graphics.Skia\\Graphics.Skia.csproj",
"src\\Graphics\\src\\Text.Markdig\\Graphics.Text.Markdig.csproj",
"src\\Essentials\\samples\\Sample.Server.WebAuthenticator\\Essentials.Sample.Server.WebAuthenticator.csproj",
"src\\Essentials\\samples\\Samples\\Essentials.Sample.csproj",
"src\\Essentials\\src\\Essentials.csproj",
"src\\Essentials\\test\\DeviceTests\\Essentials.DeviceTests.csproj",
"src\\Essentials\\test\\UnitTests\\Essentials.UnitTests.csproj",
"src\\Graphics\\src\\Graphics.Skia\\Graphics.Skia.csproj",
"src\\Graphics\\src\\Graphics\\Graphics.csproj",
"src\\Graphics\\src\\Text.Markdig\\Graphics.Text.Markdig.csproj",
"src\\SingleProject\\Resizetizer\\src\\Resizetizer.csproj",
"src\\SingleProject\\Resizetizer\\test\\UnitTests\\Resizetizer.UnitTests.csproj",
"src\\Templates\\src\\Microsoft.Maui.Templates.csproj",
Expand All @@ -65,4 +66,4 @@
"src\\Workload\\Microsoft.NET.Sdk.Maui\\Microsoft.NET.Sdk.Maui.csproj"
]
}
}
}
9 changes: 8 additions & 1 deletion Microsoft.Maui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SharedSource", "SharedSourc
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks.Droid", "src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj", "{5B56A734-D53C-4635-A53E-F889FCFCDD66}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maps", "src\Core\maps\src\Maps.csproj", "{E8728693-3537-4007-A4DB-9F9634548755}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maps", "src\Core\maps\src\Maps.csproj", "{E8728693-3537-4007-A4DB-9F9634548755}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Graphics", "Graphics", "{E4884871-4A1B-43BC-814F-E3D6E52B1673}"
EndProject
Expand Down Expand Up @@ -253,6 +253,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphicsTester.Skia.Gtk", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.Core.Design.UnitTests", "src\Controls\tests\Core.Design.UnitTests\Controls.Core.Design.UnitTests.csproj", "{F68932B0-81A2-4CC3-A4F7-28091EE91B23}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.DeviceTests.Shared", "src\Core\tests\DeviceTests.Shared\Core.DeviceTests.Shared.csproj", "{66CC98E3-6A1A-4C44-A23C-B575E82106EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -631,6 +633,10 @@ Global
{F68932B0-81A2-4CC3-A4F7-28091EE91B23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F68932B0-81A2-4CC3-A4F7-28091EE91B23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F68932B0-81A2-4CC3-A4F7-28091EE91B23}.Release|Any CPU.Build.0 = Release|Any CPU
{66CC98E3-6A1A-4C44-A23C-B575E82106EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66CC98E3-6A1A-4C44-A23C-B575E82106EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66CC98E3-6A1A-4C44-A23C-B575E82106EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66CC98E3-6A1A-4C44-A23C-B575E82106EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -748,6 +754,7 @@ Global
{F26D31D3-CE4C-4F32-A77F-E2905C948674} = {42AB9AE1-631D-4AD4-85B7-910FF0940BDB}
{F351A992-18E4-473C-8ADD-2BA0BAA7B5A2} = {1BA0121E-0B83-4C8F-81BE-C293E7E35DCE}
{F68932B0-81A2-4CC3-A4F7-28091EE91B23} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{66CC98E3-6A1A-4C44-A23C-B575E82106EC} = {C564DDD6-DE79-45CD-88EA-3F690481572A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
Expand Down
13 changes: 10 additions & 3 deletions _omnisharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Controls", "Controls", "{45
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E1082E26-D700-4127-9329-66D673FD2D55}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maui.Controls.Sample", "src\Controls\samples\Controls.Sample\Maui.Controls.Sample.csproj", "{B8DC1324-977C-46F1-B697-9064ADE6099A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.Controls.Sample", "src\Controls\samples\Controls.Sample\Maui.Controls.Sample.csproj", "{B8DC1324-977C-46F1-B697-9064ADE6099A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compatibility", "Compatibility", "{123AA89E-1638-4E0E-B828-B8F9F9F906A2}"
EndProject
Expand Down Expand Up @@ -90,9 +90,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtils.DeviceTests.Runne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.DeviceTests", "src\Core\tests\DeviceTests\Core.DeviceTests.csproj", "{50BCB5CD-DC2A-42AA-B921-D99B19625CE1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.Foldable", "src\Controls\Foldable\src\Controls.Foldable.csproj", "{F0A48792-ACD7-4B72-83EB-C56A70FA5A3A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.Foldable", "src\Controls\Foldable\src\Controls.Foldable.csproj", "{F0A48792-ACD7-4B72-83EB-C56A70FA5A3A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maps", "src\Core\maps\src\Maps.csproj", "{1C9F9D5A-2CF7-4ADB-A9F5-672ACC05B035}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maps", "src\Core\maps\src\Maps.csproj", "{1C9F9D5A-2CF7-4ADB-A9F5-672ACC05B035}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Graphics", "Graphics", "{E4884871-4A1B-43BC-814F-E3D6E52B1673}"
EndProject
Expand All @@ -104,6 +104,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graphics", "src\Graphics\sr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graphics.Tests", "src\Graphics\tests\Graphics.Tests\Graphics.Tests.csproj", "{56BBFDBD-254F-42B6-9984-46E19C53FB00}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.DeviceTests.Shared", "src\Core\tests\DeviceTests.Shared\Core.DeviceTests.Shared.csproj", "{B000E53D-AB58-42E3-8964-2B3F30ECC886}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -229,6 +231,10 @@ Global
{56BBFDBD-254F-42B6-9984-46E19C53FB00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56BBFDBD-254F-42B6-9984-46E19C53FB00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56BBFDBD-254F-42B6-9984-46E19C53FB00}.Release|Any CPU.Build.0 = Release|Any CPU
{B000E53D-AB58-42E3-8964-2B3F30ECC886}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B000E53D-AB58-42E3-8964-2B3F30ECC886}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B000E53D-AB58-42E3-8964-2B3F30ECC886}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B000E53D-AB58-42E3-8964-2B3F30ECC886}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -276,6 +282,7 @@ Global
{936C47A9-A7EA-4FBD-8733-CED1D4100E69} = {E4884871-4A1B-43BC-814F-E3D6E52B1673}
{CF056C95-51C4-4366-9D06-41D2B15EFEE4} = {42AB9AE1-631D-4AD4-85B7-910FF0940BDB}
{56BBFDBD-254F-42B6-9984-46E19C53FB00} = {936C47A9-A7EA-4FBD-8733-CED1D4100E69}
{B000E53D-AB58-42E3-8964-2B3F30ECC886} = {C564DDD6-DE79-45CD-88EA-3F690481572A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
Expand Down
1 change: 1 addition & 0 deletions src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.DeviceTests;

namespace Microsoft.Maui.MauiBlazorWebView.DeviceTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Core\tests\DeviceTests.Shared\Core.DeviceTests.Shared.csproj" />
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests\TestUtils.DeviceTests.csproj" />
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests.Runners\TestUtils.DeviceTests.Runners.csproj" />
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests.Runners.SourceGen\TestUtils.DeviceTests.Runners.SourceGen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
Expand Down
42 changes: 9 additions & 33 deletions src/BlazorWebView/tests/MauiDeviceTests/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Maui.Hosting;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Maui.DeviceTests;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.Maui.TestUtils.DeviceTests.Runners;

Expand All @@ -7,41 +10,14 @@ namespace Microsoft.Maui.MauiBlazorWebView.DeviceTests
public static class MauiProgram
{
#if ANDROID
public static Android.Content.Context CurrentContext { get; private set; }
public static Android.Content.Context CurrentContext => MauiProgramDefaults.DefaultContext;
#elif WINDOWS
public static UI.Xaml.Window DefaultWindow { get; private set; }
public static UI.Xaml.Window DefaultWindow => MauiProgramDefaults.DefaultWindow;
#endif
public static MauiApp CreateMauiApp()
{
var x = MauiApp.CreateBuilder();
x.ConfigureLifecycleEvents(life =>
public static MauiApp CreateMauiApp() =>
MauiProgramDefaults.CreateMauiApp(new List<Assembly>()
{
#if ANDROID
life.AddAndroid(android =>
{
android.OnCreate((a, b) => CurrentContext = a);
});
#elif WINDOWS
life.AddWindows(windows =>
{
windows.OnWindowCreated((w) => DefaultWindow = w);
});
#endif
typeof(MauiProgram).Assembly
});

x.ConfigureTests(new TestOptions
{
Assemblies =
{
typeof(MauiProgram).Assembly
},
})
.UseHeadlessRunner(new HeadlessRunnerOptions
{
RequiresUIContext = true,
})
.UseVisualRunner();
return x.Build();
}
}
}
56 changes: 0 additions & 56 deletions src/BlazorWebView/tests/MauiDeviceTests/Stubs/ContextStub.cs

This file was deleted.

28 changes: 0 additions & 28 deletions src/BlazorWebView/tests/MauiDeviceTests/TestBase.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Core\tests\DeviceTests.Shared\Core.DeviceTests.Shared.csproj" />
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests\TestUtils.DeviceTests.csproj" />
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests.Runners\TestUtils.DeviceTests.Runners.csproj" />
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests.Runners.SourceGen\TestUtils.DeviceTests.Runners.SourceGen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
Expand Down
55 changes: 55 additions & 0 deletions src/Controls/tests/DeviceTests/ControlsDeviceTestExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;
using Xunit;
#if ANDROID || IOS || MACCATALYST
using ShellHandler = Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer;
#endif

namespace Microsoft.Maui.DeviceTests
{
public static class ControlsDeviceTestExtensions
{
public static MauiAppBuilder ConfigureTestBuilder(this MauiAppBuilder mauiAppBuilder)
{
return
mauiAppBuilder
.RemapForControls()
.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.Window), typeof(WindowHandlerStub));
handlers.AddHandler(typeof(Controls.ContentPage), typeof(PageHandler));
handlers.AddHandler(typeof(MauiAppNewWindowStub), typeof(ApplicationHandler));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace Microsoft.Maui.DeviceTests
{
public partial class HandlerTestBase
public partial class ControlsHandlerTestBase
{
protected bool GetIsAccessibilityElement(IViewHandler viewHandler) =>
GetSemanticPlatformElement(viewHandler).ImportantForAccessibility == ImportantForAccessibility.Yes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Maui.DeviceTests
{
public partial class HandlerTestBase
public partial class ControlsHandlerTestBase
{
protected bool GetIsAccessibilityElement(IViewHandler viewHandler) =>
((AccessibilityView)((DependencyObject)viewHandler.PlatformView).GetValue(NativeAutomationProperties.AccessibilityViewProperty))
Expand Down
Loading

0 comments on commit 27c1ee6

Please sign in to comment.