Commit 51e7e69e authored by Jialiu Lin's avatar Jialiu Lin Committed by Commit Bot

ShouldShowChangePasswordSettingUI() should consider previous session

If user see modal warning, ignore it, then restart browser, change
password card should still be showing on chrome://settings page.

Bug: 765807
Change-Id: Iaeedcc4e68f865b0fc263e0b4f7cc460df43302f
Reviewed-on: https://chromium-review.googlesource.com/683461Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarNathan Parker <nparker@chromium.org>
Reviewed-by: default avatarLuke Z <lpz@chromium.org>
Commit-Queue: Jialiu Lin <jialiul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505247}
parent d0c7052e
......@@ -140,6 +140,14 @@ ChromePasswordProtectionService::~ChromePasswordProtectionService() {
LoginReputationClientRequest::PASSWORD_REUSE_EVENT));
}
// Before shutdown, if there is still unhandled password reuses, we set the
// kSafeBrowsingChangePasswordInSettingsEnabled to true. So next time when
// user starts a new session, change password card will show on Chrome
// settings page.
profile_->GetPrefs()->SetBoolean(
prefs::kSafeBrowsingChangePasswordInSettingsEnabled,
!unhandled_password_reuses_.empty());
if (pref_change_registrar_)
pref_change_registrar_->RemoveAll();
}
......@@ -161,7 +169,9 @@ bool ChromePasswordProtectionService::ShouldShowChangePasswordSettingUI(
Profile* profile) {
ChromePasswordProtectionService* service =
ChromePasswordProtectionService::GetPasswordProtectionService(profile);
return service && !service->unhandled_password_reuses().empty();
return service && (!service->unhandled_password_reuses().empty() ||
profile->GetPrefs()->GetBoolean(
prefs::kSafeBrowsingChangePasswordInSettingsEnabled));
}
void ChromePasswordProtectionService::FillReferrerChain(
......
......@@ -16,6 +16,7 @@
#include "chrome/test/base/ui_test_utils.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/safe_browsing/features.h"
#include "components/security_state/core/security_state.h"
#include "components/signin/core/browser/account_info.h"
......@@ -305,6 +306,29 @@ IN_PROC_BROWSER_TEST_F(ChromePasswordProtectionServiceBrowserTest,
testing::ElementsAre(base::Bucket(2, 1)));
}
IN_PROC_BROWSER_TEST_F(ChromePasswordProtectionServiceBrowserTest,
VerifyShouldShowChangePasswordSettingUI) {
Profile* profile = browser()->profile();
EXPECT_FALSE(
ChromePasswordProtectionService::ShouldShowChangePasswordSettingUI(
profile));
// Simulates previous session has unhandled password reuses.
profile->GetPrefs()->SetBoolean(
prefs::kSafeBrowsingChangePasswordInSettingsEnabled, true);
EXPECT_TRUE(
ChromePasswordProtectionService::ShouldShowChangePasswordSettingUI(
profile));
// Simulates a Gaia password change.
SimulateGaiaPasswordChanged(GetService(/*is_incognito=*/false));
EXPECT_FALSE(
ChromePasswordProtectionService::ShouldShowChangePasswordSettingUI(
profile));
EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
prefs::kSafeBrowsingChangePasswordInSettingsEnabled));
}
// TODO(jialiul): Add more tests where multiple browser windows are involved.
} // namespace safe_browsing
......@@ -46,14 +46,13 @@ void ChangePasswordHandler::OnJavascriptDisallowed() {
}
void ChangePasswordHandler::OnGaiaPasswordChanged() {
CallJavascriptFunction("cr.webUIListenerCallback",
base::Value("change-password-on-dismiss"));
FireWebUIListener("change-password-on-dismiss");
}
void ChangePasswordHandler::OnMarkingSiteAsLegitimate(const GURL& url) {
if (service_->unhandled_password_reuses().empty()) {
CallJavascriptFunction("cr.webUIListenerCallback",
base::Value("change-password-on-dismiss"));
if (!ChromePasswordProtectionService::ShouldShowChangePasswordSettingUI(
profile_)) {
FireWebUIListener("change-password-on-dismiss");
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment