forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSceneSongSelectNavigation.cs
More file actions
347 lines (270 loc) · 14.2 KB
/
Copy pathTestSceneSongSelectNavigation.cs
File metadata and controls
347 lines (270 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// 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;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Leaderboards;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Footer;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Select;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Tests.Resources;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Navigation
{
public partial class TestSceneSongSelectNavigation : OsuGameTestScene
{
[Test]
public void TestRetryFromResults()
{
var getOriginalPlayer = playToResults();
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);
}
[Test]
public void TestPushSongSelectAndClickBottomLeftCorner()
{
AddStep("push song select", () => Game.ScreenStack.Push(new SoloSongSelect()));
// TODO: without this step, a critical bug will be hit, see inline comment in `OsuGame.handleBackButton`.
AddUntilStep("Wait for song select", () => Game.ScreenStack.CurrentScreen is SoloSongSelect select && select.IsLoaded);
AddStep("click in corner", () =>
{
InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.BottomLeft);
InputManager.Click(MouseButton.Left);
});
ConfirmAtMainMenu();
}
[Test]
public void TestPushSongSelectAndPressBackButtonImmediately()
{
AddStep("push song select", () => Game.ScreenStack.Push(new SoloSongSelect()));
// TODO: without this step, a critical bug will be hit, see inline comment in `OsuGame.handleBackButton`.
AddUntilStep("Wait for song select", () => Game.ScreenStack.CurrentScreen is SoloSongSelect select && select.IsLoaded);
AddStep("press back button", () => Game.ChildrenOfType<ScreenBackButton>().First().Action!.Invoke());
ConfirmAtMainMenu();
}
[Test]
public void TestEditBeatmap()
{
PushAndConfirm(() => new SoloSongSelect());
AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
AddStep("open menu", () => InputManager.Key(Key.F3));
AddUntilStep("wait for footer focus", () => InputManager.FocusedDrawable is FooterButtonOptions.Popover);
AddStep("trigger edit", () =>
{
// TODO: should be 5, not 4.
InputManager.Key(Key.Number4);
});
waitForScreen<Editor>();
pushEscape();
waitForScreen<SoloSongSelect>();
}
[Test]
public void TestPresentBeatmapFromMainMenuUsesPreviewPoint()
{
BeatmapSetInfo beatmapInfo = null!;
AddStep("import beatmap", () =>
{
var task = BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true);
task.WaitSafely();
beatmapInfo = task.GetResultSafely();
});
AddStep("present beatmap", () => Game.PresentBeatmap(beatmapInfo));
AddUntilStep("wait for track playing", () => Game.MusicController.IsPlaying);
AddAssert("ensure time is reset to preview point",
() =>
{
double timeFromPreviewPoint = Math.Abs(Game.MusicController.CurrentTrack.CurrentTime - beatmapInfo.Metadata.PreviewTime);
return timeFromPreviewPoint < 5000;
});
}
[TestCase(true)]
[TestCase(false)]
public void TestSongContinuesAfterExitPlayer(bool withUserPause)
{
Player? player = null;
IWorkingBeatmap beatmap() => Game.Beatmap.Value;
PushAndConfirm(() => new SoloSongSelect());
AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
if (withUserPause)
AddStep("pause", () => Game.Dependencies.Get<MusicController>().Stop(true));
AddStep("press enter", () => InputManager.Key(Key.Enter));
AddUntilStep("wait for player", () =>
{
DismissAnyNotifications();
return (player = Game.ScreenStack.CurrentScreen as Player) != null;
});
AddUntilStep("wait for fail", () => player?.GameplayState.HasFailed, () => Is.True);
AddUntilStep("wait for track stop", () => !Game.MusicController.IsPlaying);
AddAssert("Ensure time before preview point", () => Game.MusicController.CurrentTrack.CurrentTime < beatmap().BeatmapInfo.Metadata.PreviewTime);
pushEscape();
AddUntilStep("wait for track playing", () => Game.MusicController.IsPlaying);
AddAssert("Ensure time wasn't reset to preview point", () => Game.MusicController.CurrentTrack.CurrentTime < beatmap().BeatmapInfo.Metadata.PreviewTime);
}
[Test]
public void TestAutoplayShortcutReturnsInitialModsOnExit()
{
PushAndConfirm(() => new SoloSongSelect());
AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
AddUntilStep("wait for selection", () => !Game.Beatmap.IsDefault);
AddStep("open mod select", () => InputManager.Key(Key.F1));
AddStep("search magnetised", () => this.ChildrenOfType<ModSelectOverlay>().Single().SearchTerm = "MG");
AddStep("select", () => InputManager.Key(Key.Enter));
AddAssert("magnetised selected", () => Game.SelectedMods.Value.Single(), Is.TypeOf<OsuModMagnetised>);
AddStep("configure mod", () => ((OsuModMagnetised)Game.SelectedMods.Value.Single()).AttractionStrength.Value = 1.0f);
pushEscape();
pushEscape();
AddStep("press ctrl+enter", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.Enter);
InputManager.ReleaseKey(Key.ControlLeft);
});
AddUntilStep("wait for player", () =>
{
DismissAnyNotifications();
return Game.ScreenStack.CurrentScreen is Player;
});
AddAssert("only autoplay selected", () => Game.SelectedMods.Value.Single(), Is.TypeOf<OsuModAutoplay>);
pushEscape();
waitForScreen<SoloSongSelect>();
AddAssert("magnetised selected", () => Game.SelectedMods.Value.Single(), Is.TypeOf<OsuModMagnetised>);
AddAssert("mod configured", () => ((OsuModMagnetised)Game.SelectedMods.Value.Single()).AttractionStrength.Value, () => Is.EqualTo(1.0f));
}
[Test]
public void TestLeaderboardCorrectInPlayer()
{
IWorkingBeatmap beatmap() => Game.Beatmap.Value;
PushAndConfirm(() => new SoloSongSelect());
AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
AddStep("switch to next difficulty and immediately press enter", () =>
{
InputManager.Key(Key.Down);
Schedule(() => InputManager.Key(Key.Enter));
});
AddUntilStep("wait for player", () =>
{
DismissAnyNotifications();
return Game.ScreenStack.CurrentScreen is Player;
});
AddAssert("leaderboard matches gameplay beatmap", () => Game.ChildrenOfType<LeaderboardManager>().Single().CurrentCriteria?.Beatmap, () => Is.EqualTo(beatmap().BeatmapInfo));
}
[Test]
public void TestEnterKeyProgressesToGameplayEvenIfCarouselFilteredOut()
{
PushAndConfirm(() => new SoloSongSelect());
AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
AddStep("filter out active beatmap", () => this.ChildrenOfType<SearchTextBox>().First().Text = "abacadabadaeba");
AddUntilStep("wait for filter", () => this.ChildrenOfType<BeatmapCarousel>().Single().IsFiltering, () => Is.False);
AddStep("press enter", () => InputManager.Key(Key.Enter));
AddUntilStep("player entered", () =>
{
DismissAnyNotifications();
return Game.ScreenStack.CurrentScreen is Player;
});
}
[Test]
public void TestSelectionNotLostWithConvertedBeatmapsShown()
{
BeatmapSetInfo beatmapSet = null!;
BeatmapInfo selectedBeatmap = null!;
AddStep("import beatmap", () => beatmapSet = BeatmapImportHelper.LoadOszIntoOsu(Game).GetResultSafely());
PushAndConfirm(() => new SoloSongSelect());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
AddStep("change ruleset to taiko", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.Number2);
InputManager.ReleaseKey(Key.ControlLeft);
});
AddStep("show converts", () => Game.LocalConfig.SetValue(OsuSetting.ShowConvertedBeatmaps, true));
AddStep("select osu! beatmap", () =>
{
selectedBeatmap = beatmapSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0);
Game.Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(selectedBeatmap);
});
pushEscape();
AddUntilStep("went back to main menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
PushAndConfirm(() => new SoloSongSelect());
AddUntilStep("selected beatmap is still osu! ruleset", () => Game.Beatmap.Value.BeatmapInfo, () => Is.EqualTo(selectedBeatmap));
}
/// <summary>
/// Note: This test was written to demonstrate the failure described at https://github.com/ppy/osu/issues/35023,
/// but because the failure scenario there entailed a race condition, it was possible for the test to pass regardless
/// unless <see cref="Screens.Select.SongSelect.SELECTION_DEBOUNCE"/> was increased.
/// </summary>
[Test]
public void TestPresentFromResults()
{
BeatmapSetInfo beatmapToPresent = null!;
BeatmapSetInfo beatmapToPlay = null!;
AddStep("manually insert beatmap to be presented", () =>
{
Game.Realm.Write(r =>
{
var beatmapSet = TestResources.CreateTestBeatmapSetInfo(3, [r.Find<RulesetInfo>("osu")]);
r.Add(beatmapSet);
beatmapToPresent = beatmapSet.Detach();
});
});
AddStep("import beatmap", () => beatmapToPlay = BeatmapImportHelper.LoadQuickOszIntoOsu(Game).GetResultSafely());
AddStep("set global beatmap", () => Game.Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(beatmapToPlay.Beatmaps.First()));
playToResults();
AddStep("present beatmap from results", () => Game.PresentBeatmap(beatmapToPresent));
AddUntilStep("back at song select", () => Game.ScreenStack.CurrentScreen is SoloSongSelect);
AddUntilStep("presented beatmap is current", () => Game.Beatmap.Value.BeatmapSetInfo.Equals(beatmapToPresent));
}
private Func<Player> playToResults()
{
var player = playToCompletion();
AddUntilStep("wait for results", () => Game.ScreenStack.CurrentScreen is ResultsScreen { IsLoaded: true });
return player;
}
private Func<Player> playToCompletion()
{
Player? player = null;
IWorkingBeatmap beatmap() => Game.Beatmap.Value;
PushAndConfirm(() => new SoloSongSelect());
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 } } });
pushEnter();
AddUntilStep("wait for player", () =>
{
DismissAnyNotifications();
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 complete", () => player?.GameplayState.HasPassed, () => Is.True);
return () => player!;
}
private void waitForScreen<T>() where T : OsuScreen =>
AddUntilStep($"Wait for {typeof(T).ReadableName()}", () => Game.ScreenStack.CurrentScreen is T screen && screen.IsLoaded);
private void pushEnter() =>
AddStep("Press enter", () => InputManager.Key(Key.Enter));
private void pushEscape() =>
AddStep("Press escape", () => InputManager.Key(Key.Escape));
}
}