From 65cdac60c3aa926dc0f0c91cd2459a548db1a7ec Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 22 Feb 2019 14:43:05 +0900 Subject: [PATCH] Add tests to make sure the background is always the same through screen transitions --- .../Visual/TestCaseBackgroundScreenBeatmap.cs | 35 ++++++++++++++++++- .../Play/ScreenWithBeatmapBackground.cs | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs index 6f6d43acc8..a09843318c 100644 --- a/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/TestCaseBackgroundScreenBeatmap.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; +using System.Collections.Generic; using System.Threading; using NUnit.Framework; using osu.Framework.Allocation; @@ -26,6 +28,13 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCaseBackgroundScreenBeatmap : ManualInputManagerTestCase { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(ScreenWithBeatmapBackground), + typeof(PlayerLoader), + typeof(Player) + }; + private DummySongSelect songSelect; private DimAccessiblePlayerLoader playerLoader; private DimAccessiblePlayer player; @@ -36,11 +45,13 @@ namespace osu.Game.Tests.Visual public TestCaseBackgroundScreenBeatmap() { ScreenStack screen; + InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both}); InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both }); AddStep("Load Song Select", () => { + songSelect?.MakeCurrent(); songSelect?.Exit(); LoadComponentAsync(new DummySongSelect(), p => @@ -73,6 +84,8 @@ namespace osu.Game.Tests.Visual AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); + AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); + AddStep("Update bindables", () => playerLoader.UpdateBindables()); AddStep("Trigger background preview", () => { @@ -93,6 +106,7 @@ namespace osu.Game.Tests.Visual // The OnHover of PlayerLoader will trigger, which could potentially trigger an undim unless checked for in PlayerLoader. // We need to check that in this scenario, the dim is still properly applied after entering player. AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load"); + AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); AddStep("Trigger background preview when loaded", () => { InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); @@ -142,7 +156,11 @@ namespace osu.Game.Tests.Visual [Test] public void PauseTest() { - AddStep("Transition to Pause", () => player.Exit()); + AddStep("Transition to Pause", () => + { + if (!player.IsPaused) + player.Exit(); + }); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed()); } @@ -156,6 +174,7 @@ namespace osu.Game.Tests.Visual AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }}))); AddWaitStep(5, "Wait for dim"); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed()); + AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent()); } /// @@ -196,6 +215,15 @@ namespace osu.Game.Tests.Visual { return ((FadeAccessibleBackground)Background).AssertVisible(); } + + /// + /// Make sure every time a screen gets pushed, the background doesn't get replaced + /// + /// Whether or not the original background is still the current background + public bool AssertBackgroundCurrent() + { + return ((FadeAccessibleBackground)Background).IsCurrentScreen(); + } } private class FadeAccesibleResults : SoloResults @@ -216,6 +244,8 @@ namespace osu.Game.Tests.Visual public Bindable StoryboardEnabled; public readonly Bindable ReplacesBackground = new Bindable(); + public bool IsPaused => RulesetContainer.IsPaused; + [BackgroundDependencyLoader] private void load(OsuConfigManager config) { @@ -233,6 +263,9 @@ namespace osu.Game.Tests.Visual public VisualSettings VisualSettingsPos => VisualSettings; public BackgroundScreen ScreenPos => Background; + [Resolved] + private BackgroundScreenStack stack { get; set; } + public void UpdateBindables() { DimEnabled = Background.EnableUserDim; diff --git a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs index 15016d2bc2..93223b6607 100644 --- a/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs +++ b/osu.Game/Screens/Play/ScreenWithBeatmapBackground.cs @@ -15,7 +15,7 @@ namespace osu.Game.Screens.Play { protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value); - protected new BackgroundScreenBeatmap Background => base.Background as BackgroundScreenBeatmap; + protected new BackgroundScreenBeatmap Background => (BackgroundScreenBeatmap)base.Background; protected const float BACKGROUND_FADE_DURATION = 800;