Skip to content

Commit

Permalink
Merge pull request #17333 from unoplatform/dev/jela/macos-generic-test
Browse files Browse the repository at this point in the history
ci: Add macOS desktop runtime tests
  • Loading branch information
spouliot authored Nov 6, 2024
2 parents 71dff75 + 2a6a7f9 commit d1b8399
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 53 deletions.
45 changes: 45 additions & 0 deletions build/ci/.azure-devops-skia-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,48 @@ jobs:
testResultsFiles: '$(build.sourcesdirectory)/build/skia-linux-runtime-tests-results.xml'
failTaskOnFailedTests: true
failTaskOnMissingResultsFile: true

- job: Skia_macos_Runtime_Tests_Build
displayName: 'Run Skia macOS Runtime Tests'
timeoutInMinutes: 60

pool:
vmImage: ${{ parameters.vmMacImage }}

dependsOn: Skia_Tests_Build

variables:
SamplesAppArtifactName: skia-generic-samples-app-$(XAML_FLAVOR_BUILD)
SamplesAppArtifactPath: $(build.sourcesdirectory)/build/$(SamplesAppArtifactName)

UNO_UWP_BUILD: ${{ parameters.UNO_UWP_BUILD }}
XAML_FLAVOR_BUILD: ${{ parameters.XAML_FLAVOR_BUILD }}

steps:

- template: templates/download-winui-converted-tree.yml

- task: DownloadBuildArtifacts@0
inputs:
artifactName: $(SamplesAppArtifactName)
downloadPath: '$(build.sourcesdirectory)/build'

- template: templates/dotnet-install.yml

- script: |
cd $(SamplesAppArtifactPath)
dotnet SamplesApp.Skia.Generic.dll --runtime-tests=$(build.sourcesdirectory)/build/skia-macos-runtime-tests-results.xml
displayName: Run Skia $(XAML_FLAVOR_BUILD) Runtime Tests
env:
SamplesAppArtifactPath: $(SamplesAppArtifactPath)
SamplesAppArtifactName: $(SamplesAppArtifactName)
- task: PublishTestResults@2
condition: always()
inputs:
testRunTitle: 'Skia macOS $(XAML_FLAVOR_BUILD) Runtime Tests'
testResultsFormat: 'NUnit'
testResultsFiles: '$(build.sourcesdirectory)/build/skia-macos-runtime-tests-results.xml'
failTaskOnFailedTests: true
failTaskOnMissingResultsFile: true
1 change: 1 addition & 0 deletions src/Uno.UI.Runtime.Skia.MacOS/MacOSWindowWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected override void ShowCore()
public override void Close()
{
NativeUno.uno_window_close(_window.Handle);
base.Close();
}

