2019-12-27 11:37:36 +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 NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-11-09 20:34:36 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2019-12-27 11:37:36 +08:00
|
|
|
using osu.Game.Overlays.Notifications;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Online
|
|
|
|
{
|
|
|
|
[HeadlessTest]
|
2021-11-25 16:23:46 +08:00
|
|
|
public class TestSceneBeatmapDownloading : OsuTestScene
|
2019-12-27 11:37:36 +08:00
|
|
|
{
|
2021-11-25 16:23:46 +08:00
|
|
|
private BeatmapModelDownloader beatmaps;
|
2019-12-27 11:37:36 +08:00
|
|
|
private ProgressNotification recentNotification;
|
|
|
|
|
2021-11-09 20:34:36 +08:00
|
|
|
private static readonly BeatmapSetInfo test_db_model = new BeatmapSetInfo
|
|
|
|
{
|
2021-11-12 16:50:31 +08:00
|
|
|
OnlineID = 1,
|
2021-11-09 20:34:36 +08:00
|
|
|
Metadata = new BeatmapMetadata
|
|
|
|
{
|
|
|
|
Artist = "test author",
|
|
|
|
Title = "test title",
|
|
|
|
Author = new APIUser
|
|
|
|
{
|
|
|
|
Username = "mapper"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly APIBeatmapSet test_online_model = new APIBeatmapSet
|
|
|
|
{
|
|
|
|
OnlineID = 2,
|
|
|
|
Artist = "test author",
|
|
|
|
Title = "test title",
|
|
|
|
Author = new APIUser
|
|
|
|
{
|
|
|
|
Username = "mapper"
|
|
|
|
}
|
|
|
|
};
|
2019-12-27 11:37:36 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-11-25 16:23:46 +08:00
|
|
|
private void load(BeatmapModelDownloader beatmaps)
|
2019-12-27 11:37:36 +08:00
|
|
|
{
|
|
|
|
this.beatmaps = beatmaps;
|
|
|
|
|
|
|
|
beatmaps.PostNotification = n => recentNotification = n as ProgressNotification;
|
|
|
|
}
|
|
|
|
|
2021-11-09 20:34:36 +08:00
|
|
|
private static readonly object[][] notification_test_cases =
|
|
|
|
{
|
|
|
|
new object[] { test_db_model },
|
|
|
|
new object[] { test_online_model }
|
|
|
|
};
|
|
|
|
|
|
|
|
[TestCaseSource(nameof(notification_test_cases))]
|
|
|
|
public void TestNotificationMessage(IBeatmapSetInfo model)
|
|
|
|
{
|
|
|
|
AddStep("clear recent notification", () => recentNotification = null);
|
|
|
|
AddStep("download beatmap", () => beatmaps.Download(model));
|
|
|
|
|
|
|
|
AddUntilStep("wait for notification", () => recentNotification != null);
|
|
|
|
AddUntilStep("notification text correct", () => recentNotification.Text.ToString() == "Downloading test author - test title (mapper)");
|
|
|
|
}
|
|
|
|
|
2020-01-07 10:47:00 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCancelDownloadFromRequest()
|
2019-12-27 11:37:36 +08:00
|
|
|
{
|
2021-11-09 20:34:36 +08:00
|
|
|
AddStep("download beatmap", () => beatmaps.Download(test_db_model));
|
2019-12-27 11:37:36 +08:00
|
|
|
|
2021-11-09 20:34:36 +08:00
|
|
|
AddStep("cancel download from request", () => beatmaps.GetExistingDownload(test_db_model).Cancel());
|
2020-01-07 10:47:00 +08:00
|
|
|
|
2021-11-09 20:34:36 +08:00
|
|
|
AddUntilStep("is removed from download list", () => beatmaps.GetExistingDownload(test_db_model) == null);
|
2020-01-07 10:47:00 +08:00
|
|
|
AddAssert("is notification cancelled", () => recentNotification.State == ProgressNotificationState.Cancelled);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCancelDownloadFromNotification()
|
|
|
|
{
|
2021-11-09 20:34:36 +08:00
|
|
|
AddStep("download beatmap", () => beatmaps.Download(test_db_model));
|
2020-01-07 10:47:00 +08:00
|
|
|
|
|
|
|
AddStep("cancel download from notification", () => recentNotification.Close());
|
2019-12-27 11:37:36 +08:00
|
|
|
|
2021-11-09 20:34:36 +08:00
|
|
|
AddUntilStep("is removed from download list", () => beatmaps.GetExistingDownload(test_db_model) == null);
|
2019-12-27 11:37:36 +08:00
|
|
|
AddAssert("is notification cancelled", () => recentNotification.State == ProgressNotificationState.Cancelled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|