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

feat(wasm): Enable managed pointers on wasm #17633

Merged
merged 24 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4d68131
feat(wasm): Enabled managed pointers on wasm
dr1rrb Jul 22, 2024
675ef81
fix(reg): Fix the managed pointer ID handling
dr1rrb Jul 23, 2024
7f2a8b9
test(wasm): Run compatible UI tests as runtime tests on wasm
dr1rrb Jul 24, 2024
d0cd60f
test: Enable pointer injection on wasm runtime tests
dr1rrb Jul 24, 2024
425b7f2
chore: Remove deprecated code
dr1rrb Jul 24, 2024
597fee3
chore(reg): Fix CI build - iteration 1
dr1rrb Jul 25, 2024
d82f7fb
chore(reg): Fix CI build - iteration 2
dr1rrb Jul 26, 2024
adbe9f5
chore(reg): Fix CI build - iteration 3: Disable tests that relies on …
dr1rrb Jul 26, 2024
212d50a
chore(reg): Fix CI build - iteration 4: Fix UI tests
dr1rrb Jul 29, 2024
b1d77a5
chore(reg): Fix CI build - iteration 5: Update exclusion rules for tests
dr1rrb Jul 29, 2024
feceeb6
chore(reg): Fix CI build - iteration 6
dr1rrb Jul 29, 2024
1049939
chore(reg): Fix CI build - iteration 7
dr1rrb Jul 30, 2024
9f4eec8
chore(reg): Fix CI build - iteration 8
dr1rrb Jul 30, 2024
b472c05
chore: Few fixes
Youssef1313 Aug 8, 2024
02c5206
chore: Fix for Hyperlink
Youssef1313 Aug 9, 2024
028cb66
chore: Wasm shapes hittesting
Youssef1313 Aug 12, 2024
0f3e8ec
test: Move to runtime tests falky tests
dr1rrb Aug 15, 2024
40837dd
test: Fix failing testtest: Disable failing test on WASM
dr1rrb Aug 15, 2024
0e099ff
chore: Refactor per review comments
Youssef1313 Aug 15, 2024
484a5a2
chore: Fix test failing on CI
dr1rrb Aug 16, 2024
5baf297
chore: Fix UWP build
dr1rrb Aug 16, 2024
e397018
chore: Cleanup
dr1rrb Aug 16, 2024
ee48637
chore: Fix WinAppSDK build
dr1rrb Aug 16, 2024
92edbfa
chore: Fix invalid sizing
dr1rrb Aug 16, 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
10 changes: 10 additions & 0 deletions src/SamplesApp/SamplesApp.UITests/Extensions/AppExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Uno.UITest;
using Uno.UITest.Helpers;
using Uno.UITest.Helpers.Queries;
Expand All @@ -13,6 +15,14 @@ namespace SamplesApp.UITests.Extensions
{
public static class AppExtensions
{
#if !IS_RUNTIME_UI_TESTS
public static async Task<FileInfo> TakeScreenshotAsync(this IApp app, string title)
=> app.Screenshot(title);

public static async ValueTask DragCoordinatesAsync(this IApp app, float fromX, float fromY, float toX, float toY, CancellationToken ct = default)
=> app.DragCoordinates(fromX, fromY, toX, toY);
#endif

public static void DragCoordinates(this IApp app, PointF from, PointF to) => app.DragCoordinates(from.X, from.Y, to.X, to.Y);

#if !IS_RUNTIME_UI_TESTS
Expand Down
6 changes: 6 additions & 0 deletions src/SamplesApp/SamplesApp.UITests/SampleControlUITestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ private void WriteSystemLogs(string fileName)
}
}

public async ValueTask<ScreenshotInfo> TakeScreenshotAsync(string stepName, bool? ignoreInSnapshotCompare = null)
=> TakeScreenshot(stepName, ignoreInSnapshotCompare);

