From 794ad251a345f5830f008ec37e5edeca16925f42 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Mon, 6 Mar 2023 13:57:05 +0100 Subject: [PATCH] fix: Correctly run FullWindow tests in context of Uno Island --- src/SamplesApp/SamplesApp.Shared/App.xaml.cs | 4 ++ .../Controls/UnitTest/UnitTestsControl.cs | 7 +++ .../common/TestServices.WindowHelper.cs | 44 +++++++++++++++++-- .../Tests/Windows_UI_Xaml/Given_XamlRoot.cs | 5 +++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/SamplesApp/SamplesApp.Shared/App.xaml.cs b/src/SamplesApp/SamplesApp.Shared/App.xaml.cs index 55496762d9..5af44bf6ce 100644 --- a/src/SamplesApp/SamplesApp.Shared/App.xaml.cs +++ b/src/SamplesApp/SamplesApp.Shared/App.xaml.cs @@ -656,6 +656,10 @@ namespace SamplesApp public void AssertIssue8641NativeOverlayInitialized() { #if __SKIA__ + if (Uno.UI.Xaml.Core.CoreServices.Instance.InitializationType == Uno.UI.Xaml.Core.InitializationType.IslandsOnly) + { + return; + } // Temporarily add a TextBox to the current page's content to verify native overlay is available Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Frame; var textBox = new TextBox(); diff --git a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UnitTest/UnitTestsControl.cs b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UnitTest/UnitTestsControl.cs index e8cae86c6b..88d6ef7e47 100644 --- a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UnitTest/UnitTestsControl.cs +++ b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UnitTest/UnitTestsControl.cs @@ -87,6 +87,13 @@ namespace Uno.UI.Samples.Tests Private.Infrastructure.TestServices.WindowHelper.CurrentTestWindow = Windows.UI.Xaml.Window.Current; + Private.Infrastructure.TestServices.WindowHelper.IsXamlIsland = +#if HAS_UNO + Uno.UI.Xaml.Core.CoreServices.Instance.InitializationType == Xaml.Core.InitializationType.IslandsOnly; +#else + false; +#endif + DataContext = null; SampleChooserViewModel.Instance.SampleChanging += OnSampleChanging; diff --git a/src/Uno.UI.RuntimeTests/IntegrationTests/common/TestServices.WindowHelper.cs b/src/Uno.UI.RuntimeTests/IntegrationTests/common/TestServices.WindowHelper.cs index f7e6d4f856..4d75446840 100644 --- a/src/Uno.UI.RuntimeTests/IntegrationTests/common/TestServices.WindowHelper.cs +++ b/src/Uno.UI.RuntimeTests/IntegrationTests/common/TestServices.WindowHelper.cs @@ -7,6 +7,8 @@ using System.Runtime.CompilerServices; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Tests.Enterprise; using Windows.UI.Core; +using Uno.Helpers; +using MUXControlsTestApp.Utilities; #if NETFX_CORE using Uno.UI.Extensions; #elif __IOS__ @@ -27,6 +29,8 @@ namespace Private.Infrastructure private static UIElement _originalWindowContent; public static XamlRoot XamlRoot { get; set; } + + public static bool IsXamlIsland { get; set; } public static Windows.UI.Xaml.Window CurrentTestWindow { @@ -46,13 +50,20 @@ namespace Private.Infrastructure public static UIElement WindowContent { get => UseActualWindowRoot - ? CurrentTestWindow.Content + ? (IsXamlIsland ? GetXamlIslandRootContentControl().Content as UIElement : CurrentTestWindow.Content) : EmbeddedTestRoot.getContent?.Invoke(); internal set { if (UseActualWindowRoot) { - CurrentTestWindow.Content = value; + if (IsXamlIsland) + { + GetXamlIslandRootContentControl().Content = value; + } + else + { + CurrentTestWindow.Content = value; + } } else if (EmbeddedTestRoot.setContent is { } setter) { @@ -65,16 +76,41 @@ namespace Private.Infrastructure } } + private static ContentControl GetXamlIslandRootContentControl() + { + var islandContentRoot = EmbeddedTestRoot.control.XamlRoot.Content; + if (islandContentRoot is not ContentControl contentControl) + { + contentControl = VisualTreeUtils.FindVisualChildByType(islandContentRoot); + } + + return contentControl; + } + public static void SaveOriginalWindowContent() { - _originalWindowContent = CurrentTestWindow.Content; + if (IsXamlIsland) + { + _originalWindowContent = GetXamlIslandRootContentControl().Content as UIElement; + } + else + { + _originalWindowContent = CurrentTestWindow.Content; + } } public static void RestoreOriginalWindowContent() { if (_originalWindowContent != null) { - CurrentTestWindow.Content = _originalWindowContent; + if (IsXamlIsland) + { + GetXamlIslandRootContentControl().Content = _originalWindowContent; + } + else + { + CurrentTestWindow.Content = _originalWindowContent; + } _originalWindowContent = null; } } diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_XamlRoot.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_XamlRoot.cs index cc41c23d68..d01d948630 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_XamlRoot.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_XamlRoot.cs @@ -12,6 +12,11 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml [RunsOnUIThread] public async Task When_Loaded_Matches_Window_Root() { + if (TestServices.WindowHelper.IsXamlIsland) + { + return; + } + var border = new Border(); var completionSource = new TaskCompletionSource(); border.Loaded += (s, e) => -- GitLab