2019-07-29 13:30:46 +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-04-08 14:20:53 +08:00
#nullable disable
2022-06-17 15:37:17 +08:00
2022-01-28 14:50:22 +08:00
using System ;
2019-07-29 13:30:46 +08:00
using System.Linq ;
using NUnit.Framework ;
using osu.Framework.Allocation ;
2022-01-03 16:02:15 +08:00
using osu.Framework.Extensions ;
2022-04-18 17:09:14 +08:00
using osu.Framework.Graphics ;
2019-07-29 13:30:46 +08:00
using osu.Framework.Graphics.Containers ;
2022-05-24 05:37:05 +08:00
using osu.Framework.Graphics.UserInterface ;
2020-07-10 17:13:58 +08:00
using osu.Framework.Screens ;
2020-09-14 02:49:16 +08:00
using osu.Framework.Testing ;
2019-10-10 10:58:43 +08:00
using osu.Game.Beatmaps ;
2022-05-24 05:37:05 +08:00
using osu.Game.Collections ;
2022-05-05 00:26:58 +08:00
using osu.Game.Configuration ;
2021-04-05 21:46:01 +08:00
using osu.Game.Graphics.UserInterface ;
2022-01-28 14:50:22 +08:00
using osu.Game.Online.Leaderboards ;
2019-07-31 18:47:41 +08:00
using osu.Game.Overlays ;
2019-07-29 13:30:46 +08:00
using osu.Game.Overlays.Mods ;
2020-09-14 02:49:16 +08:00
using osu.Game.Overlays.Toolbar ;
2021-06-03 13:37:38 +08:00
using osu.Game.Rulesets.Mods ;
2021-02-15 14:02:58 +08:00
using osu.Game.Rulesets.Osu.Mods ;
2022-01-28 14:50:22 +08:00
using osu.Game.Scoring ;
2021-09-10 17:16:10 +08:00
using osu.Game.Screens.Menu ;
2021-07-14 17:55:01 +08:00
using osu.Game.Screens.OnlinePlay.Lounge ;
2019-10-10 10:58:43 +08:00
using osu.Game.Screens.Play ;
2021-02-15 14:02:58 +08:00
using osu.Game.Screens.Ranking ;
2019-07-29 13:30:46 +08:00
using osu.Game.Screens.Select ;
2022-01-28 14:50:22 +08:00
using osu.Game.Screens.Select.Leaderboards ;
2020-09-15 02:21:39 +08:00
using osu.Game.Screens.Select.Options ;
2019-10-10 10:58:43 +08:00
using osu.Game.Tests.Beatmaps.IO ;
2019-07-31 15:03:05 +08:00
using osuTK ;
2019-07-29 13:30:46 +08:00
using osuTK.Input ;
2020-01-29 13:23:23 +08:00
namespace osu.Game.Tests.Visual.Navigation
2019-07-29 13:30:46 +08:00
{
2020-01-29 13:23:23 +08:00
public class TestSceneScreenNavigation : OsuGameTestScene
2019-07-29 13:30:46 +08:00
{
2019-08-13 11:26:06 +08:00
private const float click_padding = 25 ;
2020-01-29 13:23:23 +08:00
private Vector2 backButtonPosition = > Game . ToScreenSpace ( new Vector2 ( click_padding , Game . LayoutRectangle . Bottom - click_padding ) ) ;
2019-07-29 13:30:46 +08:00
2020-01-29 13:23:23 +08:00
private Vector2 optionsButtonPosition = > Game . ToScreenSpace ( new Vector2 ( click_padding , click_padding ) ) ;
2019-07-29 13:30:46 +08:00
[Test]
2019-07-30 17:18:03 +08:00
public void TestExitSongSelectWithEscape ( )
2019-07-29 13:30:46 +08:00
{
2021-05-16 23:14:23 +08:00
TestPlaySongSelect songSelect = null ;
2019-07-29 13:30:46 +08:00
2021-05-16 23:14:23 +08:00
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
2019-07-29 13:30:46 +08:00
AddStep ( "Show mods overlay" , ( ) = > songSelect . ModSelectOverlay . Show ( ) ) ;
AddAssert ( "Overlay was shown" , ( ) = > songSelect . ModSelectOverlay . State . Value = = Visibility . Visible ) ;
2019-10-10 10:58:43 +08:00
pushEscape ( ) ;
2019-07-29 13:30:46 +08:00
AddAssert ( "Overlay was hidden" , ( ) = > songSelect . ModSelectOverlay . State . Value = = Visibility . Hidden ) ;
exitViaEscapeAndConfirm ( ) ;
}
2022-05-24 05:37:05 +08:00
[Test]
public void TestSongSelectBackActionHandling ( )
{
TestPlaySongSelect songSelect = null ;
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
AddStep ( "set filter" , ( ) = > songSelect . ChildrenOfType < SearchTextBox > ( ) . Single ( ) . Current . Value = "test" ) ;
AddStep ( "press back" , ( ) = > InputManager . Click ( MouseButton . Button1 ) ) ;
AddAssert ( "still at song select" , ( ) = > Game . ScreenStack . CurrentScreen = = songSelect ) ;
AddAssert ( "filter cleared" , ( ) = > string . IsNullOrEmpty ( songSelect . ChildrenOfType < SearchTextBox > ( ) . Single ( ) . Current . Value ) ) ;
AddStep ( "set filter again" , ( ) = > songSelect . ChildrenOfType < SearchTextBox > ( ) . Single ( ) . Current . Value = "test" ) ;
AddStep ( "open collections dropdown" , ( ) = >
{
InputManager . MoveMouseTo ( songSelect . ChildrenOfType < CollectionFilterDropdown > ( ) . Single ( ) ) ;
InputManager . Click ( MouseButton . Left ) ;
} ) ;
AddStep ( "press back once" , ( ) = > InputManager . Click ( MouseButton . Button1 ) ) ;
AddAssert ( "still at song select" , ( ) = > Game . ScreenStack . CurrentScreen = = songSelect ) ;
AddAssert ( "collections dropdown closed" , ( ) = > songSelect
. ChildrenOfType < CollectionFilterDropdown > ( ) . Single ( )
. ChildrenOfType < Dropdown < CollectionFilterMenuItem > . DropdownMenu > ( ) . Single ( ) . State = = MenuState . Closed ) ;
AddStep ( "press back a second time" , ( ) = > InputManager . Click ( MouseButton . Button1 ) ) ;
AddAssert ( "filter cleared" , ( ) = > string . IsNullOrEmpty ( songSelect . ChildrenOfType < SearchTextBox > ( ) . Single ( ) . Current . Value ) ) ;
AddStep ( "press back a third time" , ( ) = > InputManager . Click ( MouseButton . Button1 ) ) ;
ConfirmAtMainMenu ( ) ;
}
2021-04-08 14:20:53 +08:00
/// <summary>
/// This tests that the F1 key will open the mod select overlay, and not be handled / blocked by the music controller (which has the same default binding
/// but should be handled *after* song select).
/// </summary>
[Test]
public void TestOpenModSelectOverlayUsingAction ( )
{
2021-05-16 23:14:23 +08:00
TestPlaySongSelect songSelect = null ;
2021-04-08 14:20:53 +08:00
2021-05-16 23:14:23 +08:00
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
2021-04-08 14:20:53 +08:00
AddStep ( "Show mods overlay" , ( ) = > InputManager . Key ( Key . F1 ) ) ;
AddAssert ( "Overlay was shown" , ( ) = > songSelect . ModSelectOverlay . State . Value = = Visibility . Visible ) ;
}
2021-03-31 13:09:38 +08:00
[Test]
public void TestRetryCountIncrements ( )
{
Player player = null ;
2021-11-25 20:11:13 +08:00
Screens . Select . SongSelect songSelect = null ;
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
AddUntilStep ( "wait for song select" , ( ) = > songSelect . BeatmapSetsLoaded ) ;
2021-03-31 13:09:38 +08:00
2021-12-17 17:26:12 +08:00
AddStep ( "import beatmap" , ( ) = > BeatmapImportHelper . LoadQuickOszIntoOsu ( Game ) . WaitSafely ( ) ) ;
2021-03-31 13:09:38 +08:00
AddUntilStep ( "wait for selected" , ( ) = > ! Game . Beatmap . IsDefault ) ;
AddStep ( "press enter" , ( ) = > InputManager . Key ( Key . Enter ) ) ;
2021-09-13 18:38:53 +08:00
AddUntilStep ( "wait for player" , ( ) = >
{
2022-04-24 04:14:14 +08:00
DismissAnyNotifications ( ) ;
2021-09-13 18:38:53 +08:00
return ( player = Game . ScreenStack . CurrentScreen as Player ) ! = null ;
} ) ;
2021-03-31 13:09:38 +08:00
AddAssert ( "retry count is 0" , ( ) = > player . RestartCount = = 0 ) ;
AddStep ( "attempt to retry" , ( ) = > player . ChildrenOfType < HotkeyRetryOverlay > ( ) . First ( ) . Action ( ) ) ;
AddUntilStep ( "wait for old player gone" , ( ) = > Game . ScreenStack . CurrentScreen ! = player ) ;
AddUntilStep ( "get new player" , ( ) = > ( player = Game . ScreenStack . CurrentScreen as Player ) ! = null ) ;
AddAssert ( "retry count is 1" , ( ) = > player . RestartCount = = 1 ) ;
}
2021-02-15 14:02:58 +08:00
[Test]
public void TestRetryFromResults ( )
{
2022-01-28 14:50:22 +08:00
var getOriginalPlayer = playToResults ( ) ;
2021-02-15 14:02:58 +08:00
2022-01-28 14:50:22 +08:00
AddStep ( "attempt to retry" , ( ) = > ( ( ResultsScreen ) Game . ScreenStack . CurrentScreen ) . ChildrenOfType < HotkeyRetryOverlay > ( ) . First ( ) . Action ( ) ) ;
AddUntilStep ( "wait for player" , ( ) = > Game . ScreenStack . CurrentScreen ! = getOriginalPlayer ( ) & & Game . ScreenStack . CurrentScreen is Player ) ;
}
2021-02-15 14:02:58 +08:00
2022-01-28 14:54:51 +08:00
[Test]
public void TestDeleteAllScoresAfterPlaying ( )
{
playToResults ( ) ;
ScoreInfo score = null ;
LeaderboardScore scorePanel = null ;
AddStep ( "get score" , ( ) = > score = ( ( ResultsScreen ) Game . ScreenStack . CurrentScreen ) . Score ) ;
AddAssert ( "ensure score is databased" , ( ) = > Game . Realm . Run ( r = > r . Find < ScoreInfo > ( score . ID ) ? . DeletePending = = false ) ) ;
AddStep ( "press back button" , ( ) = > Game . ChildrenOfType < BackButton > ( ) . First ( ) . Action ( ) ) ;
2022-03-21 16:01:46 +08:00
AddStep ( "show local scores" ,
( ) = > Game . ChildrenOfType < BeatmapDetailAreaTabControl > ( ) . First ( ) . Current . Value = new BeatmapDetailAreaLeaderboardTabItem < BeatmapLeaderboardScope > ( BeatmapLeaderboardScope . Local ) ) ;
2022-01-28 14:54:51 +08:00
AddUntilStep ( "wait for score displayed" , ( ) = > ( scorePanel = Game . ChildrenOfType < LeaderboardScore > ( ) . FirstOrDefault ( s = > s . Score . Equals ( score ) ) ) ! = null ) ;
AddStep ( "open options" , ( ) = > InputManager . Key ( Key . F3 ) ) ;
AddStep ( "choose clear all scores" , ( ) = > InputManager . Key ( Key . Number4 ) ) ;
2022-04-18 17:09:14 +08:00
AddUntilStep ( "wait for dialog display" , ( ) = > ( ( Drawable ) Game . Dependencies . Get < IDialogOverlay > ( ) ) . IsLoaded ) ;
AddUntilStep ( "wait for dialog" , ( ) = > Game . Dependencies . Get < IDialogOverlay > ( ) . CurrentDialog ! = null ) ;
2022-01-28 14:54:51 +08:00
AddStep ( "confirm deletion" , ( ) = > InputManager . Key ( Key . Number1 ) ) ;
2022-04-18 17:09:14 +08:00
AddUntilStep ( "wait for dialog dismissed" , ( ) = > Game . Dependencies . Get < IDialogOverlay > ( ) . CurrentDialog = = null ) ;
2022-01-28 14:54:51 +08:00
2022-03-10 17:08:07 +08:00
AddUntilStep ( "ensure score is pending deletion" , ( ) = > Game . Realm . Run ( r = > r . Find < ScoreInfo > ( score . ID ) ? . DeletePending = = true ) ) ;
2022-01-28 14:54:51 +08:00
AddUntilStep ( "wait for score panel removal" , ( ) = > scorePanel . Parent = = null ) ;
}
2022-01-28 14:50:22 +08:00
[Test]
public void TestDeleteScoreAfterPlaying ( )
{
playToResults ( ) ;
2021-02-15 14:02:58 +08:00
2022-01-28 14:50:22 +08:00
ScoreInfo score = null ;
LeaderboardScore scorePanel = null ;
2021-02-15 14:02:58 +08:00
2022-01-28 14:50:22 +08:00
AddStep ( "get score" , ( ) = > score = ( ( ResultsScreen ) Game . ScreenStack . CurrentScreen ) . Score ) ;
2021-02-15 14:02:58 +08:00
2022-01-28 14:50:22 +08:00
AddAssert ( "ensure score is databased" , ( ) = > Game . Realm . Run ( r = > r . Find < ScoreInfo > ( score . ID ) ? . DeletePending = = false ) ) ;
2021-02-15 14:02:58 +08:00
2022-01-28 14:50:22 +08:00
AddStep ( "press back button" , ( ) = > Game . ChildrenOfType < BackButton > ( ) . First ( ) . Action ( ) ) ;
2021-09-13 18:38:53 +08:00
2022-03-21 16:01:46 +08:00
AddStep ( "show local scores" ,
( ) = > Game . ChildrenOfType < BeatmapDetailAreaTabControl > ( ) . First ( ) . Current . Value = new BeatmapDetailAreaLeaderboardTabItem < BeatmapLeaderboardScope > ( BeatmapLeaderboardScope . Local ) ) ;
2022-01-28 14:50:22 +08:00
AddUntilStep ( "wait for score displayed" , ( ) = > ( scorePanel = Game . ChildrenOfType < LeaderboardScore > ( ) . FirstOrDefault ( s = > s . Score . Equals ( score ) ) ) ! = null ) ;
AddStep ( "right click panel" , ( ) = >
2021-09-13 18:38:53 +08:00
{
2022-01-28 14:50:22 +08:00
InputManager . MoveMouseTo ( scorePanel ) ;
InputManager . Click ( MouseButton . Right ) ;
2021-09-13 18:38:53 +08:00
} ) ;
2022-01-28 14:50:22 +08:00
AddStep ( "click delete" , ( ) = >
{
var dropdownItem = Game
. ChildrenOfType < PlayBeatmapDetailArea > ( ) . First ( )
. ChildrenOfType < OsuContextMenu > ( ) . First ( )
. ChildrenOfType < DrawableOsuMenuItem > ( ) . First ( i = > i . Item . Text . ToString ( ) = = "Delete" ) ;
InputManager . MoveMouseTo ( dropdownItem ) ;
InputManager . Click ( MouseButton . Left ) ;
} ) ;
2022-04-18 17:09:14 +08:00
AddUntilStep ( "wait for dialog display" , ( ) = > ( ( Drawable ) Game . Dependencies . Get < IDialogOverlay > ( ) ) . IsLoaded ) ;
AddUntilStep ( "wait for dialog" , ( ) = > Game . Dependencies . Get < IDialogOverlay > ( ) . CurrentDialog ! = null ) ;
2022-01-28 14:50:22 +08:00
AddStep ( "confirm deletion" , ( ) = > InputManager . Key ( Key . Number1 ) ) ;
2022-04-18 17:09:14 +08:00
AddUntilStep ( "wait for dialog dismissed" , ( ) = > Game . Dependencies . Get < IDialogOverlay > ( ) . CurrentDialog = = null ) ;
2022-01-28 14:50:22 +08:00
2022-03-10 17:08:07 +08:00
AddUntilStep ( "ensure score is pending deletion" , ( ) = > Game . Realm . Run ( r = > r . Find < ScoreInfo > ( score . ID ) ? . DeletePending = = true ) ) ;
2022-01-28 14:50:22 +08:00
AddUntilStep ( "wait for score panel removal" , ( ) = > scorePanel . Parent = = null ) ;
2021-02-15 14:02:58 +08:00
}
2019-10-10 19:12:47 +08:00
[TestCase(true)]
[TestCase(false)]
public void TestSongContinuesAfterExitPlayer ( bool withUserPause )
2019-10-10 10:58:43 +08:00
{
Player player = null ;
2021-11-15 17:46:11 +08:00
IWorkingBeatmap beatmap ( ) = > Game . Beatmap . Value ;
2019-10-10 10:58:43 +08:00
2021-11-25 20:11:13 +08:00
Screens . Select . SongSelect songSelect = null ;
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
AddUntilStep ( "wait for song select" , ( ) = > songSelect . BeatmapSetsLoaded ) ;
2019-10-10 10:58:43 +08:00
2021-12-17 17:26:12 +08:00
AddStep ( "import beatmap" , ( ) = > BeatmapImportHelper . LoadOszIntoOsu ( Game , virtualTrack : true ) . WaitSafely ( ) ) ;
2019-10-10 10:58:43 +08:00
2020-01-29 13:23:23 +08:00
AddUntilStep ( "wait for selected" , ( ) = > ! Game . Beatmap . IsDefault ) ;
2019-10-10 10:58:43 +08:00
2019-10-10 19:12:47 +08:00
if ( withUserPause )
2020-11-02 13:56:50 +08:00
AddStep ( "pause" , ( ) = > Game . Dependencies . Get < MusicController > ( ) . Stop ( true ) ) ;
2019-10-10 19:12:47 +08:00
2020-11-05 22:41:56 +08:00
AddStep ( "press enter" , ( ) = > InputManager . Key ( Key . Enter ) ) ;
2019-10-10 10:58:43 +08:00
2021-09-13 18:38:53 +08:00
AddUntilStep ( "wait for player" , ( ) = >
{
2022-04-24 04:14:14 +08:00
DismissAnyNotifications ( ) ;
2021-09-13 18:38:53 +08:00
return ( player = Game . ScreenStack . CurrentScreen as Player ) ! = null ;
} ) ;
2022-01-26 00:45:11 +08:00
AddUntilStep ( "wait for fail" , ( ) = > player . GameplayState . HasFailed ) ;
2019-10-10 10:58:43 +08:00
2020-08-07 21:06:04 +08:00
AddUntilStep ( "wait for track stop" , ( ) = > ! Game . MusicController . IsPlaying ) ;
2021-12-22 16:44:22 +08:00
AddAssert ( "Ensure time before preview point" , ( ) = > Game . MusicController . CurrentTrack . CurrentTime < beatmap ( ) . BeatmapInfo . Metadata . PreviewTime ) ;
2019-10-10 10:58:43 +08:00
pushEscape ( ) ;
2020-08-07 21:06:04 +08:00
AddUntilStep ( "wait for track playing" , ( ) = > Game . MusicController . IsPlaying ) ;
2021-12-22 16:44:22 +08:00
AddAssert ( "Ensure time wasn't reset to preview point" , ( ) = > Game . MusicController . CurrentTrack . CurrentTime < beatmap ( ) . BeatmapInfo . Metadata . PreviewTime ) ;
2019-10-10 10:58:43 +08:00
}
2020-07-10 17:13:58 +08:00
[Test]
public void TestMenuMakesMusic ( )
{
2021-05-16 23:14:23 +08:00
TestPlaySongSelect songSelect = null ;
2020-07-10 17:13:58 +08:00
2021-05-16 23:14:23 +08:00
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
2020-07-10 17:13:58 +08:00
2020-08-07 21:06:04 +08:00
AddUntilStep ( "wait for no track" , ( ) = > Game . MusicController . CurrentTrack . IsDummyDevice ) ;
2020-07-10 17:13:58 +08:00
AddStep ( "return to menu" , ( ) = > songSelect . Exit ( ) ) ;
2020-08-11 12:14:20 +08:00
AddUntilStep ( "wait for track" , ( ) = > ! Game . MusicController . CurrentTrack . IsDummyDevice & & Game . MusicController . IsPlaying ) ;
2020-07-10 17:13:58 +08:00
}
2021-06-08 16:03:46 +08:00
[Test]
public void TestPushSongSelectAndPressBackButtonImmediately ( )
{
AddStep ( "push song select" , ( ) = > Game . ScreenStack . Push ( new TestPlaySongSelect ( ) ) ) ;
AddStep ( "press back button" , ( ) = > Game . ChildrenOfType < BackButton > ( ) . First ( ) . Action ( ) ) ;
2021-06-08 16:09:03 +08:00
AddWaitStep ( "wait two frames" , 2 ) ;
2021-06-08 16:03:46 +08:00
}
2019-07-29 13:30:46 +08:00
[Test]
2019-07-30 17:18:03 +08:00
public void TestExitSongSelectWithClick ( )
2019-07-29 13:30:46 +08:00
{
2021-05-16 23:14:23 +08:00
TestPlaySongSelect songSelect = null ;
2019-07-29 13:30:46 +08:00
2021-05-16 23:14:23 +08:00
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
2019-07-29 13:30:46 +08:00
AddStep ( "Show mods overlay" , ( ) = > songSelect . ModSelectOverlay . Show ( ) ) ;
AddAssert ( "Overlay was shown" , ( ) = > songSelect . ModSelectOverlay . State . Value = = Visibility . Visible ) ;
2022-05-06 04:15:49 +08:00
AddStep ( "Move mouse to dimmed area" , ( ) = > InputManager . MoveMouseTo ( new Vector2 (
songSelect . ScreenSpaceDrawQuad . TopLeft . X + 1 ,
songSelect . ScreenSpaceDrawQuad . TopLeft . Y + songSelect . ScreenSpaceDrawQuad . Height / 2 ) ) ) ;
AddStep ( "Click left mouse button" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
2019-07-29 13:30:46 +08:00
2019-07-31 15:03:05 +08:00
AddUntilStep ( "Overlay was hidden" , ( ) = > songSelect . ModSelectOverlay . State . Value = = Visibility . Hidden ) ;
2019-07-29 13:30:46 +08:00
exitViaBackButtonAndConfirm ( ) ;
}
2022-03-22 16:38:43 +08:00
[Test]
public void TestModsResetOnEnteringMultiplayer ( )
{
var osuAutomationMod = new OsuModAutoplay ( ) ;
AddStep ( "Enable autoplay" , ( ) = > { Game . SelectedMods . Value = new [ ] { osuAutomationMod } ; } ) ;
2022-03-23 02:13:22 +08:00
PushAndConfirm ( ( ) = > new Screens . OnlinePlay . Multiplayer . Multiplayer ( ) ) ;
AddUntilStep ( "Mods are removed" , ( ) = > Game . SelectedMods . Value . Count = = 0 ) ;
2022-03-22 16:38:43 +08:00
AddStep ( "Return to menu" , ( ) = > Game . ScreenStack . CurrentScreen . Exit ( ) ) ;
AddUntilStep ( "Mods are restored" , ( ) = > Game . SelectedMods . Value . Contains ( osuAutomationMod ) ) ;
}
2019-07-29 13:30:46 +08:00
[Test]
public void TestExitMultiWithEscape ( )
{
2020-12-25 23:50:00 +08:00
PushAndConfirm ( ( ) = > new Screens . OnlinePlay . Playlists . Playlists ( ) ) ;
2019-07-29 13:30:46 +08:00
exitViaEscapeAndConfirm ( ) ;
}
[Test]
public void TestExitMultiWithBackButton ( )
{
2020-12-25 23:50:00 +08:00
PushAndConfirm ( ( ) = > new Screens . OnlinePlay . Playlists . Playlists ( ) ) ;
2019-07-29 13:30:46 +08:00
exitViaBackButtonAndConfirm ( ) ;
}
2019-07-31 18:47:41 +08:00
[Test]
public void TestOpenOptionsAndExitWithEscape ( )
{
2020-01-29 13:23:23 +08:00
AddUntilStep ( "Wait for options to load" , ( ) = > Game . Settings . IsLoaded ) ;
2020-11-05 22:41:56 +08:00
AddStep ( "Enter menu" , ( ) = > InputManager . Key ( Key . Enter ) ) ;
2019-07-31 18:47:41 +08:00
AddStep ( "Move mouse to options overlay" , ( ) = > InputManager . MoveMouseTo ( optionsButtonPosition ) ) ;
AddStep ( "Click options overlay" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
2020-01-29 13:23:23 +08:00
AddAssert ( "Options overlay was opened" , ( ) = > Game . Settings . State . Value = = Visibility . Visible ) ;
2020-11-05 22:41:56 +08:00
AddStep ( "Hide options overlay using escape" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
2020-01-29 13:23:23 +08:00
AddAssert ( "Options overlay was closed" , ( ) = > Game . Settings . State . Value = = Visibility . Hidden ) ;
2019-07-31 18:47:41 +08:00
}
2020-03-05 16:12:14 +08:00
[Test]
public void TestWaitForNextTrackInMenu ( )
{
bool trackCompleted = false ;
AddUntilStep ( "Wait for music controller" , ( ) = > Game . MusicController . IsLoaded ) ;
AddStep ( "Seek close to end" , ( ) = >
{
2020-08-07 21:06:04 +08:00
Game . MusicController . SeekTo ( Game . MusicController . CurrentTrack . Length - 1000 ) ;
Game . MusicController . CurrentTrack . Completed + = ( ) = > trackCompleted = true ;
2020-03-05 16:12:14 +08:00
} ) ;
AddUntilStep ( "Track was completed" , ( ) = > trackCompleted ) ;
2020-08-07 21:06:04 +08:00
AddUntilStep ( "Track was restarted" , ( ) = > Game . MusicController . IsPlaying ) ;
2020-03-05 16:12:14 +08:00
}
2020-09-14 02:49:16 +08:00
[Test]
public void TestModSelectInput ( )
{
2022-01-13 04:52:04 +08:00
AddUntilStep ( "Wait for toolbar to load" , ( ) = > Game . Toolbar . IsLoaded ) ;
2020-09-14 02:49:16 +08:00
2022-01-13 04:52:04 +08:00
TestPlaySongSelect songSelect = null ;
2021-05-16 23:14:23 +08:00
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
2020-09-14 02:49:16 +08:00
AddStep ( "Show mods overlay" , ( ) = > songSelect . ModSelectOverlay . Show ( ) ) ;
AddStep ( "Change ruleset to osu!taiko" , ( ) = >
{
InputManager . PressKey ( Key . ControlLeft ) ;
2020-11-05 22:41:56 +08:00
InputManager . Key ( Key . Number2 ) ;
2020-09-14 02:49:16 +08:00
InputManager . ReleaseKey ( Key . ControlLeft ) ;
} ) ;
2021-11-22 13:26:24 +08:00
AddAssert ( "Ruleset changed to osu!taiko" , ( ) = > Game . Toolbar . ChildrenOfType < ToolbarRulesetSelector > ( ) . Single ( ) . Current . Value . OnlineID = = 1 ) ;
2020-09-14 02:49:16 +08:00
AddAssert ( "Mods overlay still visible" , ( ) = > songSelect . ModSelectOverlay . State . Value = = Visibility . Visible ) ;
}
2020-09-15 02:21:39 +08:00
[Test]
public void TestBeatmapOptionsInput ( )
{
2022-01-13 04:52:04 +08:00
AddUntilStep ( "Wait for toolbar to load" , ( ) = > Game . Toolbar . IsLoaded ) ;
2020-09-15 02:21:39 +08:00
2022-01-13 04:52:04 +08:00
TestPlaySongSelect songSelect = null ;
2021-05-16 23:14:23 +08:00
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
2020-09-15 02:21:39 +08:00
AddStep ( "Show options overlay" , ( ) = > songSelect . BeatmapOptionsOverlay . Show ( ) ) ;
AddStep ( "Change ruleset to osu!taiko" , ( ) = >
{
InputManager . PressKey ( Key . ControlLeft ) ;
2020-11-05 22:41:56 +08:00
InputManager . Key ( Key . Number2 ) ;
2020-09-15 02:21:39 +08:00
InputManager . ReleaseKey ( Key . ControlLeft ) ;
} ) ;
2021-11-22 13:26:24 +08:00
AddAssert ( "Ruleset changed to osu!taiko" , ( ) = > Game . Toolbar . ChildrenOfType < ToolbarRulesetSelector > ( ) . Single ( ) . Current . Value . OnlineID = = 1 ) ;
2020-09-15 02:21:39 +08:00
AddAssert ( "Options overlay still visible" , ( ) = > songSelect . BeatmapOptionsOverlay . State . Value = = Visibility . Visible ) ;
}
2021-02-25 13:51:23 +08:00
[Test]
public void TestSettingsViaHotkeyFromMainMenu ( )
{
2022-01-13 04:52:04 +08:00
AddUntilStep ( "Wait for toolbar to load" , ( ) = > Game . Toolbar . IsLoaded ) ;
2021-02-25 13:51:23 +08:00
AddAssert ( "toolbar not displayed" , ( ) = > Game . Toolbar . State . Value = = Visibility . Hidden ) ;
AddStep ( "press settings hotkey" , ( ) = >
{
InputManager . PressKey ( Key . ControlLeft ) ;
InputManager . Key ( Key . O ) ;
InputManager . ReleaseKey ( Key . ControlLeft ) ;
} ) ;
AddUntilStep ( "settings displayed" , ( ) = > Game . Settings . State . Value = = Visibility . Visible ) ;
}
2020-11-10 06:43:06 +08:00
[Test]
public void TestToolbarHiddenByUser ( )
{
AddUntilStep ( "Wait for toolbar to load" , ( ) = > Game . Toolbar . IsLoaded ) ;
2022-01-13 04:52:04 +08:00
AddStep ( "Enter menu" , ( ) = > InputManager . Key ( Key . Enter ) ) ;
AddUntilStep ( "Toolbar is visible" , ( ) = > Game . Toolbar . State . Value = = Visibility . Visible ) ;
2020-11-10 06:43:06 +08:00
AddStep ( "Hide toolbar" , ( ) = >
{
InputManager . PressKey ( Key . ControlLeft ) ;
InputManager . Key ( Key . T ) ;
InputManager . ReleaseKey ( Key . ControlLeft ) ;
} ) ;
pushEscape ( ) ;
AddStep ( "Enter menu" , ( ) = > InputManager . Key ( Key . Enter ) ) ;
AddAssert ( "Toolbar is hidden" , ( ) = > Game . Toolbar . State . Value = = Visibility . Hidden ) ;
AddStep ( "Enter song select" , ( ) = >
{
InputManager . Key ( Key . Enter ) ;
InputManager . Key ( Key . Enter ) ;
} ) ;
AddAssert ( "Toolbar is hidden" , ( ) = > Game . Toolbar . State . Value = = Visibility . Hidden ) ;
}
2021-06-08 16:54:54 +08:00
[Test]
public void TestPushMatchSubScreenAndPressBackButtonImmediately ( )
{
2021-12-20 17:24:59 +08:00
TestMultiplayerComponents multiplayerComponents = null ;
2021-06-08 16:54:54 +08:00
2021-12-20 17:24:59 +08:00
PushAndConfirm ( ( ) = > multiplayerComponents = new TestMultiplayerComponents ( ) ) ;
2021-06-08 16:54:54 +08:00
2021-12-20 17:24:59 +08:00
AddUntilStep ( "wait for lounge" , ( ) = > multiplayerComponents . ChildrenOfType < LoungeSubScreen > ( ) . SingleOrDefault ( ) ? . IsLoaded = = true ) ;
AddStep ( "open room" , ( ) = > multiplayerComponents . ChildrenOfType < LoungeSubScreen > ( ) . Single ( ) . Open ( ) ) ;
2021-06-08 16:54:54 +08:00
AddStep ( "press back button" , ( ) = > Game . ChildrenOfType < BackButton > ( ) . First ( ) . Action ( ) ) ;
AddWaitStep ( "wait two frames" , 2 ) ;
}
2021-08-30 13:27:56 +08:00
[Test]
public void TestOverlayClosing ( )
{
// use now playing overlay for "overlay -> background" drag case
// since most overlays use a scroll container that absorbs on mouse down
NowPlayingOverlay nowPlayingOverlay = null ;
2021-10-07 14:47:59 +08:00
AddUntilStep ( "Wait for now playing load" , ( ) = > ( nowPlayingOverlay = Game . ChildrenOfType < NowPlayingOverlay > ( ) . FirstOrDefault ( ) ) ! = null ) ;
2021-08-30 13:27:56 +08:00
AddStep ( "enter menu" , ( ) = > InputManager . Key ( Key . Enter ) ) ;
2021-10-07 14:47:59 +08:00
AddUntilStep ( "toolbar displayed" , ( ) = > Game . Toolbar . State . Value = = Visibility . Visible ) ;
2021-08-30 13:27:56 +08:00
2021-10-07 14:47:59 +08:00
AddStep ( "open now playing" , ( ) = > InputManager . Key ( Key . F6 ) ) ;
AddUntilStep ( "now playing is visible" , ( ) = > nowPlayingOverlay . State . Value = = Visibility . Visible ) ;
2021-08-30 13:27:56 +08:00
// drag tests
// background -> toolbar
AddStep ( "move cursor to background" , ( ) = > InputManager . MoveMouseTo ( Game . ScreenSpaceDrawQuad . BottomRight ) ) ;
AddStep ( "press left mouse button" , ( ) = > InputManager . PressButton ( MouseButton . Left ) ) ;
AddStep ( "move cursor to toolbar" , ( ) = > InputManager . MoveMouseTo ( Game . Toolbar . ScreenSpaceDrawQuad . Centre ) ) ;
AddStep ( "release left mouse button" , ( ) = > InputManager . ReleaseButton ( MouseButton . Left ) ) ;
2021-08-31 11:53:43 +08:00
AddAssert ( "now playing is hidden" , ( ) = > nowPlayingOverlay . State . Value = = Visibility . Hidden ) ;
AddStep ( "press now playing hotkey" , ( ) = > InputManager . Key ( Key . F6 ) ) ;
2021-08-30 13:27:56 +08:00
// toolbar -> background
AddStep ( "press left mouse button" , ( ) = > InputManager . PressButton ( MouseButton . Left ) ) ;
AddStep ( "move cursor to background" , ( ) = > InputManager . MoveMouseTo ( Game . ScreenSpaceDrawQuad . BottomRight ) ) ;
AddStep ( "release left mouse button" , ( ) = > InputManager . ReleaseButton ( MouseButton . Left ) ) ;
AddAssert ( "now playing is still visible" , ( ) = > nowPlayingOverlay . State . Value = = Visibility . Visible ) ;
// background -> overlay
AddStep ( "press left mouse button" , ( ) = > InputManager . PressButton ( MouseButton . Left ) ) ;
AddStep ( "move cursor to now playing overlay" , ( ) = > InputManager . MoveMouseTo ( nowPlayingOverlay . ScreenSpaceDrawQuad . Centre ) ) ;
AddStep ( "release left mouse button" , ( ) = > InputManager . ReleaseButton ( MouseButton . Left ) ) ;
AddAssert ( "now playing is still visible" , ( ) = > nowPlayingOverlay . State . Value = = Visibility . Visible ) ;
// overlay -> background
AddStep ( "press left mouse button" , ( ) = > InputManager . PressButton ( MouseButton . Left ) ) ;
AddStep ( "move cursor to background" , ( ) = > InputManager . MoveMouseTo ( Game . ScreenSpaceDrawQuad . BottomRight ) ) ;
AddStep ( "release left mouse button" , ( ) = > InputManager . ReleaseButton ( MouseButton . Left ) ) ;
AddAssert ( "now playing is still visible" , ( ) = > nowPlayingOverlay . State . Value = = Visibility . Visible ) ;
// background -> background
AddStep ( "press left mouse button" , ( ) = > InputManager . PressButton ( MouseButton . Left ) ) ;
AddStep ( "move cursor to left" , ( ) = > InputManager . MoveMouseTo ( Game . ScreenSpaceDrawQuad . BottomLeft ) ) ;
AddStep ( "release left mouse button" , ( ) = > InputManager . ReleaseButton ( MouseButton . Left ) ) ;
AddAssert ( "now playing is hidden" , ( ) = > nowPlayingOverlay . State . Value = = Visibility . Hidden ) ;
AddStep ( "press now playing hotkey" , ( ) = > InputManager . Key ( Key . F6 ) ) ;
// click tests
// toolbar
AddStep ( "move cursor to toolbar" , ( ) = > InputManager . MoveMouseTo ( Game . Toolbar . ScreenSpaceDrawQuad . Centre ) ) ;
AddStep ( "click left mouse button" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
AddAssert ( "now playing is still visible" , ( ) = > nowPlayingOverlay . State . Value = = Visibility . Visible ) ;
// background
AddStep ( "move cursor to background" , ( ) = > InputManager . MoveMouseTo ( Game . ScreenSpaceDrawQuad . BottomRight ) ) ;
AddStep ( "click left mouse button" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
AddAssert ( "now playing is hidden" , ( ) = > nowPlayingOverlay . State . Value = = Visibility . Hidden ) ;
2022-05-24 05:58:12 +08:00
// move the mouse firmly inside game bounds to avoid interfering with other tests.
AddStep ( "center cursor" , ( ) = > InputManager . MoveMouseTo ( Game . ScreenSpaceDrawQuad . Centre ) ) ;
2021-08-30 13:27:56 +08:00
}
2021-09-10 17:16:10 +08:00
[Test]
public void TestExitGameFromSongSelect ( )
{
PushAndConfirm ( ( ) = > new TestPlaySongSelect ( ) ) ;
exitViaEscapeAndConfirm ( ) ;
pushEscape ( ) ; // returns to osu! logo
AddStep ( "Hold escape" , ( ) = > InputManager . PressKey ( Key . Escape ) ) ;
2021-10-07 14:47:59 +08:00
AddUntilStep ( "Wait for intro" , ( ) = > Game . ScreenStack . CurrentScreen is IntroScreen ) ;
2021-09-14 14:08:43 +08:00
AddStep ( "Release escape" , ( ) = > InputManager . ReleaseKey ( Key . Escape ) ) ;
2021-09-10 17:16:10 +08:00
AddUntilStep ( "Wait for game exit" , ( ) = > Game . ScreenStack . CurrentScreen = = null ) ;
2021-09-13 17:32:58 +08:00
AddStep ( "test dispose doesn't crash" , ( ) = > Game . Dispose ( ) ) ;
2021-09-10 17:16:10 +08:00
}
2022-01-28 14:50:22 +08:00
2022-05-05 00:26:58 +08:00
[Test]
public void TestRapidBackButtonExit ( )
{
AddStep ( "set hold delay to 0" , ( ) = > Game . LocalConfig . SetValue ( OsuSetting . UIHoldActivationDelay , 0.0 ) ) ;
AddStep ( "press escape twice rapidly" , ( ) = >
{
InputManager . Key ( Key . Escape ) ;
InputManager . Key ( Key . Escape ) ;
} ) ;
pushEscape ( ) ;
AddAssert ( "exit dialog is shown" , ( ) = > Game . Dependencies . Get < IDialogOverlay > ( ) . CurrentDialog ! = null ) ;
}
2022-01-28 14:50:22 +08:00
private Func < Player > playToResults ( )
{
Player player = null ;
IWorkingBeatmap beatmap ( ) = > Game . Beatmap . Value ;
Screens . Select . SongSelect songSelect = null ;
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
AddUntilStep ( "wait for song select" , ( ) = > songSelect . BeatmapSetsLoaded ) ;
AddStep ( "import beatmap" , ( ) = > BeatmapImportHelper . LoadQuickOszIntoOsu ( Game ) . WaitSafely ( ) ) ;
AddUntilStep ( "wait for selected" , ( ) = > ! Game . Beatmap . IsDefault ) ;
AddStep ( "set mods" , ( ) = > Game . SelectedMods . Value = new Mod [ ] { new OsuModNoFail ( ) , new OsuModDoubleTime { SpeedChange = { Value = 2 } } } ) ;
AddStep ( "press enter" , ( ) = > InputManager . Key ( Key . Enter ) ) ;
AddUntilStep ( "wait for player" , ( ) = >
{
2022-04-24 04:14:14 +08:00
DismissAnyNotifications ( ) ;
2022-01-28 14:50:22 +08:00
return ( player = Game . ScreenStack . CurrentScreen as Player ) ! = null ;
} ) ;
AddUntilStep ( "wait for track playing" , ( ) = > beatmap ( ) . Track . IsRunning ) ;
AddStep ( "seek to near end" , ( ) = > player . ChildrenOfType < GameplayClockContainer > ( ) . First ( ) . Seek ( beatmap ( ) . Beatmap . HitObjects [ ^ 1 ] . StartTime - 1000 ) ) ;
AddUntilStep ( "wait for pass" , ( ) = > ( Game . ScreenStack . CurrentScreen as ResultsScreen ) ? . IsLoaded = = true ) ;
return ( ) = > player ;
}
2021-09-10 17:16:10 +08:00
2019-10-10 10:58:43 +08:00
private void pushEscape ( ) = >
2020-11-05 22:41:56 +08:00
AddStep ( "Press escape" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
2019-10-10 10:58:43 +08:00
2019-07-29 13:30:46 +08:00
private void exitViaEscapeAndConfirm ( )
{
2019-10-10 10:58:43 +08:00
pushEscape ( ) ;
2020-01-29 13:23:23 +08:00
ConfirmAtMainMenu ( ) ;
2019-07-29 13:30:46 +08:00
}
private void exitViaBackButtonAndConfirm ( )
{
2019-07-31 18:30:35 +08:00
AddStep ( "Move mouse to backButton" , ( ) = > InputManager . MoveMouseTo ( backButtonPosition ) ) ;
2019-07-29 13:30:46 +08:00
AddStep ( "Click back button" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
2020-01-29 13:23:23 +08:00
ConfirmAtMainMenu ( ) ;
2019-07-29 13:30:46 +08:00
}
2021-05-16 23:14:23 +08:00
public class TestPlaySongSelect : PlaySongSelect
2019-07-29 13:30:46 +08:00
{
2022-05-11 04:29:57 +08:00
public ModSelectOverlay ModSelectOverlay = > ModSelect ;
2020-09-15 02:21:39 +08:00
public BeatmapOptionsOverlay BeatmapOptionsOverlay = > BeatmapOptions ;
2019-07-29 13:30:46 +08:00
}
}
}