1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-06 21:52:58 +08:00

Make test cases more compact, add two way toggles

This commit is contained in:
David Zhao 2019-02-28 20:01:15 +09:00
parent 19d529c1c8
commit e3338e94d1
4 changed files with 66 additions and 94 deletions

View File

@ -91,7 +91,7 @@ namespace osu.Game.Tests.Visual
} }
/// <summary> /// <summary>
/// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel. /// Check if <see cref="PlayerLoader"/> properly triggers background dim previews when a user hovers over the visual settings panel.
/// </summary> /// </summary>
[Test] [Test]
public void PlayerLoaderSettingsHoverTest() public void PlayerLoaderSettingsHoverTest()
@ -105,9 +105,11 @@ namespace osu.Game.Tests.Visual
InputManager.MoveMouseTo(playerLoader.ScreenPos); InputManager.MoveMouseTo(playerLoader.ScreenPos);
InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); InputManager.MoveMouseTo(playerLoader.VisualSettingsPos);
}); });
waitForDim(); waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
AddStep("Stop background preview", () => InputManager.MoveMouseTo(playerLoader.ScreenPos));
waitForDim();
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed());
} }
/// <summary> /// <summary>
@ -118,20 +120,11 @@ namespace osu.Game.Tests.Visual
[Test] [Test]
public void PlayerLoaderTransitionTest() public void PlayerLoaderTransitionTest()
{ {
setupUserSettings(); performFullSetup();
AddStep("Start player loader", () => { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())); });
AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load");
AddStep("Allow beatmap to load", () =>
{
player.Ready = true;
InputManager.MoveMouseTo(playerLoader.ScreenPos);
});
AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load");
AddStep("Trigger hover event", () => playerLoader.TriggerOnHover()); AddStep("Trigger hover event", () => playerLoader.TriggerOnHover());
AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent());
waitForDim(); waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); AddAssert("Screen is dimmed and unblurred", () => songSelect.IsBackgroundDimmed() && songSelect.IsBackgroundUnblurred());
AddAssert("Screen is unblurred", () => songSelect.IsBackgroundUnblurred());
} }
/// <summary> /// <summary>
@ -142,9 +135,14 @@ namespace osu.Game.Tests.Visual
{ {
performFullSetup(); performFullSetup();
createFakeStoryboard(); createFakeStoryboard();
AddStep("Storyboard Enabled", () =>
{
player.ReplacesBackground.Value = true;
player.StoryboardEnabled.Value = true;
});
waitForDim(); waitForDim();
AddAssert("Background is invisible, storyboard is visible", () => songSelect.IsBackgroundInvisible() && player.IsStoryboardVisible()); AddAssert("Background is invisible, storyboard is visible", () => songSelect.IsBackgroundInvisible() && player.IsStoryboardVisible());
AddStep("Disable storyboard", () => AddStep("Storyboard Disabled", () =>
{ {
player.ReplacesBackground.Value = false; player.ReplacesBackground.Value = false;
player.StoryboardEnabled.Value = false; player.StoryboardEnabled.Value = false;
@ -161,37 +159,24 @@ namespace osu.Game.Tests.Visual
{ {
performFullSetup(); performFullSetup();
createFakeStoryboard(); createFakeStoryboard();
AddUntilStep(() => AddStep("Exit to song select", () => player.Exit());
{
if (songSelect.IsCurrentScreen()) return true;
songSelect.MakeCurrent();
return false;
}, "Wait for song select is current");
waitForDim(); waitForDim();
AddAssert("Background is visible", () => songSelect.IsBackgroundVisible()); AddAssert("Background is visible", () => songSelect.IsBackgroundVisible());
} }
/// <summary> /// <summary>
/// Check if the fade container is properly being reset when screen dim is disabled. /// Check if the <see cref="UserDimContainer"/> is properly accepting user dim changes at all.
/// </summary> /// </summary>
[Test] [Test]
public void DisableUserDimTest() public void DisableUserDimTest()
{ {
performFullSetup(); performFullSetup();
AddStep("Test User Undimming", () => songSelect.DimEnabled.Value = false); waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
AddStep("EnableUserDim disabled", () => songSelect.DimEnabled.Value = false);
waitForDim(); waitForDim();
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed());
} AddStep("EnableUserDim enabled", () => songSelect.DimEnabled.Value = true);
/// <summary>
/// Check if the fade container is properly being faded when screen dim is enabled.
/// </summary>
[Test]
public void EnableUserDimTest()
{
performFullSetup();
AddStep("Test User Dimming", () => songSelect.DimEnabled.Value = true);
waitForDim(); waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
} }
@ -203,55 +188,44 @@ namespace osu.Game.Tests.Visual
public void PauseTest() public void PauseTest()
{ {
performFullSetup(true); performFullSetup(true);
AddStep("Transition to Pause", () => AddStep("Pause", () => player.CurrentPauseContainer.Pause());
{ waitForDim();
if (!player.IsPaused.Value) AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
player.Exit(); AddStep("Unpause", () => player.CurrentPauseContainer.Resume());
});
waitForDim(); waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed()); AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
} }
/// <summary> /// <summary>
/// Check if the fade container removes user dim when suspending player for results /// Check if the fade container removes user dim when suspending <see cref="Player"/> for <see cref="SoloResults"/>
/// </summary> /// </summary>
[Test] [Test]
public void TransitionTest() public void TransitionTest()
{ {
performFullSetup(); performFullSetup();
AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" } }))); AddStep("Transition to Results", () => player.Push(new FadeAccessibleResults(new ScoreInfo { User = new User { Username = "osu!" } })));
waitForDim(); waitForDim();
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); AddAssert("Screen is undimmed and is original background", () => songSelect.IsBackgroundUndimmed() && songSelect.IsBackgroundCurrent());
AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent());
} }
/// <summary> /// <summary>
/// Check if background gets undimmed when leaving the player for the previous screen /// Check if background gets undimmed when leaving <see cref="Player"/> for <see cref="PlaySongSelect"/>
/// </summary> /// </summary>
[Test] [Test]
public void TransitionOutTest() public void TransitionOutTest()
{ {
performFullSetup(); performFullSetup();
AddUntilStep(() => AddStep("Exit to song select", () => player.Exit());
{
if (!songSelect.IsCurrentScreen())
{
songSelect.MakeCurrent();
return false;
}
return true;
}, "Wait for song select is current");
waitForDim(); waitForDim();
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed());
} }
private void waitForDim() => AddWaitStep(5, "Wait for dim"); private void waitForDim() => AddWaitStep(5, "Wait for dim");
private void createFakeStoryboard() => AddStep("Enable storyboard", () => private void createFakeStoryboard() => AddStep("Create storyboard", () =>
{ {
player.ReplacesBackground.Value = true; player.StoryboardEnabled.Value = false;
player.StoryboardEnabled.Value = true; player.ReplacesBackground.Value = false;
player.CurrentStoryboardContainer.Add(new SpriteText player.CurrentStoryboardContainer.Add(new SpriteText
{ {
Size = new Vector2(250, 50), Size = new Vector2(250, 50),
@ -271,8 +245,6 @@ namespace osu.Game.Tests.Visual
{ {
songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer
{ {
AllowLeadIn = false,
AllowResults = false,
AllowPause = allowPause, AllowPause = allowPause,
Ready = true, Ready = true,
})); }));
@ -332,9 +304,9 @@ namespace osu.Game.Tests.Visual
public bool IsBackgroundCurrent() => ((FadeAccessibleBackground)Background).IsCurrentScreen(); public bool IsBackgroundCurrent() => ((FadeAccessibleBackground)Background).IsCurrentScreen();
} }
private class FadeAccesibleResults : SoloResults private class FadeAccessibleResults : SoloResults
{ {
public FadeAccesibleResults(ScoreInfo score) public FadeAccessibleResults(ScoreInfo score)
: base(score) : base(score)
{ {
} }
@ -356,6 +328,8 @@ namespace osu.Game.Tests.Visual
}; };
} }
public PauseContainer CurrentPauseContainer => PauseContainer;
public UserDimContainer CurrentStoryboardContainer => StoryboardContainer; public UserDimContainer CurrentStoryboardContainer => StoryboardContainer;
// Whether or not the player should be allowed to load. // Whether or not the player should be allowed to load.
@ -404,23 +378,22 @@ namespace osu.Game.Tests.Visual
{ {
} }
public void TriggerOnHover() public void TriggerOnHover() => OnHover(new HoverEvent(new InputState()));
{
OnHover(new HoverEvent(new InputState()));
}
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
} }
private class FadeAccessibleBackground : BackgroundScreenBeatmap private class FadeAccessibleBackground : BackgroundScreenBeatmap
{ {
protected override UserDimContainer CreateFadeContainer() => new TestUserDimContainer { RelativeSizeAxes = Axes.Both }; protected override UserDimContainer CreateFadeContainer() => fadeContainer = new TestUserDimContainer { RelativeSizeAxes = Axes.Both };
public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour; public Color4 CurrentColour => fadeContainer.CurrentColour;
public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha; public float CurrentAlpha => fadeContainer.CurrentAlpha;
public Vector2 CurrentBlur => Background.BlurSigma; public Vector2 CurrentBlur => Background.BlurSigma;
private TestUserDimContainer fadeContainer;
public FadeAccessibleBackground(WorkingBeatmap beatmap) public FadeAccessibleBackground(WorkingBeatmap beatmap)
: base(beatmap) : base(beatmap)
{ {
@ -429,13 +402,13 @@ namespace osu.Game.Tests.Visual
private class TestUserDimContainer : UserDimContainer private class TestUserDimContainer : UserDimContainer
{ {
public Color4 CurrentColour => DimContainer.Colour;
public float CurrentAlpha => DimContainer.Alpha;
public TestUserDimContainer(bool isStoryboard = false) public TestUserDimContainer(bool isStoryboard = false)
: base(isStoryboard) : base(isStoryboard)
{ {
} }
public Color4 CurrentColour => DimContainer.Colour;
public float CurrentAlpha => DimContainer.Alpha;
} }
} }
} }

View File

@ -16,6 +16,8 @@ namespace osu.Game.Graphics.Containers
/// </summary> /// </summary>
public class UserDimContainer : Container public class UserDimContainer : Container
{ {
private const float background_fade_duration = 800;
protected Bindable<double> DimLevel { get; private set; } protected Bindable<double> DimLevel { get; private set; }
protected Bindable<bool> ShowStoryboard { get; private set; } protected Bindable<bool> ShowStoryboard { get; private set; }
@ -30,14 +32,12 @@ namespace osu.Game.Graphics.Containers
/// </summary> /// </summary>
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>(); public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
protected Container DimContainer { get; private set; } protected Container DimContainer { get; }
protected override Container<Drawable> Content => DimContainer; protected override Container<Drawable> Content => DimContainer;
private readonly bool isStoryboard; private readonly bool isStoryboard;
private const float background_fade_duration = 800;
/// <summary> /// <summary>
/// Creates a new <see cref="UserDimContainer" />. /// Creates a new <see cref="UserDimContainer" />.
/// </summary> /// </summary>
@ -48,9 +48,8 @@ namespace osu.Game.Graphics.Containers
/// </param> /// </param>
public UserDimContainer(bool isStoryboard = false) public UserDimContainer(bool isStoryboard = false)
{ {
DimContainer = new Container { RelativeSizeAxes = Axes.Both };
this.isStoryboard = isStoryboard; this.isStoryboard = isStoryboard;
AddInternal(DimContainer); AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both });
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Users;
namespace osu.Game.Screens.Backgrounds namespace osu.Game.Screens.Backgrounds
{ {
@ -22,7 +23,7 @@ namespace osu.Game.Screens.Backgrounds
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>(); public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
protected UserDimContainer FadeContainer { get; private set; } private readonly UserDimContainer fadeContainer;
protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both }; protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both };
@ -50,9 +51,9 @@ namespace osu.Game.Screens.Backgrounds
} }
b.Depth = newDepth; b.Depth = newDepth;
FadeContainer.Add(Background = b); fadeContainer.Add(Background = b);
Background.BlurSigma = BlurTarget; Background.BlurSigma = BlurTarget;
FadeContainer.StoryboardReplacesBackground.BindTo(StoryboardReplacesBackground); StoryboardReplacesBackground.BindTo(fadeContainer.StoryboardReplacesBackground);
})); }));
}); });
} }
@ -60,10 +61,9 @@ namespace osu.Game.Screens.Backgrounds
public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null)
{ {
FadeContainer = CreateFadeContainer();
InternalChild = FadeContainer;
EnableUserDim.BindTo(FadeContainer.EnableUserDim);
Beatmap = beatmap; Beatmap = beatmap;
InternalChild = fadeContainer = CreateFadeContainer();
fadeContainer.EnableUserDim.BindTo(EnableUserDim);
} }
public override bool Equals(BackgroundScreen other) public override bool Equals(BackgroundScreen other)

