diff --git a/osu.Game.Tests/Visual/Menus/TestSceneLoginOverlay.cs b/osu.Game.Tests/Visual/Menus/TestSceneLoginOverlay.cs index 5fc075ed99..e603f72bb8 100644 --- a/osu.Game.Tests/Visual/Menus/TestSceneLoginOverlay.cs +++ b/osu.Game.Tests/Visual/Menus/TestSceneLoginOverlay.cs @@ -8,11 +8,13 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Testing; +using osu.Game.Configuration; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Overlays; using osu.Game.Overlays.Login; +using osu.Game.Overlays.Settings; using osu.Game.Users.Drawables; using osuTK.Input; @@ -25,6 +27,9 @@ namespace osu.Game.Tests.Visual.Menus private LoginOverlay loginOverlay = null!; + [Resolved] + private OsuConfigManager configManager { get; set; } = null!; + [BackgroundDependencyLoader] private void load() { @@ -156,5 +161,36 @@ namespace osu.Game.Tests.Visual.Menus }); AddAssert("login overlay is hidden", () => loginOverlay.State.Value == Visibility.Hidden); } + + [Test] + public void TestUncheckingRememberUsernameClearsIt() + { + AddStep("logout", () => API.Logout()); + AddStep("set username", () => configManager.SetValue(OsuSetting.Username, "test_user")); + AddStep("set remember password", () => configManager.SetValue(OsuSetting.SavePassword, true)); + AddStep("uncheck remember username", () => + { + InputManager.MoveMouseTo(loginOverlay.ChildrenOfType().First()); + InputManager.Click(MouseButton.Left); + }); + AddAssert("remember username off", () => configManager.Get(OsuSetting.SaveUsername), () => Is.False); + AddAssert("remember password off", () => configManager.Get(OsuSetting.SavePassword), () => Is.False); + AddAssert("username cleared", () => configManager.Get(OsuSetting.Username), () => Is.Empty); + } + + [Test] + public void TestUncheckingRememberPasswordClearsToken() + { + AddStep("logout", () => API.Logout()); + AddStep("set token", () => configManager.SetValue(OsuSetting.Token, "test_token")); + AddStep("set remember password", () => configManager.SetValue(OsuSetting.SavePassword, true)); + AddStep("uncheck remember token", () => + { + InputManager.MoveMouseTo(loginOverlay.ChildrenOfType().Last()); + InputManager.Click(MouseButton.Left); + }); + AddAssert("remember password off", () => configManager.Get(OsuSetting.SavePassword), () => Is.False); + AddAssert("token cleared", () => configManager.Get(OsuSetting.Token), () => Is.Empty); + } } } diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 6b2cb4ee74..a71460ded7 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -77,12 +77,19 @@ namespace osu.Game.Configuration SetDefault(OsuSetting.SavePassword, false).ValueChanged += enabled => { - if (enabled.NewValue) SetValue(OsuSetting.SaveUsername, true); + if (enabled.NewValue) + SetValue(OsuSetting.SaveUsername, true); + else + GetBindable(OsuSetting.Token).SetDefault(); }; SetDefault(OsuSetting.SaveUsername, true).ValueChanged += enabled => { - if (!enabled.NewValue) SetValue(OsuSetting.SavePassword, false); + if (!enabled.NewValue) + { + GetBindable(OsuSetting.Username).SetDefault(); + SetValue(OsuSetting.SavePassword, false); + } }; SetDefault(OsuSetting.ExternalLinkWarning, true);