mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 04:02:57 +08:00
Test the download button directly for safety
This commit is contained in:
parent
3294464bc6
commit
c1277b5db2
@ -0,0 +1,95 @@
|
||||
// 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.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<Type> 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -52,8 +52,6 @@ namespace osu.Game.Tests.Visual.Online
|
||||
normal.OnlineInfo.HasStoryboard = true;
|
||||
|
||||
var undownloadable = getUndownloadableBeatmapSet(ruleset);
|
||||
TestDirectGridPanel undownloadableGridPanel;
|
||||
TestDirectListPanel undownloadableListPanel;
|
||||
|
||||
Child = new BasicScrollContainer
|
||||
{
|
||||
@ -69,34 +67,11 @@ namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ namespace osu.Game.Overlays.Direct
|
||||
private const float vertical_padding = 5;
|
||||
|
||||
private FillFlowContainer bottomPanel, statusContainer;
|
||||
protected DownloadButton DownloadButton;
|
||||
private PlayButton playButton;
|
||||
private Box progressBar;
|
||||
|
||||
@ -156,7 +155,7 @@ namespace osu.Game.Overlays.Direct
|
||||
},
|
||||
},
|
||||
},
|
||||
DownloadButton = new DownloadButton(SetInfo)
|
||||
new DownloadButton(SetInfo)
|
||||
{
|
||||
Size = new Vector2(50, 30),
|
||||
Margin = new MarginPadding(horizontal_padding),
|
||||
|
@ -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 @@ namespace osu.Game.Overlays.Direct
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Enabled.BindTo(button.Enabled);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -78,14 +73,14 @@ namespace osu.Game.Overlays.Direct
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user