diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs index 49fc81752c..006d64491a 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs @@ -4,10 +4,13 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Screens; +using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Online.Spectator; using osu.Game.Replays.Legacy; using osu.Game.Screens.Play; +using osu.Game.Tests.Beatmaps.IO; using osu.Game.Users; namespace osu.Game.Tests.Visual.Gameplay @@ -17,14 +20,28 @@ namespace osu.Game.Tests.Visual.Gameplay [Cached(typeof(SpectatorStreamingClient))] private TestSpectatorStreamingClient testSpectatorStreamingClient = new TestSpectatorStreamingClient(); + private Spectator spectatorScreen; + [Resolved] private OsuGameBase game { get; set; } + public override void SetUpSteps() + { + base.SetUpSteps(); + + AddStep("import beatmap", () => ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).Wait()); + + AddStep("add streaming client", () => + { + Remove(testSpectatorStreamingClient); + Add(testSpectatorStreamingClient); + }); + } + [Test] public void TestBasicSpectatingFlow() { - AddStep("add streaming client", () => Add(testSpectatorStreamingClient)); - AddStep("load screen", () => LoadScreen(new Spectator(testSpectatorStreamingClient.StreamingUser))); + beginSpectating(); AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); } @@ -32,27 +49,68 @@ namespace osu.Game.Tests.Visual.Gameplay [Test] public void TestSpectatingDuringGameplay() { + AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); + AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); + // should seek immediately to available frames + beginSpectating(); } [Test] public void TestHostStartsPlayingWhileAlreadyWatching() { + beginSpectating(); + + AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); + AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); + + AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); + AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); // should restart either immediately or after running out of frames } [Test] public void TestHostFails() { + beginSpectating(); + + AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); + AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); + // todo: send fail state + // should replay until running out of frames then fail } [Test] public void TestStopWatchingDuringPlay() { + beginSpectating(); + + AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); + AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); + + AddUntilStep("wait for player", () => Stack.CurrentScreen is Player); + // should immediately exit and unbind from streaming client + AddStep("stop spectating", () => (Stack.CurrentScreen as Player)?.Exit()); + + AddUntilStep("spectating stopped", () => spectatorScreen.GetParentScreen() == null); } + [Test] + public void TestWatchingBeatmapThatDoesntExistLocally() + { + beginSpectating(); + + AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); + AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); + + // player should never arrive. + } + + private void beginSpectating() => + AddStep("load screen", () => LoadScreen(spectatorScreen = new Spectator(testSpectatorStreamingClient.StreamingUser))); + internal class TestSpectatorStreamingClient : SpectatorStreamingClient { [Resolved] @@ -64,7 +122,16 @@ namespace osu.Game.Tests.Visual.Gameplay { ((ISpectatorClient)this).UserBeganPlaying((int)StreamingUser.Id, new SpectatorState { - BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First().OnlineBeatmapID, + BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First(b => b.RulesetID == 0).OnlineBeatmapID, + RulesetID = 0, + }); + } + + public void EndPlay() + { + ((ISpectatorClient)this).UserFinishedPlaying((int)StreamingUser.Id, new SpectatorState + { + BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First(b => b.RulesetID == 0).OnlineBeatmapID, RulesetID = 0, }); }