2019-06-29 14:56:37 +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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-10-06 04:49:18 +08:00
|
|
|
|
using System.Linq;
|
2019-06-29 14:56:37 +08:00
|
|
|
|
using NUnit.Framework;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-06-29 14:56:37 +08:00
|
|
|
|
using osu.Game.Online;
|
2019-12-03 14:28:10 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-10-06 04:27:36 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2022-01-03 16:31:12 +08:00
|
|
|
|
using osu.Framework.Extensions;
|
2021-10-06 04:49:18 +08:00
|
|
|
|
using osu.Framework.Testing;
|
2022-01-17 13:40:06 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2021-11-06 15:45:27 +08:00
|
|
|
|
using osu.Game.Database;
|
2021-10-06 04:49:18 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-11-01 16:14:02 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2022-01-17 13:40:06 +08:00
|
|
|
|
using osu.Game.Scoring;
|
2020-03-17 16:43:16 +08:00
|
|
|
|
using osu.Game.Screens.Ranking;
|
2022-01-17 13:40:06 +08:00
|
|
|
|
using osu.Game.Tests.Resources;
|
2021-10-06 04:27:36 +08:00
|
|
|
|
using osuTK.Input;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class TestSceneReplayDownloadButton : OsuManualInputManagerTestScene
|
2019-06-29 13:25:30 +08:00
|
|
|
|
{
|
2022-04-12 17:01:29 +08:00
|
|
|
|
private const long online_score_id = 2553163309;
|
|
|
|
|
|
2019-06-29 14:56:37 +08:00
|
|
|
|
private TestReplayDownloadButton downloadButton;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
|
2022-01-17 13:40:06 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private ScoreManager scoreManager { get; set; }
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 17:01:29 +08:00
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public void SetUpSteps()
|
|
|
|
|
{
|
|
|
|
|
AddStep("delete previous imports", () =>
|
|
|
|
|
{
|
|
|
|
|
scoreManager.Delete(s => s.OnlineID == online_score_id);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 04:27:36 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDisplayStates()
|
2019-06-29 13:25:30 +08:00
|
|
|
|
{
|
2021-10-06 04:27:36 +08:00
|
|
|
|
AddStep(@"create button with replay", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(true))
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
|
|
|
|
|
2019-06-29 14:56:37 +08:00
|
|
|
|
AddStep(@"downloading state", () => downloadButton.SetDownloadState(DownloadState.Downloading));
|
|
|
|
|
AddStep(@"locally available state", () => downloadButton.SetDownloadState(DownloadState.LocallyAvailable));
|
|
|
|
|
AddStep(@"not downloaded state", () => downloadButton.SetDownloadState(DownloadState.NotDownloaded));
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 04:27:36 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestButtonWithReplayStartsDownload()
|
|
|
|
|
{
|
|
|
|
|
bool downloadStarted = false;
|
|
|
|
|
bool downloadFinished = false;
|
|
|
|
|
|
|
|
|
|
AddStep(@"create button with replay", () =>
|
|
|
|
|
{
|
|
|
|
|
downloadStarted = false;
|
|
|
|
|
downloadFinished = false;
|
|
|
|
|
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(true))
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
downloadButton.State.BindValueChanged(state =>
|
|
|
|
|
{
|
|
|
|
|
switch (state.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
downloadStarted = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (state.OldValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
downloadFinished = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
|
|
|
|
|
|
|
|
|
AddAssert("state is available", () => downloadButton.State.Value == DownloadState.NotDownloaded);
|
|
|
|
|
|
|
|
|
|
AddStep("click button", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.MoveMouseTo(downloadButton);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddAssert("state entered downloading", () => downloadStarted);
|
|
|
|
|
AddUntilStep("state left downloading", () => downloadFinished);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestButtonWithoutReplay()
|
2019-06-29 14:56:37 +08:00
|
|
|
|
{
|
2021-10-06 04:27:36 +08:00
|
|
|
|
AddStep("create button without replay", () =>
|
2019-06-29 13:25:30 +08:00
|
|
|
|
{
|
2021-10-06 04:27:36 +08:00
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(false))
|
2019-06-29 15:19:03 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
2019-06-29 13:25:30 +08:00
|
|
|
|
});
|
2020-05-28 20:46:02 +08:00
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
2021-10-06 04:49:18 +08:00
|
|
|
|
|
|
|
|
|
AddAssert("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded);
|
|
|
|
|
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
2020-05-28 20:46:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 15:12:06 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestLocallyAvailableWithoutReplay()
|
|
|
|
|
{
|
|
|
|
|
Live<ScoreInfo> imported = null;
|
|
|
|
|
|
|
|
|
|
AddStep("import score", () => imported = scoreManager.Import(getScoreInfo(false, false)));
|
|
|
|
|
|
|
|
|
|
AddStep("create button without replay", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(imported.Value)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
|
|
|
|
|
|
|
|
|
AddUntilStep("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded);
|
|
|
|
|
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-06 15:45:27 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestScoreImportThenDelete()
|
|
|
|
|
{
|
2022-01-26 12:37:33 +08:00
|
|
|
|
Live<ScoreInfo> imported = null;
|
2021-11-06 15:45:27 +08:00
|
|
|
|
|
|
|
|
|
AddStep("create button without replay", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(false))
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
|
|
|
|
|
|
|
|
|
AddUntilStep("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded);
|
|
|
|
|
|
2022-01-25 14:23:51 +08:00
|
|
|
|
AddStep("import score", () => imported = scoreManager.Import(getScoreInfo(true)));
|
2021-11-06 15:45:27 +08:00
|
|
|
|
|
|
|
|
|
AddUntilStep("state is available", () => downloadButton.State.Value == DownloadState.LocallyAvailable);
|
2022-04-05 16:00:33 +08:00
|
|
|
|
AddAssert("button is enabled", () => downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
2021-11-06 15:45:27 +08:00
|
|
|
|
|
|
|
|
|
AddStep("delete score", () => scoreManager.Delete(imported.Value));
|
|
|
|
|
|
|
|
|
|
AddUntilStep("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded);
|
2022-04-05 16:00:33 +08:00
|
|
|
|
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
2021-11-06 15:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 04:27:36 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void CreateButtonWithNoScore()
|
2020-05-28 20:46:02 +08:00
|
|
|
|
{
|
|
|
|
|
AddStep("create button with null score", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(null)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
2021-10-06 04:49:18 +08:00
|
|
|
|
|
2022-09-08 15:48:43 +08:00
|
|
|
|
AddAssert("state is unknown", () => downloadButton.State.Value == DownloadState.Unknown);
|
2021-10-06 04:49:18 +08:00
|
|
|
|
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
2019-06-29 13:25:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-25 18:03:06 +08:00
|
|
|
|
private ScoreInfo getScoreInfo(bool replayAvailable, bool hasOnlineId = true) => new ScoreInfo
|
2019-06-29 13:25:30 +08:00
|
|
|
|
{
|
2022-07-25 18:03:06 +08:00
|
|
|
|
OnlineID = hasOnlineId ? online_score_id : 0,
|
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo,
|
|
|
|
|
BeatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First(),
|
2022-07-25 20:19:32 +08:00
|
|
|
|
Hash = replayAvailable ? "online" : string.Empty,
|
2022-07-25 18:03:06 +08:00
|
|
|
|
User = new APIUser
|
2019-06-29 13:25:30 +08:00
|
|
|
|
{
|
2022-07-25 18:03:06 +08:00
|
|
|
|
Id = 39828,
|
|
|
|
|
Username = @"WubWoofWolf",
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-06-29 14:56:37 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class TestReplayDownloadButton : ReplayDownloadButton
|
2019-06-29 14:56:37 +08:00
|
|
|
|
{
|
|
|
|
|
public void SetDownloadState(DownloadState state) => State.Value = state;
|
|
|
|
|
|
2021-10-06 04:27:36 +08:00
|
|
|
|
public new Bindable<DownloadState> State => base.State;
|
|
|
|
|
|
2019-06-29 14:59:12 +08:00
|
|
|
|
public TestReplayDownloadButton(ScoreInfo score)
|
|
|
|
|
: base(score)
|
2019-06-29 14:56:37 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-29 13:25:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|