From c1277b5db2137bf0f3e601db70c88207ddb44688 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 27 Jun 2019 13:35:14 +0900 Subject: [PATCH 1/2] Test the download button directly for safety --- .../Online/TestSceneDirectDownloadButton.cs | 95 +++++++++++++++++++ .../Visual/Online/TestSceneDirectPanel.cs | 29 +----- osu.Game/Overlays/Direct/DirectGridPanel.cs | 3 +- osu.Game/Overlays/Direct/DownloadButton.cs | 13 +-- 4 files changed, 102 insertions(+), 38 deletions(-) create mode 100644 osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs b/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs new file mode 100644 index 0000000000..4c97c00a59 --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs @@ -0,0 +1,95 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Game.Beatmaps; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Osu; +using osuTK; +using DownloadButton = osu.Game.Overlays.Direct.DownloadButton; + +namespace osu.Game.Tests.Visual.Online +{ + public class TestSceneDirectDownloadButton : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(DownloadButton) + }; + + private TestDownloadButton downloadButton; + + [Test] + public void TestDownloadableBeatmap() + { + createButton(true); + assertEnabled(true); + } + + [Test] + public void TestUndownloadableBeatmap() + { + createButton(false); + assertEnabled(false); + } + + private void assertEnabled(bool enabled) + { + AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadAllowed == enabled); + } + + 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; + } + + private class TestDownloadButton : DownloadButton + { + public new bool DownloadAllowed => base.DownloadAllowed; + + public TestDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false) + : base(beatmapSet, noVideo) + { + } + } + } +} diff --git a/osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs b/osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs index 7a305f0328..051724579b 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs @@ -52,8 +52,6 @@ private void load() normal.OnlineInfo.HasStoryboard = true; var undownloadable = getUndownloadableBeatmapSet(ruleset); - TestDirectGridPanel undownloadableGridPanel; - TestDirectListPanel undownloadableListPanel; Child = new BasicScrollContainer { @@ -69,34 +67,11 @@ private void load() { new DirectGridPanel(normal), new DirectListPanel(normal), - undownloadableGridPanel = new TestDirectGridPanel(undownloadable), - undownloadableListPanel = new TestDirectListPanel(undownloadable), + new DirectGridPanel(undownloadable), + new DirectListPanel(undownloadable), }, }, }; - - AddAssert("is download button disabled on second grid panel", () => !undownloadableGridPanel.IsDownloadButtonEnabled); - AddAssert("is download button disabled on second list panel", () => !undownloadableListPanel.IsDownloadButtonEnabled); - } - - private class TestDirectGridPanel : DirectGridPanel - { - public bool IsDownloadButtonEnabled => DownloadButton.Enabled.Value; - - public TestDirectGridPanel(BeatmapSetInfo beatmap) - : base(beatmap) - { - } - } - - private class TestDirectListPanel : DirectListPanel - { - public bool IsDownloadButtonEnabled => DownloadButton.Enabled.Value; - - public TestDirectListPanel(BeatmapSetInfo beatmap) - : base(beatmap) - { - } } } } diff --git a/osu.Game/Overlays/Direct/DirectGridPanel.cs b/osu.Game/Overlays/Direct/DirectGridPanel.cs index 571fb40d39..5756a4593d 100644 --- a/osu.Game/Overlays/Direct/DirectGridPanel.cs +++ b/osu.Game/Overlays/Direct/DirectGridPanel.cs @@ -25,7 +25,6 @@ public class DirectGridPanel : DirectPanel private const float vertical_padding = 5; private FillFlowContainer bottomPanel, statusContainer; - protected DownloadButton DownloadButton; private PlayButton playButton; private Box progressBar; @@ -156,7 +155,7 @@ private void load(OsuColour colours) }, }, }, - DownloadButton = new DownloadButton(SetInfo) + new DownloadButton(SetInfo) { Size = new Vector2(50, 30), Margin = new MarginPadding(horizontal_padding), diff --git a/osu.Game/Overlays/Direct/DownloadButton.cs b/osu.Game/Overlays/Direct/DownloadButton.cs index 1225eef8d8..25cdddd3ae 100644 --- a/osu.Game/Overlays/Direct/DownloadButton.cs +++ b/osu.Game/Overlays/Direct/DownloadButton.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; @@ -17,19 +16,17 @@ namespace osu.Game.Overlays.Direct { public class DownloadButton : BeatmapDownloadTrackingComposite { + protected bool DownloadAllowed => button.Enabled.Value; + private readonly bool noVideo; private readonly SpriteIcon icon; private readonly SpriteIcon checkmark; private readonly Box background; private OsuColour colours; - private readonly ShakeContainer shakeContainer; - private readonly OsuAnimatedButton button; - public readonly BindableBool Enabled = new BindableBool(true); - public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false) : base(beatmapSet) { @@ -66,8 +63,6 @@ public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false) } } }; - - Enabled.BindTo(button.Enabled); } protected override void LoadComplete() @@ -78,14 +73,14 @@ protected override void LoadComplete() FinishTransforms(true); } - [BackgroundDependencyLoader(permitNulls: true)] + [BackgroundDependencyLoader(true)] private void load(OsuColour colours, OsuGame game, BeatmapManager beatmaps) { this.colours = colours; if (BeatmapSet.Value.OnlineInfo.Availability?.DownloadDisabled ?? false) { - Enabled.Value = false; + button.Enabled.Value = false; button.TooltipText = "This beatmap is currently not available for download."; return; } From 9e2e393ab7a29172bc8ae53c42373740e9703365 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 27 Jun 2019 13:38:21 +0900 Subject: [PATCH 2/2] DownloadAllowed -> DownloadEnabled --- .../Visual/Online/TestSceneDirectDownloadButton.cs | 7 +++---- osu.Game/Overlays/Direct/DownloadButton.cs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs b/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs index 4c97c00a59..ceb19a3ec6 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs @@ -6,10 +6,9 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Game.Beatmaps; -using osu.Game.Rulesets; +using osu.Game.Overlays.Direct; using osu.Game.Rulesets.Osu; using osuTK; -using DownloadButton = osu.Game.Overlays.Direct.DownloadButton; namespace osu.Game.Tests.Visual.Online { @@ -38,7 +37,7 @@ public void TestUndownloadableBeatmap() private void assertEnabled(bool enabled) { - AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadAllowed == enabled); + AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadEnabled == enabled); } private void createButton(bool downloadable) @@ -84,7 +83,7 @@ private BeatmapSetInfo getUndownloadableBeatmapSet() private class TestDownloadButton : DownloadButton { - public new bool DownloadAllowed => base.DownloadAllowed; + public new bool DownloadEnabled => base.DownloadEnabled; public TestDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false) : base(beatmapSet, noVideo) diff --git a/osu.Game/Overlays/Direct/DownloadButton.cs b/osu.Game/Overlays/Direct/DownloadButton.cs index 25cdddd3ae..81709187e7 100644 --- a/osu.Game/Overlays/Direct/DownloadButton.cs +++ b/osu.Game/Overlays/Direct/DownloadButton.cs @@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Direct { public class DownloadButton : BeatmapDownloadTrackingComposite { - protected bool DownloadAllowed => button.Enabled.Value; + protected bool DownloadEnabled => button.Enabled.Value; private readonly bool noVideo; private readonly SpriteIcon icon;