mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:37:28 +08:00
Merge pull request #19796 from peppy/fix-player-loader-tests-volume-adjustment
Fix running `TestScenePlayerLoader` interactively leaving volume in a bad state
This commit is contained in:
commit
26568f7ac9
@ -56,6 +56,10 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
private readonly ChangelogOverlay changelogOverlay;
|
||||
|
||||
private double savedTrackVolume;
|
||||
private double savedMasterVolume;
|
||||
private bool savedMutedState;
|
||||
|
||||
public TestScenePlayerLoader()
|
||||
{
|
||||
AddRange(new Drawable[]
|
||||
@ -75,11 +79,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup() => Schedule(() =>
|
||||
{
|
||||
player = null;
|
||||
audioManager.Volume.SetDefault();
|
||||
});
|
||||
public void Setup() => Schedule(() => player = null);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the input manager child to a new test player loader container instance.
|
||||
@ -147,6 +147,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
moveMouse();
|
||||
return player?.LoadState == LoadState.Ready;
|
||||
});
|
||||
|
||||
AddRepeatStep("move mouse", moveMouse, 20);
|
||||
|
||||
AddAssert("loader still active", () => loader.IsCurrentScreen());
|
||||
@ -154,6 +155,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
void moveMouse()
|
||||
{
|
||||
notificationOverlay.State.Value = Visibility.Hidden;
|
||||
|
||||
InputManager.MoveMouseTo(
|
||||
loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft
|
||||
+ (loader.VisualSettings.ScreenSpaceDrawQuad.BottomRight - loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft)
|
||||
@ -274,6 +277,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddStep("load player", () => resetPlayer(false, beforeLoad));
|
||||
AddUntilStep("wait for player", () => player?.LoadState == LoadState.Ready);
|
||||
|
||||
saveVolumes();
|
||||
|
||||
AddAssert("check for notification", () => notificationOverlay.UnreadCount.Value == 1);
|
||||
AddStep("click notification", () =>
|
||||
{
|
||||
@ -287,6 +292,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
AddAssert("check " + volumeName, assert);
|
||||
|
||||
restoreVolumes();
|
||||
|
||||
AddUntilStep("wait for player load", () => player.IsLoaded);
|
||||
}
|
||||
|
||||
@ -294,6 +301,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[TestCase(false)]
|
||||
public void TestEpilepsyWarning(bool warning)
|
||||
{
|
||||
saveVolumes();
|
||||
setFullVolume();
|
||||
|
||||
AddStep("change epilepsy warning", () => epilepsyWarning = warning);
|
||||
AddStep("load dummy beatmap", () => resetPlayer(false));
|
||||
|
||||
@ -306,6 +316,30 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddUntilStep("sound volume decreased", () => Beatmap.Value.Track.AggregateVolume.Value == 0.25);
|
||||
AddUntilStep("sound volume restored", () => Beatmap.Value.Track.AggregateVolume.Value == 1);
|
||||
}
|
||||
|
||||
restoreVolumes();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEpilepsyWarningEarlyExit()
|
||||
{
|
||||
saveVolumes();
|
||||
setFullVolume();
|
||||
|
||||
AddStep("set epilepsy warning", () => epilepsyWarning = true);
|
||||
AddStep("load dummy beatmap", () => resetPlayer(false));
|
||||
|
||||
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
||||
|
||||
AddUntilStep("wait for epilepsy warning", () => getWarning().Alpha > 0);
|
||||
AddUntilStep("warning is shown", () => getWarning().State.Value == Visibility.Visible);
|
||||
|
||||
AddStep("exit early", () => loader.Exit());
|
||||
|
||||
AddUntilStep("warning is hidden", () => getWarning().State.Value == Visibility.Hidden);
|
||||
AddUntilStep("sound volume restored", () => Beatmap.Value.Track.AggregateVolume.Value == 1);
|
||||
|
||||
restoreVolumes();
|
||||
}
|
||||
|
||||
[TestCase(true, 1.0, false)] // on battery, above cutoff --> no warning
|
||||
@ -336,21 +370,34 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddUntilStep("wait for player load", () => player.IsLoaded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEpilepsyWarningEarlyExit()
|
||||
private void restoreVolumes()
|
||||
{
|
||||
AddStep("set epilepsy warning", () => epilepsyWarning = true);
|
||||
AddStep("load dummy beatmap", () => resetPlayer(false));
|
||||
AddStep("restore previous volumes", () =>
|
||||
{
|
||||
audioManager.VolumeTrack.Value = savedTrackVolume;
|
||||
audioManager.Volume.Value = savedMasterVolume;
|
||||
volumeOverlay.IsMuted.Value = savedMutedState;
|
||||
});
|
||||
}
|
||||
|
||||
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
||||
private void setFullVolume()
|
||||
{
|
||||
AddStep("set volumes to 100%", () =>
|
||||
{
|
||||
audioManager.VolumeTrack.Value = 1;
|
||||
audioManager.Volume.Value = 1;
|
||||
volumeOverlay.IsMuted.Value = false;
|
||||
});
|
||||
}
|
||||
|
||||
AddUntilStep("wait for epilepsy warning", () => getWarning().Alpha > 0);
|
||||
AddUntilStep("warning is shown", () => getWarning().State.Value == Visibility.Visible);
|
||||
|
||||
AddStep("exit early", () => loader.Exit());
|
||||
|
||||
AddUntilStep("warning is hidden", () => getWarning().State.Value == Visibility.Hidden);
|
||||
AddUntilStep("sound volume restored", () => Beatmap.Value.Track.AggregateVolume.Value == 1);
|
||||
private void saveVolumes()
|
||||
{
|
||||
AddStep("save previous volumes", () =>
|
||||
{
|
||||
savedTrackVolume = audioManager.VolumeTrack.Value;
|
||||
savedMasterVolume = audioManager.Volume.Value;
|
||||
savedMutedState = volumeOverlay.IsMuted.Value;
|
||||
});
|
||||
}
|
||||
|
||||
private EpilepsyWarning getWarning() => loader.ChildrenOfType<EpilepsyWarning>().SingleOrDefault();
|
||||
|
Loading…
Reference in New Issue
Block a user