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-08-27 17:57:35 +08:00
|
|
|
using System.Diagnostics;
|
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-07-19 19:55:14 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-08-03 17:37:09 +08:00
|
|
|
using osu.Framework.Input;
|
2021-05-11 18:01:41 +08:00
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Testing;
|
2021-08-27 17:44:44 +08:00
|
|
|
using osu.Framework.Utils;
|
2021-05-11 18:01:41 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-07-05 18:41:00 +08:00
|
|
|
using osu.Game.Database;
|
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;
|
2021-06-25 18:16:54 +08:00
|
|
|
using osu.Game.Screens;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
2021-07-13 16:31:28 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
2021-07-19 19:55:14 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
2021-08-13 13:04:43 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match;
|
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;
|
2021-08-24 12:20:01 +08:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osu.Game.Screens.Ranking;
|
2021-05-11 18:01:41 +08:00
|
|
|
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-05-11 18:01:41 +08:00
|
|
|
private BeatmapManager beatmaps;
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
private BeatmapSetInfo importedSet;
|
|
|
|
|
2021-06-25 18:16:54 +08:00
|
|
|
private DependenciesScreen dependenciesScreen;
|
|
|
|
private TestMultiplayer multiplayerScreen;
|
|
|
|
private TestMultiplayerClient client;
|
2021-05-11 18:01:41 +08:00
|
|
|
|
2021-08-17 08:45:10 +08:00
|
|
|
private TestRequestHandlingMultiplayerRoomManager roomManager => multiplayerScreen.RoomManager;
|
|
|
|
|
2021-07-05 18:41:00 +08:00
|
|
|
[Cached(typeof(UserLookupCache))]
|
|
|
|
private UserLookupCache lookupCache = new TestUserLookupCache();
|
|
|
|
|
2021-05-11 18:01:41 +08:00
|
|
|
[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-07-05 18:10:27 +08:00
|
|
|
public override void SetUpSteps()
|
2021-05-11 18:26:58 +08:00
|
|
|
{
|
2021-07-05 18:10:27 +08:00
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
|
|
AddStep("import beatmap", () =>
|
|
|
|
{
|
|
|
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
|
|
|
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("create multiplayer screen", () => multiplayerScreen = new TestMultiplayer());
|
|
|
|
|
|
|
|
AddStep("load dependencies", () =>
|
|
|
|
{
|
2021-08-17 08:45:10 +08:00
|
|
|
client = new TestMultiplayerClient(roomManager);
|
2021-07-05 18:10:27 +08:00
|
|
|
|
|
|
|
// The screen gets suspended so it stops receiving updates.
|
|
|
|
Child = client;
|
|
|
|
|
|
|
|
LoadScreen(dependenciesScreen = new DependenciesScreen(client));
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for dependencies to load", () => dependenciesScreen.IsLoaded);
|
|
|
|
|
|
|
|
AddStep("load multiplayer", () => LoadScreen(multiplayerScreen));
|
|
|
|
AddUntilStep("wait for multiplayer to load", () => multiplayerScreen.IsLoaded);
|
2021-07-26 13:29:16 +08:00
|
|
|
AddUntilStep("wait for lounge to load", () => this.ChildrenOfType<MultiplayerLoungeSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
2021-07-05 18:10:27 +08:00
|
|
|
}
|
2021-05-11 18:26:58 +08:00
|
|
|
|
|
|
|
[Test]
|
2021-07-05 18:10:27 +08:00
|
|
|
public void TestEmpty()
|
2021-05-11 18:26:58 +08:00
|
|
|
{
|
2021-07-05 18:10:27 +08:00
|
|
|
// used to test the flow of multiplayer from visual tests.
|
2021-08-06 18:40:29 +08:00
|
|
|
AddStep("empty step", () => { });
|
2021-07-05 18:10:27 +08:00
|
|
|
}
|
2021-05-11 18:26:58 +08:00
|
|
|
|
2021-08-27 17:44:44 +08:00
|
|
|
[Test]
|
|
|
|
public void TestLobbyEvents()
|
|
|
|
{
|
|
|
|
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 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddRepeatStep("random stuff happens", performRandomAction, 30);
|
|
|
|
|
|
|
|
// ensure we have a handful of players so the ready-up sounds good :9
|
|
|
|
AddRepeatStep("player joins", addRandomPlayer, 5);
|
|
|
|
|
|
|
|
// all ready
|
|
|
|
AddUntilStep("all players ready", () =>
|
|
|
|
{
|
|
|
|
var nextUnready = client.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Idle);
|
|
|
|
if (nextUnready != null)
|
|
|
|
client.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Ready);
|
|
|
|
|
|
|
|
return client.Room?.Users.All(u => u.State == MultiplayerUserState.Ready) == true;
|
|
|
|
});
|
2021-08-27 17:57:35 +08:00
|
|
|
|
|
|
|
AddStep("unready all players at once", () =>
|
|
|
|
{
|
|
|
|
Debug.Assert(client.Room != null);
|
|
|
|
|
|
|
|
foreach (var u in client.Room.Users) client.ChangeUserState(u.UserID, MultiplayerUserState.Idle);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("ready all players at once", () =>
|
|
|
|
{
|
|
|
|
Debug.Assert(client.Room != null);
|
|
|
|
|
|
|
|
foreach (var u in client.Room.Users) client.ChangeUserState(u.UserID, MultiplayerUserState.Ready);
|
|
|
|
});
|
2021-08-27 17:44:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addRandomPlayer()
|
|
|
|
{
|
|
|
|
int randomUser = RNG.Next(200000, 500000);
|
|
|
|
client.AddUser(new User { Id = randomUser, Username = $"user {randomUser}" });
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeLastUser()
|
|
|
|
{
|
|
|
|
User lastUser = client.Room?.Users.Last().User;
|
|
|
|
|
|
|
|
if (lastUser == null || lastUser == client.LocalUser?.User)
|
|
|
|
return;
|
|
|
|
|
|
|
|
client.RemoveUser(lastUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void kickLastUser()
|
|
|
|
{
|
|
|
|
User lastUser = client.Room?.Users.Last().User;
|
|
|
|
|
|
|
|
if (lastUser == null || lastUser == client.LocalUser?.User)
|
|
|
|
return;
|
|
|
|
|
|
|
|
client.KickUser(lastUser.Id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void markNextPlayerReady()
|
|
|
|
{
|
|
|
|
var nextUnready = client.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Idle);
|
|
|
|
if (nextUnready != null)
|
|
|
|
client.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Ready);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void markNextPlayerIdle()
|
|
|
|
{
|
|
|
|
var nextUnready = client.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Ready);
|
|
|
|
if (nextUnready != null)
|
|
|
|
client.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void performRandomAction()
|
|
|
|
{
|
|
|
|
int eventToPerform = RNG.Next(1, 6);
|
|
|
|
|
|
|
|
switch (eventToPerform)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
addRandomPlayer();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
removeLastUser();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
kickLastUser();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
markNextPlayerReady();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
markNextPlayerIdle();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-03 17:37:09 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCreateRoomViaKeyboard()
|
|
|
|
{
|
|
|
|
// create room dialog
|
|
|
|
AddStep("Press new document", () => InputManager.Keys(PlatformAction.DocumentNew));
|
|
|
|
AddUntilStep("wait for settings", () => InputManager.ChildrenOfType<MultiplayerMatchSettingsOverlay>().FirstOrDefault() != null);
|
|
|
|
|
|
|
|
// edit playlist item
|
|
|
|
AddStep("Press select", () => InputManager.Key(Key.Enter));
|
|
|
|
AddUntilStep("wait for song select", () => InputManager.ChildrenOfType<MultiplayerMatchSongSelect>().FirstOrDefault() != null);
|
|
|
|
|
|
|
|
// select beatmap
|
|
|
|
AddStep("Press select", () => InputManager.Key(Key.Enter));
|
|
|
|
AddUntilStep("wait for return to screen", () => InputManager.ChildrenOfType<MultiplayerMatchSongSelect>().FirstOrDefault() == null);
|
|
|
|
|
|
|
|
// create room
|
|
|
|
AddStep("Press select", () => InputManager.Key(Key.Enter));
|
|
|
|
|
|
|
|
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
|
|
|
AddUntilStep("wait for join", () => client.Room != null);
|
|
|
|
}
|
|
|
|
|
2021-07-19 19:55:14 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCreateRoomWithoutPassword()
|
|
|
|
{
|
|
|
|
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 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-20 15:23:48 +08:00
|
|
|
[Test]
|
|
|
|
public void TestExitMidJoin()
|
|
|
|
{
|
|
|
|
AddStep("create room", () =>
|
|
|
|
{
|
2021-08-17 08:45:10 +08:00
|
|
|
roomManager.AddServerSideRoom(new Room
|
2021-07-20 15:23:48 +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 },
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 08:36:43 +08:00
|
|
|
});
|
2021-07-20 15:23:48 +08:00
|
|
|
});
|
|
|
|
|
2021-08-17 08:36:43 +08:00
|
|
|
AddStep("refresh rooms", () => this.ChildrenOfType<LoungeSubScreen>().Single().UpdateFilter());
|
|
|
|
AddUntilStep("wait for room", () => this.ChildrenOfType<DrawableRoom>().Any());
|
|
|
|
|
2021-07-20 15:23:48 +08:00
|
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
2021-08-17 08:36:43 +08:00
|
|
|
AddStep("join room and immediately exit select", () =>
|
2021-07-20 15:23:48 +08:00
|
|
|
{
|
2021-08-17 08:36:43 +08:00
|
|
|
InputManager.Key(Key.Enter);
|
2021-07-20 15:23:48 +08:00
|
|
|
Schedule(() => Stack.CurrentScreen.Exit());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-19 19:55:14 +08:00
|
|
|
[Test]
|
|
|
|
public void TestJoinRoomWithoutPassword()
|
|
|
|
{
|
|
|
|
AddStep("create room", () =>
|
|
|
|
{
|
2021-08-17 08:45:10 +08:00
|
|
|
roomManager.AddServerSideRoom(new Room
|
2021-07-19 19:55:14 +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 },
|
|
|
|
}
|
|
|
|
}
|
2021-07-26 14:47:13 +08:00
|
|
|
});
|
2021-07-19 19:55:14 +08:00
|
|
|
});
|
|
|
|
|
2021-08-17 08:36:43 +08:00
|
|
|
AddStep("refresh rooms", () => this.ChildrenOfType<LoungeSubScreen>().Single().UpdateFilter());
|
|
|
|
AddUntilStep("wait for room", () => this.ChildrenOfType<DrawableRoom>().Any());
|
|
|
|
|
2021-07-19 19:55:14 +08:00
|
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
|
|
AddStep("join room", () => InputManager.Key(Key.Enter));
|
|
|
|
|
|
|
|
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
|
|
|
AddUntilStep("wait for join", () => client.Room != null);
|
|
|
|
}
|
|
|
|
|
2021-07-19 19:08:29 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCreateRoomWithPassword()
|
|
|
|
{
|
|
|
|
createRoom(() => new Room
|
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Password = { Value = "password" },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("room has password", () => client.APIRoom?.Password.Value == "password");
|
|
|
|
}
|
|
|
|
|
2021-07-19 19:55:14 +08:00
|
|
|
[Test]
|
|
|
|
public void TestJoinRoomWithPassword()
|
|
|
|
{
|
|
|
|
AddStep("create room", () =>
|
|
|
|
{
|
2021-08-17 08:45:10 +08:00
|
|
|
roomManager.AddServerSideRoom(new Room
|
2021-07-19 19:55:14 +08:00
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Password = { Value = "password" },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
2021-07-26 14:47:13 +08:00
|
|
|
});
|
2021-07-19 19:55:14 +08:00
|
|
|
});
|
|
|
|
|
2021-08-17 08:36:43 +08:00
|
|
|
AddStep("refresh rooms", () => this.ChildrenOfType<LoungeSubScreen>().Single().UpdateFilter());
|
|
|
|
AddUntilStep("wait for room", () => this.ChildrenOfType<DrawableRoom>().Any());
|
|
|
|
|
2021-07-19 19:55:14 +08:00
|
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
|
|
AddStep("join room", () => InputManager.Key(Key.Enter));
|
|
|
|
|
2021-08-18 19:53:17 +08:00
|
|
|
DrawableLoungeRoom.PasswordEntryPopover passwordEntryPopover = null;
|
|
|
|
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
|
2021-07-19 19:55:14 +08:00
|
|
|
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "password");
|
2021-08-04 16:27:44 +08:00
|
|
|
AddStep("press join room button", () => passwordEntryPopover.ChildrenOfType<OsuButton>().First().TriggerClick());
|
2021-07-20 15:44:51 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
|
|
|
AddUntilStep("wait for join", () => client.Room != null);
|
2021-07-19 19:55:14 +08:00
|
|
|
}
|
|
|
|
|
2021-07-19 19:20:08 +08:00
|
|
|
[Test]
|
|
|
|
public void TestLocalPasswordUpdatedWhenMultiplayerSettingsChange()
|
|
|
|
{
|
|
|
|
createRoom(() => new Room
|
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Password = { Value = "password" },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("change password", () => client.ChangeSettings(password: "password2"));
|
|
|
|
AddUntilStep("local password changed", () => client.APIRoom?.Password.Value == "password2");
|
|
|
|
}
|
|
|
|
|
2021-07-05 18:10:27 +08:00
|
|
|
[Test]
|
|
|
|
public void TestUserSetToIdleWhenBeatmapDeleted()
|
|
|
|
{
|
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
|
|
|
{
|
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-08-13 12:54:52 +08:00
|
|
|
AddUntilStep("wait for spectating user state", () => client.LocalUser?.State == MultiplayerUserState.Spectating);
|
|
|
|
|
2021-05-11 18:21:44 +08:00
|
|
|
AddStep("start match externally", () => client.StartMatch());
|
|
|
|
|
|
|
|
AddAssert("play not started", () => multiplayerScreen.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLocalPlayStartsWhileSpectatingWhenBeatmapBecomesAvailable()
|
|
|
|
{
|
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);
|
|
|
|
});
|
|
|
|
|
2021-08-13 12:54:52 +08:00
|
|
|
AddUntilStep("wait for spectating user state", () => client.LocalUser?.State == MultiplayerUserState.Spectating);
|
|
|
|
|
2021-05-11 18:01:41 +08:00
|
|
|
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-07-13 16:31:28 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSubScreenExitedWhenDisconnectedFromMultiplayerServer()
|
|
|
|
{
|
|
|
|
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 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("disconnect", () => client.Disconnect());
|
|
|
|
AddUntilStep("back in lounge", () => this.ChildrenOfType<LoungeSubScreen>().FirstOrDefault()?.IsCurrentScreen() == true);
|
|
|
|
}
|
|
|
|
|
2021-06-22 23:48:41 +08:00
|
|
|
[Test]
|
|
|
|
public void TestLeaveNavigation()
|
|
|
|
{
|
|
|
|
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() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-13 13:04:43 +08:00
|
|
|
AddStep("open mod overlay", () => this.ChildrenOfType<RoomSubScreen.UserModSelectButton>().Single().TriggerClick());
|
2021-06-22 23:48:41 +08:00
|
|
|
|
|
|
|
AddStep("invoke on back button", () => multiplayerScreen.OnBackButton());
|
|
|
|
|
2021-09-01 16:22:52 +08:00
|
|
|
AddAssert("mod overlay is hidden", () => this.ChildrenOfType<UserModSelectOverlay>().Single().State.Value == Visibility.Hidden);
|
2021-06-22 23:48:41 +08:00
|
|
|
|
|
|
|
AddAssert("dialog overlay is hidden", () => DialogOverlay.State.Value == Visibility.Hidden);
|
|
|
|
|
|
|
|
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-08-24 12:20:01 +08:00
|
|
|
[Test]
|
|
|
|
public void TestGameplayFlow()
|
|
|
|
{
|
|
|
|
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 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-14 15:50:38 +08:00
|
|
|
AddUntilStep("wait for ready button to be enabled", () => readyButton.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
2021-10-14 14:58:42 +08:00
|
|
|
|
|
|
|
AddStep("click ready button", () =>
|
2021-08-24 12:20:01 +08:00
|
|
|
{
|
2021-10-14 14:58:42 +08:00
|
|
|
InputManager.MoveMouseTo(readyButton);
|
2021-08-24 12:20:01 +08:00
|
|
|
InputManager.Click(MouseButton.Left);
|
2021-10-14 14:58:42 +08:00
|
|
|
});
|
|
|
|
|
2021-10-14 15:50:38 +08:00
|
|
|
AddUntilStep("wait for player to be ready", () => client.Room?.Users[0].State == MultiplayerUserState.Ready);
|
|
|
|
AddUntilStep("wait for ready button to be enabled", () => readyButton.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
2021-10-14 14:58:42 +08:00
|
|
|
|
|
|
|
AddStep("click start button", () => InputManager.Click(MouseButton.Left));
|
2021-08-24 12:20:01 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for player", () => Stack.CurrentScreen is Player);
|
|
|
|
|
|
|
|
// Gameplay runs in real-time, so we need to incrementally check if gameplay has finished in order to not time out.
|
|
|
|
for (double i = 1000; i < TestResources.QUICK_BEATMAP_LENGTH; i += 1000)
|
|
|
|
{
|
|
|
|
var time = i;
|
|
|
|
AddUntilStep($"wait for time > {i}", () => this.ChildrenOfType<GameplayClockContainer>().SingleOrDefault()?.GameplayClock.CurrentTime > time);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddUntilStep("wait for results", () => Stack.CurrentScreen is ResultsScreen);
|
|
|
|
}
|
|
|
|
|
2021-10-14 14:58:42 +08:00
|
|
|
private MultiplayerReadyButton readyButton => this.ChildrenOfType<MultiplayerReadyButton>().Single();
|
|
|
|
|
2021-05-11 18:31:32 +08:00
|
|
|
private void createRoom(Func<Room> room)
|
2021-05-11 18:21:44 +08:00
|
|
|
{
|
2021-07-14 17:55:01 +08:00
|
|
|
AddUntilStep("wait for lounge", () => multiplayerScreen.ChildrenOfType<LoungeSubScreen>().SingleOrDefault()?.IsLoaded == true);
|
2021-08-03 19:07:42 +08:00
|
|
|
AddStep("open room", () => multiplayerScreen.ChildrenOfType<LoungeSubScreen>().Single().Open(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
|
|
|
}
|
|
|
|
|
2021-06-25 18:16:54 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Used for the sole purpose of adding <see cref="TestMultiplayerClient"/> as a resolvable dependency.
|
|
|
|
/// </summary>
|
|
|
|
private class DependenciesScreen : OsuScreen
|
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-06-25 18:16:54 +08:00
|
|
|
public DependenciesScreen(TestMultiplayerClient client)
|
2021-03-03 20:54:34 +08:00
|
|
|
{
|
2021-06-25 18:16:54 +08:00
|
|
|
Client = client;
|
2021-03-03 20:54:34 +08:00
|
|
|
}
|
2021-06-25 18:16:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestMultiplayer : Screens.OnlinePlay.Multiplayer.Multiplayer
|
|
|
|
{
|
2021-07-26 14:47:13 +08:00
|
|
|
public new TestRequestHandlingMultiplayerRoomManager RoomManager { get; private set; }
|
2020-12-24 04:00:47 +08:00
|
|
|
|
2021-07-26 14:47:13 +08:00
|
|
|
protected override RoomManager CreateRoomManager() => RoomManager = new TestRequestHandlingMultiplayerRoomManager();
|
2020-12-21 17:42:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|