View File

@ -72,7 +72,7 @@ namespace osu.Game.Screens.Play
[Resolved] [Resolved]
private ScoreManager scoreManager { get; set; } private ScoreManager scoreManager { get; set; }
private PauseContainer pauseContainer; protected PauseContainer PauseContainer { get; private set; }
private RulesetInfo ruleset; private RulesetInfo ruleset;
@ -80,10 +80,10 @@ namespace osu.Game.Screens.Play
private SampleChannel sampleRestart; private SampleChannel sampleRestart;
protected ScoreProcessor ScoreProcessor; protected ScoreProcessor ScoreProcessor { get; private set; }
protected RulesetContainer RulesetContainer; protected RulesetContainer RulesetContainer { get; private set; }
protected HUDOverlay HUDOverlay; protected HUDOverlay HUDOverlay { get; private set; }
private FailOverlay failOverlay; private FailOverlay failOverlay;
private DrawableStoryboard storyboard; private DrawableStoryboard storyboard;
@ -175,7 +175,7 @@ namespace osu.Game.Screens.Play
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
pauseContainer = new PauseContainer(offsetClock, adjustableClock) PauseContainer = new PauseContainer(offsetClock, adjustableClock)
{ {
Retries = RestartCount, Retries = RestartCount,
OnRetry = Restart, OnRetry = Restart,
@ -239,7 +239,7 @@ namespace osu.Game.Screens.Play
HUDOverlay.HoldToQuit.Action = performUserRequestedExit; HUDOverlay.HoldToQuit.Action = performUserRequestedExit;
HUDOverlay.KeyCounter.Visible.BindTo(RulesetContainer.HasReplayLoaded); HUDOverlay.KeyCounter.Visible.BindTo(RulesetContainer.HasReplayLoaded);
RulesetContainer.IsPaused.BindTo(pauseContainer.IsPaused); RulesetContainer.IsPaused.BindTo(PauseContainer.IsPaused);
if (ShowStoryboard.Value) if (ShowStoryboard.Value)
initializeStoryboard(false); initializeStoryboard(false);
@ -357,7 +357,7 @@ namespace osu.Game.Screens.Play
Background.EnableUserDim.Value = true; Background.EnableUserDim.Value = true;
storyboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground); Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground); StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
@ -372,7 +372,7 @@ namespace osu.Game.Screens.Play
this.Delay(750).Schedule(() => this.Delay(750).Schedule(() =>
{ {
if (!pauseContainer.IsPaused.Value) if (!PauseContainer.IsPaused.Value)
{ {
adjustableClock.Start(); adjustableClock.Start();
} }
@ -380,8 +380,8 @@ namespace osu.Game.Screens.Play
}); });
}); });
pauseContainer.Alpha = 0; PauseContainer.Alpha = 0;
pauseContainer.FadeIn(750, Easing.OutQuint); PauseContainer.FadeIn(750, Easing.OutQuint);
} }
public override void OnSuspending(IScreen next) public override void OnSuspending(IScreen next)
@ -399,7 +399,7 @@ namespace osu.Game.Screens.Play
return true; return true;
} }
if ((!AllowPause || HasFailed || !ValidForResume || pauseContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!pauseContainer?.IsResuming ?? true)) if ((!AllowPause || HasFailed || !ValidForResume || PauseContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!PauseContainer?.IsResuming ?? true))
{ {
// In the case of replays, we may have changed the playback rate. // In the case of replays, we may have changed the playback rate.
applyRateFromMods(); applyRateFromMods();
@ -408,7 +408,7 @@ namespace osu.Game.Screens.Play
} }
if (LoadedBeatmapSuccessfully) if (LoadedBeatmapSuccessfully)
pauseContainer?.Pause(); PauseContainer?.Pause();
return true; return true;
} }
@ -421,7 +421,7 @@ namespace osu.Game.Screens.Play
storyboardReplacesBackground.Value = false; storyboardReplacesBackground.Value = false;
} }
protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !pauseContainer.IsPaused.Value; protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !PauseContainer.IsPaused.Value;
private void initializeStoryboard(bool asyncLoad) private void initializeStoryboard(bool asyncLoad)
{ {