1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 19:32:54 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestScenePauseWhenInactive.cs

89 lines
3.4 KiB
C#
Raw Normal View History

2019-12-11 14:24:06 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-02-19 14:34:39 +08:00
using System.Collections.Generic;
2019-12-11 14:24:06 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
2021-02-19 14:34:39 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Storyboards;
using osu.Game.Tests.Beatmaps;
using osuTK;
2019-12-11 14:24:06 +08:00
namespace osu.Game.Tests.Visual.Gameplay
{
[HeadlessTest] // we alter unsafe properties on the game host to test inactive window state.
2020-06-12 18:40:54 +08:00
public class TestScenePauseWhenInactive : OsuPlayerTestScene
2019-12-11 14:24:06 +08:00
{
[Resolved]
private GameHost host { get; set; }
[Test]
public void TestDoesntPauseDuringIntro()
{
AddStep("set inactive", () => ((Bindable<bool>)host.IsActive).Value = false);
2019-12-11 14:47:34 +08:00
2019-12-11 14:24:06 +08:00
AddStep("resume player", () => Player.GameplayClockContainer.Start());
2019-12-11 14:47:34 +08:00
AddAssert("ensure not paused", () => !Player.GameplayClockContainer.IsPaused.Value);
2021-02-19 14:34:39 +08:00
AddStep("progress time to gameplay", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.GameplayStartTime));
AddUntilStep("wait for pause", () => Player.GameplayClockContainer.IsPaused.Value);
}
/// <summary>
/// Tests that if a pause from focus lose is performed while in pause cooldown,
/// the player will still pause after the cooldown is finished.
/// </summary>
[Test]
public void TestPauseWhileInCooldown()
{
AddStep("move cursor outside", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.TopLeft - new Vector2(10)));
2021-02-19 14:34:39 +08:00
AddStep("resume player", () => Player.GameplayClockContainer.Start());
AddStep("skip to gameplay", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.GameplayStartTime));
AddStep("set inactive", () => ((Bindable<bool>)host.IsActive).Value = false);
AddUntilStep("wait for pause", () => Player.GameplayClockContainer.IsPaused.Value);
AddStep("set active", () => ((Bindable<bool>)host.IsActive).Value = true);
AddStep("resume player", () => Player.Resume());
AddAssert("unpaused", () => !Player.GameplayClockContainer.IsPaused.Value);
bool pauseCooldownActive = false;
AddStep("set inactive again", () =>
2021-02-19 14:34:39 +08:00
{
pauseCooldownActive = Player.PauseCooldownActive;
((Bindable<bool>)host.IsActive).Value = false;
2021-02-19 14:34:39 +08:00
});
AddAssert("pause cooldown active", () => pauseCooldownActive);
2019-12-11 14:24:06 +08:00
AddUntilStep("wait for pause", () => Player.GameplayClockContainer.IsPaused.Value);
}
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(true, true, true);
2021-02-19 14:34:39 +08:00
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset)
{
return new Beatmap
{
HitObjects = new List<HitObject>
{
new HitCircle { StartTime = 30000 },
new HitCircle { StartTime = 35000 },
},
};
}
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
=> new TestWorkingBeatmap(beatmap, storyboard, Audio);
2019-12-11 14:24:06 +08:00
}
}