public ScreenshotInfo TakeScreenshot(string stepName, bool? ignoreInSnapshotCompare = null)
=> TakeScreenshot(
stepName,
Expand All @@ -289,6 +292,9 @@ public ScreenshotInfo TakeScreenshot(string stepName, bool? ignoreInSnapshotComp
: null
);

public async ValueTask<ScreenshotInfo> TakeScreenshotAsync(string stepName, ScreenshotOptions options)
=> TakeScreenshot(stepName, options);

public ScreenshotInfo TakeScreenshot(string stepName, ScreenshotOptions options)
{
if (_app == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<DefineConstants Condition="$(UnoTargetFrameworkOverride.ToLowerInvariant().Contains('-ios'))">$(DefineConstants);TARGET_FRAMEWORK_OVERRIDE_IOS</DefineConstants>

<!-- Use 'GeneratedRegexAttribute' to generate the regular expression -->
<NoWarn>$(NoWarn);SYSLIB1045</NoWarn>
<NoWarn>$(NoWarn);SYSLIB1045;CS1998</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/SamplesApp/SamplesApp.UITests/TestFramework/ImageAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,27 @@ static ImageAssert()
#region Are[Almost]Equal
public static void AreEqual(ScreenshotInfo expected, ScreenshotInfo actual, IAppRect rect, double expectedToActualScale = 1, PixelTolerance tolerance = default, [CallerLineNumber] int line = 0)
=> AreEqualImpl(expected, rect.ToRectangle(), actual, rect.ToRectangle(), expectedToActualScale, tolerance, line);
public static async Task AreEqualAsync(ScreenshotInfo expected, ScreenshotInfo actual, IAppRect rect, double expectedToActualScale = 1, PixelTolerance tolerance = default, [CallerLineNumber] int line = 0)
=> AreEqualImpl(expected, rect.ToRectangle(), actual, rect.ToRectangle(), expectedToActualScale, tolerance, line);

public static void AreEqual(ScreenshotInfo expected, ScreenshotInfo actual, Rectangle? rect = null, double expectedToActualScale = 1, PixelTolerance tolerance = default, [CallerLineNumber] int line = 0)
=> AreEqualImpl(expected, rect ?? FirstQuadrant, actual, rect ?? FirstQuadrant, expectedToActualScale, tolerance, line);

public static async Task AreEqualAsync(ScreenshotInfo expected, ScreenshotInfo actual, Rectangle? rect = null, double expectedToActualScale = 1, PixelTolerance tolerance = default, [CallerLineNumber] int line = 0)
=> AreEqualImpl(expected, rect ?? FirstQuadrant, actual, rect ?? FirstQuadrant, expectedToActualScale, tolerance, line);

public static void AreEqual(ScreenshotInfo expected, IAppRect expectedRect, ScreenshotInfo actual, IAppRect actualRect, double expectedToActualScale = 1, PixelTolerance tolerance = default, [CallerLineNumber] int line = 0)
=> AreEqualImpl(expected, expectedRect.ToRectangle(), actual, actualRect.ToRectangle(), expectedToActualScale, tolerance, line);

public static async Task AreEqualAsync(ScreenshotInfo expected, IAppRect expectedRect, ScreenshotInfo actual, IAppRect actualRect, double expectedToActualScale = 1, PixelTolerance tolerance = default, [CallerLineNumber] int line = 0)
=> AreEqualImpl(expected, expectedRect.ToRectangle(), actual, actualRect.ToRectangle(), expectedToActualScale, tolerance, line);

public static void AreEqual(ScreenshotInfo expected, Rectangle expectedRect, ScreenshotInfo actual, Rectangle actualRect, double expectedToActualScale = 1, PixelTolerance tolerance = default, [CallerLineNumber] int line = 0)
=> AreEqualImpl(expected, expectedRect, actual, actualRect, expectedToActualScale, tolerance, line);

public static async Task AreEqualAsync(ScreenshotInfo expected, Rectangle expectedRect, ScreenshotInfo actual, Rectangle actualRect, double expectedToActualScale = 1, PixelTolerance tolerance = default, [CallerLineNumber] int line = 0)
=> AreEqualImpl(expected, expectedRect, actual, actualRect, expectedToActualScale, tolerance, line);

/// <summary>
/// Asserts that two screenshots are equal to each other inside the area of the nominated rect to within the given pixel error
/// (ie, the A, R, G, or B values cumulatively differ by more than the permitted error for any pixel).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,102 +1,250 @@
using NUnit.Framework;
#if IS_RUNTIME_UI_TESTS
#define CAN_ASSERT_CONTENT
#if HAS_RENDER_TARGET_BITMAP
#define CAN_ASSERT_IMAGE
#endif
using Microsoft/* UWP don't rename */.UI.Xaml.Controls;
using Uno.UI.RuntimeTests.Helpers;
#else
#define CAN_ASSERT_IMAGE
#endif

#if !CAN_ASSERT_CONTENT && !CAN_ASSERT_IMAGE
#error No way to assert the test result
#endif

using NUnit.Framework;
using SamplesApp.UITests.TestFramework;
using Uno.UITest;
using Uno.UITest.Helpers;
using Uno.UITest.Helpers.Queries;
using System.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Input;
using SamplesApp.UITests.Extensions;
using Uno.Testing;

namespace SamplesApp.UITests.Windows_UI_Xaml.DragAndDropTests
{
[TestFixture]
public partial class DragDrop_TreeView_Reorder_Automated : SampleControlUITestBase
{
const int _itemHeight = 70;
const int _offset = 30;
[Test]
[AutoRetry]
[ActivePlatforms(Platform.Browser)]
public void When_Dragging_TreeView_Item()
[InjectedPointer(PointerDeviceType.Mouse)]
#if !IS_RUNTIME_UI_TESTS
[Ignore("Flaky")]
#endif
public async Task When_Dragging_TreeView_Item()
{
Run("UITests.Windows_UI_Xaml.DragAndDrop.DragDrop_TreeView", skipInitialScreenshot: true);

var tv = _app.Marked("tv");
var bt0 = _app.Marked("bt0");
var bt1 = _app.Marked("bt1");
var bt2 = _app.Marked("bt2");
var bt3 = _app.Marked("bt3");
var focusbt = _app.Marked("focusbt");
var radio_disable = _app.Marked("radio_disable");

_app.WaitForElement(radio_disable);
_app.Tap(radio_disable);

_app.WaitForElement(tv);
_app.Tap(bt1);
_app.Tap(focusbt);
var case1 = _app.Screenshot("case1");

_app.Tap(bt2);
_app.Tap(focusbt);
var case2 = _app.Screenshot("case2");

_app.Tap(bt3);
_app.Tap(focusbt);
var case3 = _app.Screenshot("case3");

_app.Tap(bt0);
var tvBounds = _app.Query("tv").Single().Rect;
float fromX = tvBounds.X + 100;
float fromY = tvBounds.Y + _itemHeight * 3 + _offset;
float toX = tvBounds.X + 100;
float toY = tvBounds.Y + _offset;
_app.DragCoordinates(fromX, fromY, toX, toY);
_app.Tap(focusbt);
var result = _app.Screenshot("result1");
ImageAssert.AreEqual(case1, result);
await RunAsync("UITests.Windows_UI_Xaml.DragAndDrop.DragDrop_TreeView", skipInitialScreenshot: true);

var tv = App.Marked("tv");
var bt0 = App.Marked("bt0");
var bt1 = App.Marked("bt1");
var bt2 = App.Marked("bt2");
var bt3 = App.Marked("bt3");
var focusbt = App.Marked("focusbt");
var radio_disable = App.Marked("radio_disable");

App.WaitForElement(radio_disable);
App.Tap(radio_disable);

App.WaitForElement(tv);

#if CAN_ASSERT_IMAGE
App.Tap(bt1);
App.Tap(focusbt);
var case1 = await Screenshot("case1");

App.Tap(bt2);
App.Tap(focusbt);
var case2 = await Screenshot("ase2");

App.Tap(bt3);
App.Tap(focusbt);
var case3 = await Screenshot("case3");

App.Tap(bt0);
#endif
#if CAN_ASSERT_CONTENT
App.Tap(bt0);
await UITestHelper.WaitForIdle();
await UITestHelper.WaitForIdle();
await UITestHelper.WaitForIdle();

var treeView = (TreeView)App.Query(tv).Single().Element;
Assert.IsNotNull(treeView);
Assert.AreEqual(
""""
v aaa
- bbb
- ccc
- ddd
- eee
"""".Trim().Replace("\r\n", "\n"),
Dump(treeView));
#endif

var tvBounds = App.Query("tv").Single().Rect;
var fromX = tvBounds.X + 100;
var fromY = tvBounds.Y + _itemHeight * 3 + _offset;
var toX = tvBounds.X + 100;
var toY = tvBounds.Y + _offset;

await App.DragCoordinatesAsync(fromX, fromY, toX, toY);
App.Tap(focusbt);

#if CAN_ASSERT_IMAGE
var result = await Screenshot("result1");
await ImageAssert.AreEqualAsync(case1, result);
#endif
#if CAN_ASSERT_CONTENT
await UITestHelper.WaitForIdle();
Assert.AreEqual(
""""
v aaa
- bbb
- ddd
- ccc
- eee
"""".Trim().Replace("\r\n", "\n"),
Dump(treeView));
#endif

fromY = tvBounds.Y + _itemHeight * 1 + _offset;
toY = tvBounds.Y + _itemHeight * 4 + _offset;
_app.DragCoordinates(fromX, fromY, toX, toY);
_app.Tap(focusbt);
result = _app.Screenshot("result2");
ImageAssert.AreEqual(case2, result);
await App.DragCoordinatesAsync(fromX, fromY, toX, toY);
App.Tap(focusbt);

#if CAN_ASSERT_IMAGE
result = await Screenshot("result2");
await ImageAssert.AreEqualAsync(case2, result);
#endif
#if CAN_ASSERT_CONTENT
await UITestHelper.WaitForIdle();
Assert.AreEqual(
""""
v aaa
- ddd
- ccc
> eee
"""".Trim().Replace("\r\n", "\n"),
Dump(treeView));
#endif

fromY = tvBounds.Y + _itemHeight * 3 + _offset;
toY = tvBounds.Y + _itemHeight - 5;
_app.DragCoordinates(fromX, fromY, toX, toY);
_app.Tap(focusbt);
result = _app.Screenshot("result3");
ImageAssert.AreEqual(case3, result);
await App.DragCoordinatesAsync(fromX, fromY, toX, toY);
App.Tap(focusbt);

#if CAN_ASSERT_IMAGE
result = await Screenshot("result3");
await ImageAssert.AreEqualAsync(case3, result);
#endif
#if CAN_ASSERT_CONTENT
await UITestHelper.WaitForIdle();
Assert.AreEqual(
""""
v aaa
> eee
- ddd
- ccc
"""".Trim().Replace("\r\n", "\n"),
Dump(treeView));
#endif

#if CAN_ASSERT_IMAGE
#if IS_RUNTIME_UI_TESTS
async ValueTask<RawBitmap> Screenshot(string name) => await UITestHelper.ScreenShot((TreeView)App.Query(tv).Single().Element);
#else
async ValueTask<FileInfo> Screenshot(string name) => await App.TakeScreenshotAsync(name);
#endif
#endif
}

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Browser)]
public void When_OnDragItemsCompleted()
[InjectedPointer(PointerDeviceType.Mouse)]
public async Task When_OnDragItemsCompleted()
{
Run("UITests.Windows_UI_Xaml.DragAndDrop.DragDrop_TreeView", skipInitialScreenshot: true);
var tv = _app.Marked("tv");
var bt0 = _app.Marked("bt0");
var radio_enable = _app.Marked("radio_enable");
var tb = _app.Marked("tb");

_app.WaitForElement(tv);

_app.WaitForElement(radio_enable);
_app.Tap(radio_enable);
_app.WaitForElement(bt0);
_app.Tap(bt0);

var tvBounds = _app.Query("tv").Single().Rect;
float fromX = tvBounds.X + 100;
float fromY = tvBounds.Y + _itemHeight * 3 + _offset;
float toX = tvBounds.X + 100;
float toY = tvBounds.Y + _offset;
_app.DragCoordinates(fromX, fromY, toX, toY);

string text = _app.GetText("tb").Trim();
await RunAsync("UITests.Windows_UI_Xaml.DragAndDrop.DragDrop_TreeView", skipInitialScreenshot: true);
var tv = App.Marked("tv");
var bt0 = App.Marked("bt0");
var radio_enable = App.Marked("radio_enable");
var tb = App.Marked("tb");

App.WaitForElement(tv);

App.WaitForElement(radio_enable);
App.Tap(radio_enable);
App.WaitForElement(bt0);
App.Tap(bt0);

#if IS_RUNTIME_UI_TESTS
await UITestHelper.WaitForIdle();
await UITestHelper.WaitForIdle();
await UITestHelper.WaitForIdle();
#endif

var tvBounds = App.Query("tv").Single().Rect;
var fromX = tvBounds.X + 100;
var fromY = tvBounds.Y + _itemHeight * 3 + _offset;
var toX = tvBounds.X + 100;
var toY = tvBounds.Y + _offset;
await App.DragCoordinatesAsync(fromX, fromY, toX, toY);

#if IS_RUNTIME_UI_TESTS
await UITestHelper.WaitForIdle();
await UITestHelper.WaitForIdle();
await UITestHelper.WaitForIdle();
#endif

string text = App.GetText("tb").Trim();
Assert.AreEqual("DragItemsCompleted is triggered", text);
}

#if CAN_ASSERT_CONTENT
private string Dump(TreeView tv)
{
var dump = new StringBuilder();
DumpCore(0, tv.RootNodes);
return dump.ToString().Trim().Replace("\r\n", "\n");

void DumpCore(int level, IList<TreeViewNode> nodes)
{
foreach (var node in nodes)
{
dump.Append(new string('\t', level));
switch (node)
{
case { Children: null or { Count: 0 } }:
dump.Append("- ");
dump.AppendLine(node.Content?.ToString() ?? "--null--");
break;

case { IsExpanded: false }:
dump.Append("> ");
dump.AppendLine(node.Content?.ToString() ?? "--null--");
break;

default:
dump.Append("v ");
dump.AppendLine(node.Content?.ToString() ?? "--null--");
DumpCore(level + 1, node.Children);
break;
}
}
}
}
#endif
}
}
Loading
Loading