2022-07-19 17:50:27 +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 System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2022-10-14 03:03:52 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2022-07-19 17:50:27 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Online.API;
|
2022-10-13 07:40:20 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Dialog;
|
2022-07-19 17:50:27 +08:00
|
|
|
using osu.Game.Screens.Select;
|
|
|
|
using osu.Game.Screens.Select.Carousel;
|
|
|
|
using osu.Game.Tests.Online;
|
|
|
|
using osu.Game.Tests.Resources;
|
2022-10-13 07:40:20 +08:00
|
|
|
using osuTK.Input;
|
2022-07-19 17:50:27 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.SongSelect
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class TestSceneUpdateBeatmapSetButton : OsuManualInputManagerTestScene
|
|
|
|
{
|
|
|
|
private BeatmapCarousel carousel = null!;
|
|
|
|
|
|
|
|
private TestSceneOnlinePlayBeatmapAvailabilityTracker.TestBeatmapModelDownloader beatmapDownloader = null!;
|
|
|
|
|
2022-07-19 18:01:23 +08:00
|
|
|
private BeatmapSetInfo testBeatmapSetInfo = null!;
|
|
|
|
|
2022-07-19 17:50:27 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
{
|
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
|
|
|
|
2022-07-19 19:06:19 +08:00
|
|
|
var importer = parent.Get<BeatmapManager>();
|
2022-07-19 17:50:27 +08:00
|
|
|
|
|
|
|
dependencies.CacheAs<BeatmapModelDownloader>(beatmapDownloader = new TestSceneOnlinePlayBeatmapAvailabilityTracker.TestBeatmapModelDownloader(importer, API));
|
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
2022-07-19 18:01:23 +08:00
|
|
|
private UpdateBeatmapSetButton? getUpdateButton() => carousel.ChildrenOfType<UpdateBeatmapSetButton>().SingleOrDefault();
|
2022-07-19 17:50:27 +08:00
|
|
|
|
2022-07-19 18:01:23 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
2022-10-13 07:40:20 +08:00
|
|
|
AddStep("create carousel", () => Child = createCarousel());
|
2022-07-19 17:50:27 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => carousel.BeatmapSetsLoaded);
|
|
|
|
|
|
|
|
AddAssert("update button not visible", () => getUpdateButton() == null);
|
2022-07-19 18:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDownloadToCompletion()
|
|
|
|
{
|
|
|
|
ArchiveDownloadRequest<IBeatmapSetInfo>? downloadRequest = null;
|
2022-07-19 17:50:27 +08:00
|
|
|
|
|
|
|
AddStep("update online hash", () =>
|
|
|
|
{
|
|
|
|
testBeatmapSetInfo.Beatmaps.First().OnlineMD5Hash = "different hash";
|
|
|
|
testBeatmapSetInfo.Beatmaps.First().LastOnlineUpdate = DateTimeOffset.Now;
|
|
|
|
|
|
|
|
carousel.UpdateBeatmapSet(testBeatmapSetInfo);
|
|
|
|
});
|
|
|
|
|
2022-07-21 15:24:46 +08:00
|
|
|
AddUntilStep("only one set visible", () => carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().Count() == 1);
|
2022-07-19 17:50:27 +08:00
|
|
|
AddUntilStep("update button visible", () => getUpdateButton() != null);
|
|
|
|
|
|
|
|
AddStep("click button", () => getUpdateButton()?.TriggerClick());
|
|
|
|
|
|
|
|
AddUntilStep("wait for download started", () =>
|
|
|
|
{
|
|
|
|
downloadRequest = beatmapDownloader.GetExistingDownload(testBeatmapSetInfo);
|
|
|
|
return downloadRequest != null;
|
|
|
|
});
|
|
|
|
|
2022-07-19 18:01:23 +08:00
|
|
|
AddUntilStep("wait for button disabled", () => getUpdateButton()?.Enabled.Value == false);
|
|
|
|
|
2022-07-19 17:50:27 +08:00
|
|
|
AddUntilStep("progress download to completion", () =>
|
|
|
|
{
|
|
|
|
if (downloadRequest is TestSceneOnlinePlayBeatmapAvailabilityTracker.TestDownloadRequest testRequest)
|
|
|
|
{
|
|
|
|
testRequest.SetProgress(testRequest.Progress + 0.1f);
|
|
|
|
|
|
|
|
if (testRequest.Progress >= 1)
|
|
|
|
{
|
|
|
|
testRequest.TriggerSuccess();
|
|
|
|
|
|
|
|
// usually this would be done by the import process.
|
|
|
|
testBeatmapSetInfo.Beatmaps.First().MD5Hash = "different hash";
|
|
|
|
testBeatmapSetInfo.Beatmaps.First().LastOnlineUpdate = DateTimeOffset.Now;
|
|
|
|
|
|
|
|
// usually this would be done by a realm subscription.
|
|
|
|
carousel.UpdateBeatmapSet(testBeatmapSetInfo);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2022-07-19 18:01:23 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDownloadFailed()
|
|
|
|
{
|
|
|
|
ArchiveDownloadRequest<IBeatmapSetInfo>? downloadRequest = null;
|
|
|
|
|
|
|
|
AddStep("update online hash", () =>
|
|
|
|
{
|
|
|
|
testBeatmapSetInfo.Beatmaps.First().OnlineMD5Hash = "different hash";
|
|
|
|
testBeatmapSetInfo.Beatmaps.First().LastOnlineUpdate = DateTimeOffset.Now;
|
|
|
|
|
|
|
|
carousel.UpdateBeatmapSet(testBeatmapSetInfo);
|
|
|
|
});
|
|
|
|
|
2022-07-21 15:24:46 +08:00
|
|
|
AddUntilStep("only one set visible", () => carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().Count() == 1);
|
2022-07-19 18:01:23 +08:00
|
|
|
AddUntilStep("update button visible", () => getUpdateButton() != null);
|
|
|
|
|
|
|
|
AddStep("click button", () => getUpdateButton()?.TriggerClick());
|
|
|
|
|
|
|
|
AddUntilStep("wait for download started", () =>
|
|
|
|
{
|
|
|
|
downloadRequest = beatmapDownloader.GetExistingDownload(testBeatmapSetInfo);
|
|
|
|
return downloadRequest != null;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for button disabled", () => getUpdateButton()?.Enabled.Value == false);
|
|
|
|
|
|
|
|
AddUntilStep("progress download to failure", () =>
|
|
|
|
{
|
|
|
|
if (downloadRequest is TestSceneOnlinePlayBeatmapAvailabilityTracker.TestDownloadRequest testRequest)
|
|
|
|
{
|
|
|
|
testRequest.SetProgress(testRequest.Progress + 0.1f);
|
|
|
|
|
|
|
|
if (testRequest.Progress >= 0.5f)
|
|
|
|
{
|
|
|
|
testRequest.TriggerFailure(new Exception());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for button enabled", () => getUpdateButton()?.Enabled.Value == true);
|
|
|
|
}
|
2022-10-13 07:40:20 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestUpdateLocalBeatmap()
|
|
|
|
{
|
|
|
|
DialogOverlay dialogOverlay = null!;
|
2022-10-14 03:03:52 +08:00
|
|
|
UpdateBeatmapSetButton? updateButton = null;
|
2022-10-13 07:40:20 +08:00
|
|
|
|
|
|
|
AddStep("create carousel with dialog overlay", () =>
|
|
|
|
{
|
|
|
|
dialogOverlay = new DialogOverlay();
|
|
|
|
|
|
|
|
Child = new DependencyProvidingContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
CachedDependencies = new (Type, object)[] { (typeof(IDialogOverlay), dialogOverlay), },
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
createCarousel(),
|
|
|
|
dialogOverlay,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("setup beatmap state", () =>
|
|
|
|
{
|
|
|
|
testBeatmapSetInfo.Beatmaps.First().OnlineMD5Hash = "different hash";
|
|
|
|
testBeatmapSetInfo.Beatmaps.First().LastOnlineUpdate = DateTimeOffset.Now;
|
|
|
|
testBeatmapSetInfo.Status = BeatmapOnlineStatus.LocallyModified;
|
|
|
|
|
|
|
|
carousel.UpdateBeatmapSet(testBeatmapSetInfo);
|
|
|
|
});
|
|
|
|
|
2022-10-14 03:03:52 +08:00
|
|
|
AddUntilStep("wait for update button", () => (updateButton = getUpdateButton()) != null);
|
|
|
|
AddStep("click button", () => updateButton.AsNonNull().TriggerClick());
|
2022-10-13 07:40:20 +08:00
|
|
|
|
|
|
|
AddAssert("dialog displayed", () => dialogOverlay.CurrentDialog is UpdateLocalConfirmationDialog);
|
|
|
|
AddStep("click confirmation", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(dialogOverlay.CurrentDialog.ChildrenOfType<PopupDialogButton>().First());
|
|
|
|
InputManager.PressButton(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("update started", () => beatmapDownloader.GetExistingDownload(testBeatmapSetInfo) != null);
|
|
|
|
AddStep("release mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
|
|
|
|
}
|
|
|
|
|
|
|
|
private BeatmapCarousel createCarousel()
|
|
|
|
{
|
|
|
|
return carousel = new BeatmapCarousel
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
BeatmapSets = new List<BeatmapSetInfo>
|
|
|
|
{
|
|
|
|
(testBeatmapSetInfo = TestResources.CreateTestBeatmapSetInfo()),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2022-07-19 17:50:27 +08:00
|
|
|
}
|
|
|
|
}
|