Skip to content

test: Validate ListView does not stay blank when fast scrolling using mouse #19906

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/Uno.UI.Composition/Composition/Compositor.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ static partial void Initialize()

internal bool? IsSoftwareRenderer { get; set; }

internal bool IsAnimating => _runningAnimations.Count > 0;

internal void RegisterAnimation(CompositionAnimation animation, CompositionObject visual)
{
if (animation.IsTrackedByCompositor)
Expand Down
12 changes: 11 additions & 1 deletion src/Uno.UI.RuntimeTests/Helpers/UITestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ public static async Task WaitForLoaded<T>(T element, Func<T, bool>? isLoaded = n
await TestServices.WindowHelper.WaitForIdle();
}

public static Task WaitForIdle() => TestServices.WindowHelper.WaitForIdle();
public static async Task WaitForIdle(bool waitForCompositionAnimations = true)
{
#if __SKIA__
do
{
await TestServices.WindowHelper.WaitForIdle();
} while (waitForCompositionAnimations && (TestServices.WindowHelper.WindowContent?.Visual?.Compositor?.IsAnimating ?? false));
#else
await TestServices.WindowHelper.WaitForIdle();
#endif
}

/// <summary>
/// Takes a screen-shot of the given element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,62 @@ string RandomString(int length)
ImageAssert.DoesNotHaveColorInRectangle(si, new Rectangle(100, 110, si.Width - 100, si.Height - 110), Colors.FromARGB("#FFE6E6E6"), tolerance); // hovered
}


[TestMethod]
[RunsOnUIThread]
#if !HAS_INPUT_INJECTOR
[Ignore("InputInjector is not supported on this platform.")]
#elif !HAS_RENDER_TARGET_BITMAP
[Ignore("Cannot take screenshot on this platform.")]
#endif
public async Task When_FastMouseWheelScroll_Then_ItemsRealized()
{
var container = new Grid { Height = 500, Width = 100 };
var sut = new ListView
{
ItemsSource = Enumerable.Range(0, 100),
ItemTemplate = new DataTemplate(() =>
{
var tb = new TextBlock();
tb.SetBinding(TextBlock.TextProperty, new Binding());
var border = new Border()
{
Height = 50,
Child = tb
};

return border;
})
};
container.Children.Add(sut);

var bounds = await UITestHelper.Load(container);

var injector = InputInjector.TryCreate() ?? throw new InvalidOperationException("Failed to init the InputInjector");
var mouse = injector.GetMouse();
mouse.MoveTo(bounds.GetCenter());

var top1 = await UITestHelper.ScreenShot(sut);

for (var i = 0; i < 100; i++)
{
mouse.Wheel(-4096); // Fast scroll to the bottom
}
await UITestHelper.WaitForIdle(waitForCompositionAnimations: true);

var bottom = await UITestHelper.ScreenShot(sut);
await ImageAssert.AreNotEqualAsync(top1, bottom);

for (var i = 0; i < 100; i++)
{
mouse.Wheel(4096); // Fast scroll to the bottom
}
await UITestHelper.WaitForIdle(waitForCompositionAnimations: true);

var top2 = await UITestHelper.ScreenShot(sut);
ImageAssert.HasPixels(top1, ExpectedPixels.At(0, 0).Pixels(top2, new Rectangle(0, 0, 50, 500))); // Validate only the left to ignore the scroll bar
}

[TestMethod]
[RunsOnUIThread]
#if !__CROSSRUNTIME__
Expand Down
Loading