Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7039)

Unified Diff: chrome/browser/password_manager/chrome_password_manager_client_unittest.cc

Issue 451853003: [Password Manager] Setup experiment to restrict autofilling of sync credential (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
diff --git a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
index 100a3e6b7fca7c43eaa4a5a26a1c6ce957fe8edd..56295dce5a2039ce2f72264dbea32c21f509f458 100644
--- a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
+++ b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
@@ -32,6 +32,28 @@ class MockLogReceiver : public password_manager::LogReceiver {
MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&));
};
+class TestChromePasswordManagerClient : public ChromePasswordManagerClient {
+ public:
+ explicit TestChromePasswordManagerClient(content::WebContents* web_contents)
+ : ChromePasswordManagerClient(web_contents, NULL),
+ is_sync_account_credential_(false) {}
+ virtual ~TestChromePasswordManagerClient() {}
+
+ virtual bool IsSyncAccountCredential(
+ const std::string& username, const std::string& origin) const OVERRIDE {
Ilya Sherman 2014/08/13 20:48:14 nit: One param per line, please.
Garrett Casto 2014/08/13 23:12:54 Done.
+ return is_sync_account_credential_;
+ }
+
+ void SetIsSyncAccountCredential(bool is_sync_account_credential) {
Ilya Sherman 2014/08/13 20:48:14 nit: hacker_case, please.
Garrett Casto 2014/08/13 23:12:54 Done.
+ is_sync_account_credential_ = is_sync_account_credential;
+ }
+
+ private:
+ bool is_sync_account_credential_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestChromePasswordManagerClient);
+};
+
} // namespace
class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness {
@@ -192,3 +214,53 @@ TEST_F(ChromePasswordManagerClientTest, LogToAReceiver) {
service_->UnregisterReceiver(&receiver_);
EXPECT_FALSE(client->IsLoggingActive());
}
+
+TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult_Reauth) {
+ // Make client disallow only reauth requests.
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ command_line->AppendSwitch(
+ password_manager::switches::kDisallowAutofillSyncCredentialForReauth);
+ scoped_ptr<TestChromePasswordManagerClient> client(
+ new TestChromePasswordManagerClient(web_contents()));
+ autofill::PasswordForm form;
+
+ client->SetIsSyncAccountCredential(false);
+ NavigateAndCommit(
+ GURL("https://accounts.google.com/login?rart=123&continue=blah"));
+ EXPECT_FALSE(client->ShouldFilterAutofillResult(form));
+
+ client->SetIsSyncAccountCredential(true);
+ NavigateAndCommit(
+ GURL("https://accounts.google.com/login?rart=123&continue=blah"));
+ EXPECT_TRUE(client->ShouldFilterAutofillResult(form));
+
+ // This counts as a reauth url, though a valid URL should have a value for
+ // "rart"
+ NavigateAndCommit(GURL("https://accounts.google.com/addlogin?rart"));
+ EXPECT_TRUE(client->ShouldFilterAutofillResult(form));
+
+ NavigateAndCommit(GURL("https://accounts.google.com/login?param=123"));
+ EXPECT_FALSE(client->ShouldFilterAutofillResult(form));
+
+ NavigateAndCommit(GURL("https://site.com/login?rart=678"));
+ EXPECT_FALSE(client->ShouldFilterAutofillResult(form));
+}
+
+TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult) {
+ // Normally the client should allow any credentials thourgh, even if they
Ilya Sherman 2014/08/13 20:48:14 nit: "thourgh" -> "through"
Garrett Casto 2014/08/13 23:12:54 Done.
+ // are the sync credential.
+ scoped_ptr<TestChromePasswordManagerClient> client(
+ new TestChromePasswordManagerClient(web_contents()));
+ autofill::PasswordForm form;
+ client->SetIsSyncAccountCredential(true);
+ NavigateAndCommit(GURL("https://accounts.google.com/Login"));
+ EXPECT_FALSE(client->ShouldFilterAutofillResult(form));
+
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ command_line->AppendSwitch(
+ password_manager::switches::kDisallowAutofillSyncCredential);
+ client.reset(new TestChromePasswordManagerClient(web_contents()));
+ client->SetIsSyncAccountCredential(true);
+ NavigateAndCommit(GURL("https://accounts.google.com/Login"));
+ EXPECT_TRUE(client->ShouldFilterAutofillResult(form));
Ilya Sherman 2014/08/13 20:48:14 Optional nit: WDYT of "ShouldDrop" rather than "Sh
Garrett Casto 2014/08/13 23:12:54 I'm indifferent. If you prefer I can change it, bu
+}

Powered by Google App Engine
This is Rietveld 408576698