From e3562536196f3f4ddaaf83a0c5968c0b7db15d44 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 2 Apr 2024 16:36:11 +0200 Subject: [PATCH] test: Additional launch assertions for ContentIsland --- .../SamplesApp.Shared/MainPage.xaml.cs | 1 + .../Views/Controls/SampleChooserControl.xaml.cs | 6 ++++++ .../WpfDisplayInformationExtension.cs | 6 +++--- .../UnoXamlHostBase.host.cs | 1 + src/Uno.UI/UI/Content/IContentIslandHost.cs | 17 +++++++++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/Uno.UI/UI/Content/IContentIslandHost.cs diff --git a/src/SamplesApp/SamplesApp.Shared/MainPage.xaml.cs b/src/SamplesApp/SamplesApp.Shared/MainPage.xaml.cs index 3153df7ad0e6..9d2667009743 100644 --- a/src/SamplesApp/SamplesApp.Shared/MainPage.xaml.cs +++ b/src/SamplesApp/SamplesApp.Shared/MainPage.xaml.cs @@ -2,6 +2,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Navigation; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace SamplesApp { diff --git a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/SampleChooserControl.xaml.cs b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/SampleChooserControl.xaml.cs index 2bed176c8b72..2669a2564791 100644 --- a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/SampleChooserControl.xaml.cs +++ b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/SampleChooserControl.xaml.cs @@ -62,6 +62,12 @@ private void OnXamlRootChanged(XamlRoot sender, XamlRootChangedEventArgs args) protected override Size MeasureOverride(Size availableSize) { + Assert.IsTrue(IsLoaded, "The control should be loaded before the first measure."); + Assert.IsNotNull(XamlRoot, "Child should not be null."); +#if HAS_UNO + Assert.IsNotNull(XamlRoot?.VisualTree.ContentRoot.CompositionContent, "ContentIsland of the ContentRoot should have been set by now."); +#endif + if (_initialMeasure && availableSize == default) { _initialMeasure = false; diff --git a/src/Uno.UI.Runtime.Skia.Wpf/Extensions/WpfDisplayInformationExtension.cs b/src/Uno.UI.Runtime.Skia.Wpf/Extensions/WpfDisplayInformationExtension.cs index d18fbbf2c374..94c0725f87c2 100644 --- a/src/Uno.UI.Runtime.Skia.Wpf/Extensions/WpfDisplayInformationExtension.cs +++ b/src/Uno.UI.Runtime.Skia.Wpf/Extensions/WpfDisplayInformationExtension.cs @@ -2,10 +2,10 @@ using System; using System.Windows; using System.Windows.Media; -using Windows.ApplicationModel.Core; -using Windows.Graphics.Display; using Microsoft.UI.Windowing; using Uno.UI.Runtime.Skia.Wpf.UI.Controls; +using Windows.ApplicationModel.Core; +using Windows.Graphics.Display; using WpfApplication = global::System.Windows.Application; using WpfWindow = global::System.Windows.Window; @@ -41,7 +41,7 @@ private WpfWindow GetWindow() // TODO: this is a ridiculous amount of indirection, find something better if (!AppWindow.TryGetFromWindowId(_displayInformation.WindowId, out var appWindow) || Microsoft.UI.Xaml.Window.GetFromAppWindow(appWindow) is not { } window || - UnoWpfWindow.GetWpfWindowFromWindow(window) is not { } wpfWindow) + UnoWpfWindow.GetFromWinUIWindow(window) is not { } wpfWindow) { throw new InvalidOperationException($"{nameof(WpfDisplayInformationExtension)} couldn't find a WPF window."); } diff --git a/src/Uno.UI.XamlHost.Skia.Wpf/UnoXamlHostBase.host.cs b/src/Uno.UI.XamlHost.Skia.Wpf/UnoXamlHostBase.host.cs index 0ef5d02f54fe..6d48f6f0c6ab 100644 --- a/src/Uno.UI.XamlHost.Skia.Wpf/UnoXamlHostBase.host.cs +++ b/src/Uno.UI.XamlHost.Skia.Wpf/UnoXamlHostBase.host.cs @@ -10,6 +10,7 @@ using Uno.UI.Runtime.Skia.Wpf.Extensions; using Uno.UI.Hosting; using Uno.UI.Runtime.Skia.Wpf; +using Microsoft.UI.Content; namespace Uno.UI.XamlHost.Skia.Wpf; diff --git a/src/Uno.UI/UI/Content/IContentIslandHost.cs b/src/Uno.UI/UI/Content/IContentIslandHost.cs new file mode 100644 index 000000000000..abd1ddcfa130 --- /dev/null +++ b/src/Uno.UI/UI/Content/IContentIslandHost.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Uno.UI.Content; + +/// +/// Represents a hosting site for a ContentIsland. +/// +internal interface IContentIslandHost +{ + float RasterizationScale { get; } + + bool IsSiteVisible { get; } +}