Skip to content
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

Make Samples app use fluent styles by default #16762

Merged
merged 52 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e100b18
refactor: Make Samples app Fluent by default
MartinZikmund Jan 12, 2024
638d143
chore: Address comments
MartinZikmund Jan 16, 2024
a8d9cb8
chore: Re-add usings
MartinZikmund Jan 16, 2024
3ce45e8
chore: Adjust When_ComboBox_Theme_Changed
MartinZikmund Jan 17, 2024
d6950df
chore: Adjust Given_TextBox.skia
MartinZikmund Jan 17, 2024
91ce8b0
chore: Adjust Given_ToggleSwitch
MartinZikmund Jan 17, 2024
acdf55e
chore: Cleanup nonexisting API
MartinZikmund Mar 18, 2024
9efcc32
chore: Adjust TeachingTipTests
MartinZikmund Mar 18, 2024
e0d6624
chore: Fix Android build
Youssef1313 Mar 19, 2024
89dbf9d
chore: Adjust AppBar/CommandBar tests
Youssef1313 Mar 19, 2024
d2446f1
chore: Fix opacity tests
Youssef1313 Mar 19, 2024
89756af
chore: Fix When_Theme_Changes when run under fluent
Youssef1313 Mar 19, 2024
aab5366
chore: Fix few more tests
Youssef1313 Mar 19, 2024
6a1f5e9
chore: Duplicate using
MartinZikmund Apr 22, 2024
9352f40
chore: Add missing using
MartinZikmund Apr 22, 2024
362ad45
chore: Remove border from button on UI test
MartinZikmund Apr 23, 2024
1366865
chore: remove UseFluentStyles
ramezgerges May 15, 2024
b480390
chore: fix When_PasswordBox_TextRevealed
ramezgerges Apr 23, 2024
cfe5351
chore: adjust CanOpenFlyoutByKeyboard
ramezgerges Apr 23, 2024
0c80ead
chore: adjust When_Caret_Color_DarkMode
ramezgerges Apr 23, 2024
8240b8e
chore: adjust Check_Placement_All_MenuFlyout
ramezgerges Apr 23, 2024
354ee29
fix: hyperlink foreground logic to make TestRespectHyperlinkForegroun…
ramezgerges Apr 24, 2024
15ff01b
chore: adjust When_Visibility_Changes
ramezgerges Apr 24, 2024
8c77d47
fix(popup): transfer RenderTransform and Translation to the Child
ramezgerges May 15, 2024
9ab85e0
chore: fix Drag&drop in TreeView (When_TreeViewItem_Dragged_NRE)
ramezgerges May 16, 2024
0b7adbb
chore: Formatting adjustment
MartinZikmund May 17, 2024
9f81a66
chore: Adjust the test for WinAppSDK
MartinZikmund May 17, 2024
4655710
chore: Adjust for UWP build and StyleHelper
MartinZikmund Jun 21, 2024
861575b
chore: Disable failing test, adjust TB test
MartinZikmund Jun 22, 2024
216172c
chore: Disable CornerRadius UI test (#17272)
MartinZikmund Jun 22, 2024
6d06c62
chore: Disable ItemCornerRadius test on WASM (#17272)
MartinZikmund Jun 22, 2024
6da1754
chore: Disable Validate_UseUWPDefaultStyles (#17272)
MartinZikmund Jun 22, 2024
dbca1b0
fix: Avoid infinite layout loop in MediaTransportControls
MartinZikmund Jun 24, 2024
1762cab
chore: Adjust tests for fluent
Youssef1313 Jul 8, 2024
ac8205d
chore: Adjust DatePicker
Youssef1313 Jul 8, 2024
9033419
chore: Adjust
Youssef1313 Jul 8, 2024
6b7647b
chore: Adjust for Android
Youssef1313 Jul 10, 2024
9b5d249
chore: Adjust
Youssef1313 Jul 10, 2024
831847d
chore: Adjust test
Youssef1313 Jul 12, 2024
1d2b680
chore: Adjust tests
Youssef1313 Jul 12, 2024
5b5bdb4
chore: Adjust for failing Wasm tests
Youssef1313 Jul 15, 2024
d1cb7f3
chore: Adjust TextBox test
Youssef1313 Jul 15, 2024
4f10cbb
chore: Remove StyleHelper usage
MartinZikmund Aug 7, 2024
ff6f793
chore: Cleanup after rebase
MartinZikmund Aug 29, 2024
1d2c0ef
chore: Adjust and address comment
MartinZikmund Aug 30, 2024
5dc146f
chore: Fix test for UWP styles
MartinZikmund Sep 2, 2024
3fc626d
chore: Adjust tests for fluent
MartinZikmund Sep 3, 2024
5acd312
chore: Disable failing CommandBar tests
MartinZikmund Sep 3, 2024
8d73dce
chore: Adjust test to do UWP
MartinZikmund Sep 3, 2024
c06021a
chore: Disable failing tests for #18105
MartinZikmund Sep 4, 2024
2ca340f
chore: Disable additional failing tests #18105
MartinZikmund Sep 5, 2024
aef9aa3
fix: NRE in TextBlock
MartinZikmund Sep 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void When_Clipped_Rounded_Corners()

[Test]
[AutoRetry]
[Ignore("Fails on Fluent styles #17272")]
public void When_CornerRadiusControls()
{
Run("UITests.Windows_UI_Xaml.Clipping.CornerRadiusControls");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void Test_Reorder(int from, int to, int? expectedTo = null)
_app.WaitForElement(sut);

var sutBounds = _app.Query(sut).Single().Rect;
var x = sutBounds.X + 50;
var x = sutBounds.CenterX + 50;
var srcY = Item(sutBounds, from);
var dstY = Item(sutBounds, to);
var expectedY = expectedTo is null ? dstY : Item(sutBounds, expectedTo.Value);
Expand All @@ -218,7 +218,7 @@ private void Test_ReorderMulti(int from, int to, int? expectedTo = null)
_app.WaitForElement(sut);

var sutBounds = _app.Query(sut).Single().Rect;
var x = sutBounds.X + 50;
var x = sutBounds.CenterX;
var srcY = Item(sutBounds, from);
var dstY = Item(sutBounds, to);
var expectedY = expectedTo is null ? dstY : Item(sutBounds, expectedTo.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void AssertHasColorAtCenterAndBorder(string element, Color centerColor, Color bo
var rect = _app.GetPhysicalRect(element);
var borderCenterOffset = rect.Width / 50f * 7.5f;

const byte tolerance = 4;
const byte tolerance = 6;

ImageAssert.HasColorAt(scrn, rect.CenterX, rect.CenterY, centerColor, tolerance);
ImageAssert.HasColorAt(scrn, rect.X + borderCenterOffset, rect.CenterY, borderColor, tolerance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Change_Manipulation_Property()
[ActivePlatforms(Platform.Browser)]
public void Check_CornerRadius_Border_Basic()
{
const string white = "#FFFFFF";
const string white = "#F3F3F3";

// Verify that border is drawn with CornerRadius
Run("Uno.UI.Samples.UITests.BorderTestsControl.Border_CornerRadius", skipInitialScreenshot: true);
Expand Down Expand Up @@ -230,6 +230,7 @@ public void Border_CornerRadius_Clipping()
//For other platform the test have been moved to runtime
//It will be moves to when an equivalent of TakesScreenshot exist for that target
[ActivePlatforms(Platform.Browser)]
[Ignore("LinearGradientBrush doesn't work well when there is a CornerRadius")]
public void Border_LinearGradient()
{
Run("UITests.Windows_UI_Xaml_Controls.BorderTests.Border_LinearGradientBrush");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ partial class Button_Tests : SampleControlUITestBase
{
[Test]
[AutoRetry]
[Ignore("Fails on Fluent styles #17272")]
public void Validate_UseUWPDefaultStyles()
{
Run("UITests.Shared.Windows_UI_Xaml_Controls.Button.Button_UseUWPDefaultStyles");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void Test(bool aboveEquals, bool belowEquals, [CallerMemberName] string

// Assertions
const int testHeight = 50;
const int tolerance = 10; // Margins, etc
const int tolerance = 16; // Margins, etc
var above = new Rectangle((int)rect.X, (int)rect.Y - testHeight - tolerance, (int)rect.Width, testHeight);
var below = new Rectangle((int)rect.X, (int)rect.Bottom + tolerance, (int)rect.Width, testHeight);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,17 @@ public void DatePicker_PickerFlyout_Placements(string name, bool checkHorizontal

if (checkHorizontal)
{
controlRect.CenterX.Should().BeApproximately(highlightRect.CenterX, 2f, "horizontal center");
controlRect.CenterX.Should().BeApproximately(highlightRect.CenterX, 10f, "horizontal center");
}

if (checkVertical)
{
controlRect.CenterY.Should().BeApproximately(highlightRect.CenterY, 2f, "vertical center");
controlRect.CenterY.Should().BeApproximately(highlightRect.CenterY, 10f, "vertical center");
}

if (checkWidth)
{
controlRect.Width.Should().BeApproximately(highlightRect.Width, 2f, "width");
controlRect.Width.Should().BeApproximately(highlightRect.Width, 10f, "width");
}

_app.FastTap("DismissButton");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ string GetCurrentNavigationContext() =>

// check for selection index && content
Assert.AreEqual(expectedIndex, flipview.GetDependencyPropertyValue<int>("SelectedIndex"));

var rect = _app.Query("SUT").Single().Rect;

// Get rid of Button hover color so we can assert the actual button background.
_app.TapCoordinates(rect.Right + 5, rect.Bottom + 5);

using (var screenshot = TakeScreenshot($"Post_{navigationContext}_Navigation", ignoreInSnapshotCompare: true))
{
ImageAssert.HasColorAt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ public void UniformToFill_Second_Load()
ImageAssert.AreAlmostEqual(bmp, expectedRect, bmp, secondControlRect, permittedPixelError: 20);
}

// Images sometimes fail to load on iOS https://github.com/unoplatform/uno/issues/2295
// Fails on WebAssembly with Fluent Styles #18105
[Test]
[AutoRetry]
[ActivePlatforms(Platform.Android, Platform.Browser)] // Images sometimes fail to load on iOS https://github.com/unoplatform/uno/issues/2295
[ActivePlatforms(Platform.Android)]
public void Late_With_Fixed_Dimensions()
{
Run("UITests.Windows_UI_Xaml_Controls.ImageTests.ImageWithLateSourceFixedDimensions");
Expand All @@ -193,7 +195,7 @@ public void Late_With_Fixed_Dimensions()

var lateRect = _app.GetPhysicalRect("lateImage");

ImageAssert.AreAlmostEqual(bmp, expectedRect, bmp, lateRect, permittedPixelError: 20);
ImageAssert.AreAlmostEqual(bmp, expectedRect, bmp, lateRect, permittedPixelError: 21);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ public void PasswordShouldBeObscured()
Run("UITests.Shared.Windows_UI_Xaml_Controls.PasswordBoxTests.PasswordBoxPage");
var passwordBox = _app.Marked("redPasswordBox");
passwordBox.EnterText(" ");

// PasswordBox has to be unfocused for Foreground to be red.
// Otherwise, animations from template would take precedence and set the Foreground to black.
var rect = _app.Query("redPasswordBox").Single().Rect;
_app.TapCoordinates(rect.CenterX, rect.Bottom + 5);
using var screenshot = TakeScreenshot("Spaces typed in PasswordBox.");
ImageAssert.HasColorInRectangle(screenshot, _app.Query("redPasswordBox").Single().Rect.ToRectangle(), Color.Red);
ImageAssert.HasColorInRectangle(screenshot, rect.ToRectangle(), Color.Red);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task When_MultipleItems()
[Ignore("Cannot take screenshot on this platform.")]
#endif
public Task When_InListView()
=> When_InScrollableContainer("UITests.Windows_UI_Xaml_Controls.SwipeControlTests.SwipeControl_ListView");
=> When_InScrollableContainer("UITests.Windows_UI_Xaml_Controls.SwipeControlTests.SwipeControl_ListView", isLeftAligned: false);

[Test]
[AutoRetry]
Expand All @@ -90,17 +90,17 @@ public Task When_InListView()
[Ignore("Cannot take screenshot on this platform.")]
#endif
public Task When_InScrollViewer()
=> When_InScrollableContainer("UITests.Windows_UI_Xaml_Controls.SwipeControlTests.SwipeControl_ScrollViewer");
=> When_InScrollableContainer("UITests.Windows_UI_Xaml_Controls.SwipeControlTests.SwipeControl_ScrollViewer", isLeftAligned: true);

private async Task When_InScrollableContainer(string testName)
private async Task When_InScrollableContainer(string testName, bool isLeftAligned)
{
QueryEx sut = new QueryEx(q => q.All().Marked("SUT"));
QueryEx output = new QueryEx(q => q.All().Marked("Output"));

await RunAsync(testName);

var sutPhyRect = App.GetPhysicalRect(sut);
var item2PhyPosition = new Point((int)sutPhyRect.X + 150, (int)sutPhyRect.Y + 150).LogicalToPhysicalPixels(App);
var item2PhyPosition = new Point((int)(isLeftAligned ? sutPhyRect.X : sutPhyRect.CenterX), (int)sutPhyRect.Y + 150).LogicalToPhysicalPixels(App);

// Validate initial state
var initial = await TakeScreenshotAsync("initial");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public void When_Text_Selection_Is_Enabled()

using (var nonSelectableScreenshot = TakeScreenshot("NonSelectableTextBlock", ignoreInSnapshotCompare: true))
{
ImageAssert.HasColorAt(nonSelectableScreenshot, nonSelectableTextBlock.CenterX, nonSelectableTextBlock.CenterY, Color.White);
ImageAssert.HasColorAt(nonSelectableScreenshot, nonSelectableTextBlock.CenterX, nonSelectableTextBlock.CenterY, Color.FromArgb(255, 243, 243, 243));
}

// Click to ensure any selection is removed
Expand All @@ -535,7 +535,7 @@ public void When_Text_Selection_Is_Enabled()

using (var selectableScreenshot = TakeScreenshot("SelectableTextBlock", ignoreInSnapshotCompare: true))
{
ImageAssert.DoesNotHaveColorAt(selectableScreenshot, selectableTextBlock.CenterX, selectableTextBlock.CenterY, Color.White);
ImageAssert.DoesNotHaveColorAt(selectableScreenshot, selectableTextBlock.CenterX, selectableTextBlock.CenterY, Color.FromArgb(255, 243, 243, 243));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void When_Opacity_Is_Specified()

var grid = _app.Query("TestGrid").Single().Rect;
using var screenshot = TakeScreenshot(nameof(When_Opacity_Is_Specified));
ImageAssert.HasColorAt(screenshot, grid.CenterX, grid.CenterY, Color.FromArgb(255, 255, 128, 128));
ImageAssert.HasColorAt(screenshot, grid.CenterX, grid.CenterY, Color.FromArgb(255, 249, 122, 122));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void When_Stretch()
ImageAssert.HasColorAt(screenshot, uniformToFill.Right - 6, uniformToFill.CenterY, Yellowish, tolerance: 5);

// Top and bottom are same as backround. Left and right are red-ish
ImageAssert.HasColorAt(screenshot, uniform.CenterX, uniform.Y + 6, Color.White, tolerance: 5);
ImageAssert.HasColorAt(screenshot, uniform.CenterX, uniform.Bottom - 6, Color.White, tolerance: 5);
ImageAssert.HasColorAt(screenshot, uniform.CenterX, uniform.Y + 6, Color.FromArgb(255, 243, 243, 243), tolerance: 5);
ImageAssert.HasColorAt(screenshot, uniform.CenterX, uniform.Bottom - 6, Color.FromArgb(255, 243, 243, 243), tolerance: 5);
ImageAssert.HasColorAt(screenshot, uniform.X + 6, uniform.CenterY, Redish, tolerance: 5);
ImageAssert.HasColorAt(screenshot, uniform.Right - 6, uniform.CenterY, Redish, tolerance: 5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
using Uno.UI.Samples.Entities;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Globalization;
using Windows.UI.Core;
using Windows.Storage;
using Microsoft.UI.Xaml;
using System.IO;
using Windows.UI.Popups;
using Uno.Extensions;
using Uno.UI.Samples.Tests;

Expand Down Expand Up @@ -110,9 +108,7 @@ public SampleChooserViewModel(SampleChooserControl owner)
// Disable all pooling so that controls get collected quickly.
Microsoft.UI.Xaml.FrameworkTemplatePool.IsPoolingEnabled = false;
#endif
#if WINAPPSDK
UseFluentStyles = true;
#endif
InitializeCommands();
ObserveChanges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="Margin" Value="0,0,0,8" />
<Setter Property="IsTextSelectionEnabled" Value="True" />
</Style>
</StackPanel.Resources>
<TextBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ToolTip x:Name="ctl3" Background="Green" Width="80" CornerRadius="{x:Bind ToRadius(cornerRadius.Value), Mode=OneWay}">
<TextBlock Foreground="Yellow" HorizontalAlignment="Center">ToolTip<LineBreak/>(Control)</TextBlock>
</ToolTip>
<Button x:Name="ctl4" Background="Green" Width="80" Height="100" CornerRadius="{x:Bind ToRadius(cornerRadius.Value), Mode=OneWay}">
<Button x:Name="ctl4" Background="Green" Width="80" Height="100" BorderThickness="0" CornerRadius="{x:Bind ToRadius(cornerRadius.Value), Mode=OneWay}">
<TextBlock Foreground="Yellow" HorizontalAlignment="Center">Button<LineBreak/>(Control)</TextBlock>
</Button>
<ScrollViewer x:Name="ctl5" Background="Green" Width="80" CornerRadius="{x:Bind ToRadius(cornerRadius.Value), Mode=OneWay}">
Expand Down
42 changes: 28 additions & 14 deletions src/Uno.UI.RuntimeTests/Helpers/StyleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,51 @@ public static IDisposable UseAppLevelResources(ResourceDictionary resources)
return Disposable.Create(() => appResources.MergedDictionaries.Remove(resources));
}



/// <summary>
/// Ensure Fluent styles are available for the course of a single test.
/// </summary>
public static IDisposable UseFluentStyles()
public static IDisposable UseUwpStyles()
{
#if WINAPPSDK // Disabled on Windows for now because 19041 doesn't support WinUI 2.x; Fluent resources are used by default in SamplesApp.Windows
return null;
#if WINAPPSDK // Disabled on WinUI as removing the resource dictionary causes a crash.
return Disposable.Empty;
#else

NativeDispatcher.CheckThreadAccess();

var resources = Application.Current.Resources;
if (resources is Microsoft/* UWP don't rename */.UI.Xaml.Controls.XamlControlsResources || resources.MergedDictionaries.OfType<Microsoft/* UWP don't rename */.UI.Xaml.Controls.XamlControlsResources>().Any())
var xamlResources = resources.MergedDictionaries.OfType<Microsoft/* UWP don't rename */.UI.Xaml.Controls.XamlControlsResources>().FirstOrDefault();
if (xamlResources is null)
{
return null;
return Disposable.Empty;
}

var xcr = new Microsoft/* UWP don't rename */.UI.Xaml.Controls.XamlControlsResources();
resources.MergedDictionaries.Insert(0, xcr);

// Force default brushes to be reloaded
DefaultBrushes.ResetDefaultThemeBrushes();
resources.MergedDictionaries.Remove(xamlResources);
ForceReload();

return new DisposableAction(() =>
{
resources.MergedDictionaries.Remove(xcr);
DefaultBrushes.ResetDefaultThemeBrushes();
resources.MergedDictionaries.Insert(0, xamlResources);
ForceReload();
});

static void ForceReload()
{
DefaultBrushes.ResetDefaultThemeBrushes();
ResetIslandRootForeground();
}
#endif
}

#if !WINAPPSDK
private static void ResetIslandRootForeground()
{
if (Uno.UI.Xaml.Core.CoreServices.Instance.InitializationType == Xaml.Core.InitializationType.IslandsOnly &&
VisualTreeUtils.FindVisualChildByType<Control>(TestServices.WindowHelper.XamlRoot.VisualTree.RootElement) is { } control)
{
// Ensure the root element's Foreground is set correctly
control.SetValue(Control.ForegroundProperty, DefaultBrushes.TextForegroundBrush, DependencyPropertyValuePrecedences.DefaultValue);
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1641,8 +1641,8 @@ public async Task ValidateFootprint()

double expectedAppBarWidth = 400;

double expectedAppBarCompactClosedHeight = 40;
double expectedAppBarCompactOpenHeight = 40;
double expectedAppBarCompactClosedHeight = 48;
double expectedAppBarCompactOpenHeight = 48;

double expectedAppBarMinimalClosedHeight = 24;
double expectedAppBarMinimalOpenHeight = 24;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma warning disable 168 // for cleanup imported member

using System;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
Expand All @@ -16,6 +17,7 @@
using FluentAssertions.Execution;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Private.Infrastructure;
using Uno.Disposables;
using Uno.UI.RuntimeTests.Helpers;
using Uno.UI.RuntimeTests.MUX.Helpers;

Expand Down Expand Up @@ -202,6 +204,15 @@ await RunOnUIThread(() =>
#endif
public async Task CanOpenFlyoutByKeyboard()
{
// The test using fluent styles is broken due to lifecycle issues. https://github.com/unoplatform/uno/issues/16433
IDisposable styleDisposable = null;
await RunOnUIThread(() =>
{
var undoUseUwpStyles = StyleHelper.UseUwpStyles();
styleDisposable = Disposable.Create(() => RunOnUIThread(() => undoUseUwpStyles.Dispose()));
});


TestCleanupWrapper cleanup;

Grid rootPanel = null;
Expand Down Expand Up @@ -255,6 +266,8 @@ await RunOnUIThread(() =>
// escape to close the flyout
TestServices.KeyboardHelper.Escape();
await TestServices.WindowHelper.WaitForIdle();

styleDisposable?.Dispose();
}


Expand Down
Loading
Loading