2019-06-27 12:35:14 +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.
|
|
|
|
|
2019-06-27 20:01:21 +08:00
|
|
|
using System.Linq;
|
2019-06-27 12:35:14 +08:00
|
|
|
using NUnit.Framework;
|
2019-06-27 20:01:21 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-06-27 12:35:14 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Beatmaps;
|
2019-06-27 20:01:21 +08:00
|
|
|
using osu.Game.Online;
|
2020-04-21 15:03:18 +08:00
|
|
|
using osu.Game.Overlays.BeatmapListing.Panels;
|
2019-06-27 12:35:14 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2019-06-27 20:01:21 +08:00
|
|
|
using osu.Game.Tests.Resources;
|
2019-06-27 12:35:14 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
{
|
|
|
|
public class TestSceneDirectDownloadButton : OsuTestScene
|
|
|
|
{
|
|
|
|
private TestDownloadButton downloadButton;
|
|
|
|
|
2019-06-27 20:01:21 +08:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
2019-06-27 12:35:14 +08:00
|
|
|
[Test]
|
|
|
|
public void TestDownloadableBeatmap()
|
|
|
|
{
|
|
|
|
createButton(true);
|
|
|
|
assertEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestUndownloadableBeatmap()
|
|
|
|
{
|
|
|
|
createButton(false);
|
|
|
|
assertEnabled(false);
|
|
|
|
}
|
|
|
|
|
2019-06-27 20:01:21 +08:00
|
|
|
[Test]
|
|
|
|
public void TestDownloadState()
|
|
|
|
{
|
|
|
|
AddUntilStep("ensure manager loaded", () => beatmaps != null);
|
|
|
|
ensureSoleilyRemoved();
|
|
|
|
createButtonWithBeatmap(createSoleily());
|
|
|
|
AddAssert("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
|
2020-12-07 17:00:45 +08:00
|
|
|
AddStep("import soleily", () => beatmaps.Import(TestResources.GetTestBeatmapForImport()));
|
2019-06-27 20:01:21 +08:00
|
|
|
AddUntilStep("wait for beatmap import", () => beatmaps.GetAllUsableBeatmapSets().Any(b => b.OnlineBeatmapSetID == 241526));
|
|
|
|
createButtonWithBeatmap(createSoleily());
|
|
|
|
AddAssert("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
|
|
|
|
ensureSoleilyRemoved();
|
|
|
|
AddAssert("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ensureSoleilyRemoved()
|
|
|
|
{
|
|
|
|
AddStep("remove soleily", () =>
|
|
|
|
{
|
|
|
|
var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == 241526);
|
|
|
|
|
|
|
|
if (beatmap != null) beatmaps.Delete(beatmap);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-27 12:35:14 +08:00
|
|
|
private void assertEnabled(bool enabled)
|
|
|
|
{
|
2019-06-27 12:38:21 +08:00
|
|
|
AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadEnabled == enabled);
|
2019-06-27 12:35:14 +08:00
|
|
|
}
|
|
|
|
|
2019-06-27 20:01:21 +08:00
|
|
|
private BeatmapSetInfo createSoleily()
|
|
|
|
{
|
|
|
|
return new BeatmapSetInfo
|
|
|
|
{
|
|
|
|
ID = 1,
|
|
|
|
OnlineBeatmapSetID = 241526,
|
|
|
|
OnlineInfo = new BeatmapSetOnlineInfo
|
|
|
|
{
|
|
|
|
Availability = new BeatmapSetOnlineAvailability
|
|
|
|
{
|
|
|
|
DownloadDisabled = false,
|
|
|
|
ExternalLink = string.Empty,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createButtonWithBeatmap(BeatmapSetInfo beatmap)
|
|
|
|
{
|
|
|
|
AddStep("create button", () =>
|
|
|
|
{
|
|
|
|
Child = downloadButton = new TestDownloadButton(beatmap)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(75, 50),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-27 12:35:14 +08:00
|
|
|
private void createButton(bool downloadable)
|
|
|
|
{
|
|
|
|
AddStep("create button", () =>
|
|
|
|
{
|
|
|
|
Child = downloadButton = new TestDownloadButton(downloadable ? getDownloadableBeatmapSet() : getUndownloadableBeatmapSet())
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(75, 50),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private BeatmapSetInfo getDownloadableBeatmapSet()
|
|
|
|
{
|
|
|
|
var normal = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).BeatmapSetInfo;
|
|
|
|
normal.OnlineInfo.HasVideo = true;
|
|
|
|
normal.OnlineInfo.HasStoryboard = true;
|
|
|
|
|
|
|
|
return normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
private BeatmapSetInfo getUndownloadableBeatmapSet()
|
|
|
|
{
|
|
|
|
var beatmap = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).BeatmapSetInfo;
|
|
|
|
beatmap.Metadata.Artist = "test";
|
|
|
|
beatmap.Metadata.Title = "undownloadable";
|
|
|
|
beatmap.Metadata.AuthorString = "test";
|
|
|
|
|
|
|
|
beatmap.OnlineInfo.HasVideo = true;
|
|
|
|
beatmap.OnlineInfo.HasStoryboard = true;
|
|
|
|
|
|
|
|
beatmap.OnlineInfo.Availability = new BeatmapSetOnlineAvailability
|
|
|
|
{
|
|
|
|
DownloadDisabled = true,
|
|
|
|
ExternalLink = "http://osu.ppy.sh",
|
|
|
|
};
|
|
|
|
|
|
|
|
return beatmap;
|
|
|
|
}
|
|
|
|
|
2020-04-21 15:03:18 +08:00
|
|
|
private class TestDownloadButton : BeatmapPanelDownloadButton
|
2019-06-27 12:35:14 +08:00
|
|
|
{
|
2019-06-27 12:38:21 +08:00
|
|
|
public new bool DownloadEnabled => base.DownloadEnabled;
|
2019-06-27 12:35:14 +08:00
|
|
|
|
2019-06-27 20:01:21 +08:00
|
|
|
public DownloadState DownloadState => State.Value;
|
|
|
|
|
2020-04-13 02:57:35 +08:00
|
|
|
public TestDownloadButton(BeatmapSetInfo beatmapSet)
|
|
|
|
: base(beatmapSet)
|
2019-06-27 12:35:14 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|