2020-12-21 17:42:31 +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.
|
|
|
|
|
2021-05-11 18:31:32 +08:00
|
|
|
using System;
|
2021-05-11 18:01:41 +08:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2021-03-03 20:54:34 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-05-11 18:01:41 +08:00
|
|
|
using osu.Framework.Audio;
|
2021-06-22 23:48:41 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-11 18:01:41 +08:00
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-06-22 23:48:41 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-03-03 20:54:34 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-05-11 18:01:41 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2021-06-22 23:48:41 +08:00
|
|
|
using osu.Game.Overlays.Mods;
|
2021-05-11 18:01:41 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-06-22 23:48:41 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
2021-06-22 23:48:41 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
2021-05-11 18:31:32 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
2021-05-11 18:01:41 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK.Input;
|
2020-12-21 17:42:31 +08:00
|
|
|
|
2020-12-25 12:20:37 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2020-12-21 17:42:31 +08:00
|
|
|
{
|
2021-03-03 20:54:34 +08:00
|
|
|
public class TestSceneMultiplayer : ScreenTestScene
|
2020-12-21 17:42:31 +08:00
|
|
|
{
|
2021-03-03 21:07:39 +08:00
|
|
|
private TestMultiplayer multiplayerScreen;
|
|
|
|
|
2021-05-11 18:01:41 +08:00
|
|
|
private BeatmapManager beatmaps;
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
private BeatmapSetInfo importedSet;
|
|
|
|
|
|
|
|
private TestMultiplayerClient client => multiplayerScreen.Client;
|
|
|
|
private Room room => client.APIRoom;
|
|
|
|
|
2020-12-25 12:38:11 +08:00
|
|
|
public TestSceneMultiplayer()
|
2021-05-11 18:01:41 +08:00
|
|
|
{
|
|
|
|
loadMultiplayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost host, AudioManager audio)
|
|
|
|
{
|
|
|
|
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
2021-05-31 17:37:32 +08:00
|
|
|
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
|
2021-05-11 18:26:58 +08:00
|
|
|
}
|
2021-05-11 18:01:41 +08:00
|
|
|
|
2021-05-11 18:26:58 +08:00
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
|
|
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
2021-05-11 18:01:41 +08:00
|
|
|
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
2021-05-11 18:26:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestUserSetToIdleWhenBeatmapDeleted()
|
|
|
|
{
|
|
|
|
loadMultiplayer();
|
|
|
|
|
2021-05-11 18:31:32 +08:00
|
|
|
createRoom(() => new Room
|
2021-05-11 18:26:58 +08:00
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("set user ready", () => client.ChangeState(MultiplayerUserState.Ready));
|
|
|
|
AddStep("delete beatmap", () => beatmaps.Delete(importedSet));
|
|
|
|
|
2021-05-13 10:53:50 +08:00
|
|
|
AddUntilStep("user state is idle", () => client.LocalUser?.State == MultiplayerUserState.Idle);
|
2021-05-11 18:01:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-05-11 18:21:44 +08:00
|
|
|
public void TestLocalPlayDoesNotStartWhileSpectatingWithNoBeatmap()
|
2021-05-11 18:01:41 +08:00
|
|
|
{
|
|
|
|
loadMultiplayer();
|
|
|
|
|
2021-05-11 18:31:32 +08:00
|
|
|
createRoom(() => new Room
|
2021-05-11 18:01:41 +08:00
|
|
|
{
|
2021-05-11 18:21:44 +08:00
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Playlist =
|
2021-05-11 18:01:41 +08:00
|
|
|
{
|
2021-05-11 18:21:44 +08:00
|
|
|
new PlaylistItem
|
2021-05-11 18:01:41 +08:00
|
|
|
{
|
2021-05-11 18:21:44 +08:00
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
2021-05-11 18:01:41 +08:00
|
|
|
}
|
2021-05-11 18:21:44 +08:00
|
|
|
}
|
2021-05-11 18:01:41 +08:00
|
|
|
});
|
|
|
|
|
2021-05-11 18:21:44 +08:00
|
|
|
AddStep("join other user (ready, host)", () =>
|
2021-05-11 18:01:41 +08:00
|
|
|
{
|
2021-05-11 18:21:44 +08:00
|
|
|
client.AddUser(new User { Id = MultiplayerTestScene.PLAYER_1_ID, Username = "Other" });
|
|
|
|
client.TransferHost(MultiplayerTestScene.PLAYER_1_ID);
|
|
|
|
client.ChangeUserState(MultiplayerTestScene.PLAYER_1_ID, MultiplayerUserState.Ready);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("delete beatmap", () => beatmaps.Delete(importedSet));
|
|
|
|
|
|
|
|
AddStep("click spectate button", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerSpectateButton>().Single());
|
2021-05-11 18:01:41 +08:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
2021-05-11 18:21:44 +08:00
|
|
|
AddStep("start match externally", () => client.StartMatch());
|
|
|
|
|
|
|
|
AddAssert("play not started", () => multiplayerScreen.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLocalPlayStartsWhileSpectatingWhenBeatmapBecomesAvailable()
|
|
|
|
{
|
|
|
|
loadMultiplayer();
|
|
|
|
|
2021-05-11 18:31:32 +08:00
|
|
|
createRoom(() => new Room
|
2021-05-11 18:21:44 +08:00
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("delete beatmap", () => beatmaps.Delete(importedSet));
|
2021-05-11 18:01:41 +08:00
|
|
|
|
|
|
|
AddStep("join other user (ready, host)", () =>
|
|
|
|
{
|
|
|
|
client.AddUser(new User { Id = MultiplayerTestScene.PLAYER_1_ID, Username = "Other" });
|
|
|
|
client.TransferHost(MultiplayerTestScene.PLAYER_1_ID);
|
|
|
|
client.ChangeUserState(MultiplayerTestScene.PLAYER_1_ID, MultiplayerUserState.Ready);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("click spectate button", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerSpectateButton>().Single());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("start match externally", () => client.StartMatch());
|
|
|
|
|
2021-05-11 18:21:44 +08:00
|
|
|
AddStep("restore beatmap", () =>
|
|
|
|
{
|
|
|
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
|
|
|
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("play started", () => !multiplayerScreen.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2021-06-22 23:48:41 +08:00
|
|
|
[Test]
|
|
|
|
public void TestLeaveNavigation()
|
|
|
|
{
|
|
|
|
loadMultiplayer();
|
|
|
|
|
|
|
|
createRoom(() => new Room
|
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
AllowedMods = { new OsuModHidden() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("open mod overlay", () => this.ChildrenOfType<PurpleTriangleButton>().ElementAt(2).Click());
|
|
|
|
|
|
|
|
AddStep("invoke on back button", () => multiplayerScreen.OnBackButton());
|
|
|
|
|
|
|
|
AddAssert("mod overlay is hidden", () => this.ChildrenOfType<LocalPlayerModSelectOverlay>().Single().State.Value == Visibility.Hidden);
|
|
|
|
|
|
|
|
AddAssert("dialog overlay is hidden", () => DialogOverlay.State.Value == Visibility.Hidden);
|
|
|
|
|
|
|
|
testLeave("lounge tab item", () => this.ChildrenOfType<BreadcrumbControl<IScreen>.BreadcrumbTabItem>().First().Click());
|
|
|
|
|
|
|
|
testLeave("back button", () => multiplayerScreen.OnBackButton());
|
|
|
|
|
|
|
|
// mimics home button and OS window close
|
|
|
|
testLeave("forced exit", () => multiplayerScreen.Exit());
|
|
|
|
|
|
|
|
void testLeave(string actionName, Action action)
|
|
|
|
{
|
|
|
|
AddStep($"leave via {actionName}", action);
|
|
|
|
|
|
|
|
AddAssert("dialog overlay is visible", () => DialogOverlay.State.Value == Visibility.Visible);
|
|
|
|
|
|
|
|
AddStep("close dialog overlay", () => InputManager.Key(Key.Escape));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-11 18:31:32 +08:00
|
|
|
private void createRoom(Func<Room> room)
|
2021-05-11 18:21:44 +08:00
|
|
|
{
|
|
|
|
AddStep("open room", () =>
|
|
|
|
{
|
2021-05-11 18:31:32 +08:00
|
|
|
multiplayerScreen.OpenNewRoom(room());
|
2021-05-11 18:21:44 +08:00
|
|
|
});
|
|
|
|
|
2021-05-11 18:31:32 +08:00
|
|
|
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
|
|
|
AddWaitStep("wait for transition", 2);
|
|
|
|
|
2021-05-11 18:21:44 +08:00
|
|
|
AddStep("create room", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for join", () => client.Room != null);
|
2021-05-11 18:01:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void loadMultiplayer()
|
2020-12-21 17:42:31 +08:00
|
|
|
{
|
2021-03-03 21:07:39 +08:00
|
|
|
AddStep("show", () =>
|
|
|
|
{
|
|
|
|
multiplayerScreen = new TestMultiplayer();
|
|
|
|
|
|
|
|
// Needs to be added at a higher level since the multiplayer screen becomes non-current.
|
|
|
|
Child = multiplayerScreen.Client;
|
|
|
|
|
|
|
|
LoadScreen(multiplayerScreen);
|
|
|
|
});
|
2020-12-21 17:42:31 +08:00
|
|
|
|
2021-03-03 21:07:39 +08:00
|
|
|
AddUntilStep("wait for loaded", () => multiplayerScreen.IsLoaded);
|
2020-12-21 17:42:31 +08:00
|
|
|
}
|
|
|
|
|
2021-03-03 20:54:34 +08:00
|
|
|
private class TestMultiplayer : Screens.OnlinePlay.Multiplayer.Multiplayer
|
2020-12-24 04:00:47 +08:00
|
|
|
{
|
2021-05-20 14:39:45 +08:00
|
|
|
[Cached(typeof(MultiplayerClient))]
|
2021-03-03 20:54:34 +08:00
|
|
|
public readonly TestMultiplayerClient Client;
|
2020-12-24 04:00:47 +08:00
|
|
|
|
2021-03-03 20:54:34 +08:00
|
|
|
public TestMultiplayer()
|
|
|
|
{
|
2021-03-03 21:07:39 +08:00
|
|
|
Client = new TestMultiplayerClient((TestMultiplayerRoomManager)RoomManager);
|
2021-03-03 20:54:34 +08:00
|
|
|
}
|
2020-12-24 04:00:47 +08:00
|
|
|
|
2020-12-25 12:38:11 +08:00
|
|
|
protected override RoomManager CreateRoomManager() => new TestMultiplayerRoomManager();
|
2020-12-21 17:42:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|