Add test coverage of cross-thread transforms if a dialog is pushed too early

This commit is contained in:
Dean Herbert
2022-05-04 20:14:30 +09:00
parent 0018408bdb
commit cf220f171b

View File

@ -1,10 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Dialog; using osu.Game.Overlays.Dialog;
@ -15,15 +17,11 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
private DialogOverlay overlay; private DialogOverlay overlay;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create dialog overlay", () => Child = overlay = new DialogOverlay());
}
[Test] [Test]
public void TestBasic() public void TestBasic()
{ {
AddStep("create dialog overlay", () => Child = overlay = new DialogOverlay());
TestPopupDialog firstDialog = null; TestPopupDialog firstDialog = null;
TestPopupDialog secondDialog = null; TestPopupDialog secondDialog = null;
@ -37,12 +35,12 @@ namespace osu.Game.Tests.Visual.UserInterface
new PopupDialogOkButton new PopupDialogOkButton
{ {
Text = @"I never want to see this again.", Text = @"I never want to see this again.",
Action = () => System.Console.WriteLine(@"OK"), Action = () => Console.WriteLine(@"OK"),
}, },
new PopupDialogCancelButton new PopupDialogCancelButton
{ {
Text = @"Firetruck, I still want quick ranks!", Text = @"Firetruck, I still want quick ranks!",
Action = () => System.Console.WriteLine(@"Cancel"), Action = () => Console.WriteLine(@"Cancel"),
}, },
}, },
})); }));
@ -87,9 +85,51 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("first dialog is not part of hierarchy", () => firstDialog.Parent == null); AddAssert("first dialog is not part of hierarchy", () => firstDialog.Parent == null);
} }
[Test]
public void TestPushBeforeLoad()
{
PopupDialog dialog = null;
AddStep("create dialog overlay", () => overlay = new SlowLoadingDialogOverlay());
AddStep("start loading overlay", () => LoadComponentAsync(overlay, Add));
AddStep("push dialog before loaded", () =>
{
overlay.Push(dialog = new TestPopupDialog
{
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton { Text = @"OK" },
},
});
});
AddAssert("dialog not displayed", () => overlay.CurrentDialog != dialog);
AddStep("complete load", () => ((SlowLoadingDialogOverlay)overlay).LoadEvent.Set());
AddUntilStep("wait for load", () => overlay.IsLoaded);
AddAssert("dialog displayed", () => overlay.CurrentDialog == dialog);
}
public class SlowLoadingDialogOverlay : DialogOverlay
{
public ManualResetEventSlim LoadEvent = new ManualResetEventSlim();
[BackgroundDependencyLoader]
private void load()
{
LoadEvent.Wait(10000);
}
}
[Test] [Test]
public void TestDismissBeforePush() public void TestDismissBeforePush()
{ {
AddStep("create dialog overlay", () => Child = overlay = new DialogOverlay());
TestPopupDialog testDialog = null; TestPopupDialog testDialog = null;
AddStep("dismissed dialog push", () => AddStep("dismissed dialog push", () =>
{ {
@ -106,6 +146,8 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test] [Test]
public void TestDismissBeforePushViaButtonPress() public void TestDismissBeforePushViaButtonPress()
{ {
AddStep("create dialog overlay", () => Child = overlay = new DialogOverlay());
TestPopupDialog testDialog = null; TestPopupDialog testDialog = null;
AddStep("dismissed dialog push", () => AddStep("dismissed dialog push", () =>
{ {