2021-07-09 15:01:52 +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.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2021-07-12 14:49:09 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-07-09 15:01:52 +08:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Testing;
|
2021-07-12 14:49:09 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online.Rooms;
|
2021-07-09 15:01:52 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
|
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
2021-07-12 14:49:09 +08:00
|
|
|
using osuTK.Input;
|
2021-07-09 15:01:52 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
|
|
|
public class TestSceneMultiplayerLoungeSubScreen : OnlinePlayTestScene
|
|
|
|
{
|
2021-08-19 11:25:47 +08:00
|
|
|
protected new TestRequestHandlingRoomManager RoomManager => (TestRequestHandlingRoomManager)base.RoomManager;
|
2021-07-09 15:01:52 +08:00
|
|
|
|
|
|
|
private LoungeSubScreen loungeScreen;
|
|
|
|
|
2021-07-12 14:49:09 +08:00
|
|
|
private Room lastJoinedRoom;
|
|
|
|
private string lastJoinedPassword;
|
|
|
|
|
2021-07-09 15:01:52 +08:00
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
|
|
AddStep("push screen", () => LoadScreen(loungeScreen = new MultiplayerLoungeSubScreen()));
|
|
|
|
|
|
|
|
AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen());
|
2021-07-12 14:49:09 +08:00
|
|
|
|
|
|
|
AddStep("bind to event", () =>
|
|
|
|
{
|
|
|
|
lastJoinedRoom = null;
|
|
|
|
lastJoinedPassword = null;
|
|
|
|
RoomManager.JoinRoomRequested = onRoomJoined;
|
|
|
|
});
|
2021-07-09 15:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestJoinRoomWithoutPassword()
|
|
|
|
{
|
|
|
|
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: false));
|
2021-07-12 14:49:09 +08:00
|
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
|
|
AddStep("join room", () => InputManager.Key(Key.Enter));
|
|
|
|
|
|
|
|
AddAssert("room join requested", () => lastJoinedRoom == RoomManager.Rooms.First());
|
|
|
|
AddAssert("room join password correct", () => lastJoinedPassword == null);
|
2021-07-09 15:01:52 +08:00
|
|
|
}
|
|
|
|
|
2021-07-17 21:31:47 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPopoverHidesOnLeavingScreen()
|
|
|
|
{
|
|
|
|
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
|
|
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
|
|
|
|
2021-08-18 19:53:17 +08:00
|
|
|
AddUntilStep("password prompt appeared", () => InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());
|
2021-07-17 21:31:47 +08:00
|
|
|
AddStep("exit screen", () => Stack.Exit());
|
2021-08-18 19:53:17 +08:00
|
|
|
AddUntilStep("password prompt hidden", () => !InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());
|
2021-07-17 21:31:47 +08:00
|
|
|
}
|
|
|
|
|
2021-07-09 15:01:52 +08:00
|
|
|
[Test]
|
|
|
|
public void TestJoinRoomWithPassword()
|
|
|
|
{
|
2021-08-18 19:53:17 +08:00
|
|
|
DrawableLoungeRoom.PasswordEntryPopover passwordEntryPopover = null;
|
2021-07-12 14:49:09 +08:00
|
|
|
|
2021-07-09 15:01:52 +08:00
|
|
|
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
|
2021-07-12 14:49:09 +08:00
|
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
2021-08-18 19:53:17 +08:00
|
|
|
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
|
2021-07-12 14:49:09 +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-12 14:49:09 +08:00
|
|
|
|
|
|
|
AddAssert("room join requested", () => lastJoinedRoom == RoomManager.Rooms.First());
|
|
|
|
AddAssert("room join password correct", () => lastJoinedPassword == "password");
|
2021-07-09 15:01:52 +08:00
|
|
|
}
|
|
|
|
|
2021-07-21 06:04:51 +08:00
|
|
|
[Test]
|
|
|
|
public void TestJoinRoomWithPasswordViaKeyboardOnly()
|
|
|
|
{
|
2021-08-18 19:53:17 +08:00
|
|
|
DrawableLoungeRoom.PasswordEntryPopover passwordEntryPopover = null;
|
2021-07-21 06:04:51 +08:00
|
|
|
|
|
|
|
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
|
|
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
2021-08-18 19:53:17 +08:00
|
|
|
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
|
2021-07-21 06:04:51 +08:00
|
|
|
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "password");
|
|
|
|
AddStep("press enter", () => InputManager.Key(Key.Enter));
|
|
|
|
|
|
|
|
AddAssert("room join requested", () => lastJoinedRoom == RoomManager.Rooms.First());
|
|
|
|
AddAssert("room join password correct", () => lastJoinedPassword == "password");
|
|
|
|
}
|
|
|
|
|
2021-07-12 14:49:09 +08:00
|
|
|
private void onRoomJoined(Room room, string password)
|
|
|
|
{
|
|
|
|
lastJoinedRoom = room;
|
|
|
|
lastJoinedPassword = password;
|
|
|
|
}
|
2021-07-09 15:01:52 +08:00
|
|
|
}
|
|
|
|
}
|