public override void Move(PointInt32 position)
Expand Down
9 changes: 6 additions & 3 deletions src/Uno.UI.RuntimeTests/Helpers/ImageAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,19 @@ private static async Task<bool> AreRenderTargetBitmapsEqualAsync(RenderTargetBit
/// If the error is greater than or equal to 0.022, the differences are visible to human eyes.
/// <paramref name="actual">The image to compare with reference</paramref>
/// <paramref name="expected">Reference image.</paramref>
/// <paramref name="imperceptibilityThreshold">It is the threshold beyond which the compared images are not considered equal. Default value is 0.022.</paramref>>
/// <paramref name="imperceptibilityThreshold">It is the threshold beyond which the compared images are not considered equal. Default value is 0.022.</paramref>
/// <paramref name="resolutionTolerance">Limits of resolution (in pixels) difference between the bitmaps</paramref>
/// </summary>
public static async Task AreSimilarAsync(RawBitmap actual, RawBitmap expected, double imperceptibilityThreshold = 0.022)
public static async Task AreSimilarAsync(RawBitmap actual, RawBitmap expected, double imperceptibilityThreshold = 0.022, int resolutionTolerance = 0)
{
await actual.Populate();
await expected.Populate();

using var assertionScope = new AssertionScope("ImageAssert");

if (actual.Width != expected.Width || actual.Height != expected.Height)
var dx = Math.Abs(actual.Width - expected.Width);
var dy = Math.Abs(actual.Height - expected.Height);
if (dx > resolutionTolerance || dy > resolutionTolerance)
{
assertionScope.FailWith($"Images have different resolutions. {Environment.NewLine}expected:({expected.Width},{expected.Height}){Environment.NewLine}actual :({actual.Width},{actual.Height})");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1988,11 +1988,13 @@ string RandomString(int length)
// since this is originally a virtualization issue and references
// could be to different things than those shown on the screen.
var si = await UITestHelper.ScreenShot(list, true);
ImageAssert.HasColorAt(si, 70, 65, Colors.FromARGB("#1A69A6")); // selected
// on macOS/metal we get the color #1A6AA7 which is quite close but not identical
var tolerance = (byte)(OperatingSystem.IsMacOS() ? 1 : 0);
ImageAssert.HasColorAt(si, 70, 65, Colors.FromARGB("#1A69A6"), tolerance); // selected

// check starting from below the second item that nothing looks selected or hovered
ImageAssert.DoesNotHaveColorInRectangle(si, new Rectangle(100, 110, si.Width - 100, si.Height - 110), Colors.FromARGB("#1A69A6")); // selected
ImageAssert.DoesNotHaveColorInRectangle(si, new Rectangle(100, 110, si.Width - 100, si.Height - 110), Colors.FromARGB("#FFE6E6E6")); // hovered
ImageAssert.DoesNotHaveColorInRectangle(si, new Rectangle(100, 110, si.Width - 100, si.Height - 110), Colors.FromARGB("#1A69A6"), tolerance); // selected
ImageAssert.DoesNotHaveColorInRectangle(si, new Rectangle(100, 110, si.Width - 100, si.Height - 110), Colors.FromARGB("#FFE6E6E6"), tolerance); // hovered
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ public async Task Check_FontFallback_Shaping()
await UITestHelper.Load(expected);
var screenshot2 = await UITestHelper.ScreenShot(expected);

Assert.AreEqual(screenshot2.Width, screenshot1.Width);
Assert.AreEqual(screenshot2.Height, screenshot1.Height);

await ImageAssert.AreSimilarAsync(screenshot1, screenshot2, imperceptibilityThreshold: 0.15);
// we tolerate a 2 pixels difference between the bitmaps due to font differences
await ImageAssert.AreSimilarAsync(screenshot1, screenshot2, imperceptibilityThreshold: 0.18, resolutionTolerance: 2);
}
#endif

Expand Down Expand Up @@ -1264,7 +1262,8 @@ public async Task When_IsTextSelectionEnabled_Keyboard_SelectAll_Copy()
mouse.Release();
await WindowHelper.WaitForIdle();

SUT.SafeRaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.A, VirtualKeyModifiers.Control));
var mod = OperatingSystem.IsMacOS() ? VirtualKeyModifiers.Windows : VirtualKeyModifiers.Control;
SUT.SafeRaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.A, mod));
await WindowHelper.WaitForIdle();

var bitmap = await UITestHelper.ScreenShot(SUT);
Expand All @@ -1278,7 +1277,7 @@ public async Task When_IsTextSelectionEnabled_Keyboard_SelectAll_Copy()
SUT.SelectionHighlightColor.Color);
}

SUT.SafeRaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.C, VirtualKeyModifiers.Control));
SUT.SafeRaiseEvent(UIElement.KeyDownEvent, new KeyRoutedEventArgs(SUT, VirtualKey.C, mod));
await WindowHelper.WaitForIdle();

Assert.AreEqual(SUT.Text, await Clipboard.GetContent()!.GetTextAsync());
Expand Down
Loading

0 comments on commit d1b8399

Please sign in to comment.