Chromium Code Reviews| 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..06b2263a7a2555b777532f14b2846c30712af50a 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,29 @@ 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 { |
| + return is_sync_account_credential_; |
| + } |
| + |
| + void set_is_sync_account_credential(bool is_sync_account_credential) { |
| + 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 +215,54 @@ 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->set_is_sync_account_credential(false); |
| + NavigateAndCommit( |
| + GURL("https://accounts.google.com/login?rart=123&continue=blah")); |
| + EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); |
| + |
| + client->set_is_sync_account_credential(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 through, even if they |
| + // are the sync credential. |
| + scoped_ptr<TestChromePasswordManagerClient> client( |
| + new TestChromePasswordManagerClient(web_contents())); |
| + autofill::PasswordForm form; |
| + client->set_is_sync_account_credential(true); |
| + NavigateAndCommit(GURL("https://accounts.google.com/Login")); |
| + EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); |
| + |
| + // |
|
Ilya Sherman
2014/08/14 07:38:14
nit: ^^^
Garrett Casto
2014/08/14 19:48:43
Filled out the comment I meant to leave.
|
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + command_line->AppendSwitch( |
| + password_manager::switches::kDisallowAutofillSyncCredential); |
| + client.reset(new TestChromePasswordManagerClient(web_contents())); |
| + client->set_is_sync_account_credential(true); |
| + NavigateAndCommit(GURL("https://accounts.google.com/Login")); |
| + EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); |
| +} |