Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 | 6 |
| 7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 8 | 8 |
| 9 #include "chrome/common/chrome_version_info.h" | 9 #include "chrome/common/chrome_version_info.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kTestText[] = "abcd1234"; | 28 const char kTestText[] = "abcd1234"; |
| 29 | 29 |
| 30 class MockLogReceiver : public password_manager::LogReceiver { | 30 class MockLogReceiver : public password_manager::LogReceiver { |
| 31 public: | 31 public: |
| 32 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); | 32 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class TestChromePasswordManagerClient : public ChromePasswordManagerClient { | |
| 36 public: | |
| 37 explicit TestChromePasswordManagerClient(content::WebContents* web_contents) | |
| 38 : ChromePasswordManagerClient(web_contents, NULL), | |
| 39 is_sync_account_credential_(false) {} | |
| 40 virtual ~TestChromePasswordManagerClient() {} | |
| 41 | |
| 42 virtual bool IsSyncAccountCredential( | |
| 43 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.
| |
| 44 return is_sync_account_credential_; | |
| 45 } | |
| 46 | |
| 47 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.
| |
| 48 is_sync_account_credential_ = is_sync_account_credential; | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 bool is_sync_account_credential_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(TestChromePasswordManagerClient); | |
| 55 }; | |
| 56 | |
| 35 } // namespace | 57 } // namespace |
| 36 | 58 |
| 37 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { | 59 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { |
| 38 public: | 60 public: |
| 39 ChromePasswordManagerClientTest(); | 61 ChromePasswordManagerClientTest(); |
| 40 | 62 |
| 41 virtual void SetUp() OVERRIDE; | 63 virtual void SetUp() OVERRIDE; |
| 42 | 64 |
| 43 protected: | 65 protected: |
| 44 ChromePasswordManagerClient* GetClient(); | 66 ChromePasswordManagerClient* GetClient(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 ChromePasswordManagerClient* client = GetClient(); | 207 ChromePasswordManagerClient* client = GetClient(); |
| 186 service_->RegisterReceiver(&receiver_); | 208 service_->RegisterReceiver(&receiver_); |
| 187 EXPECT_TRUE(client->IsLoggingActive()); | 209 EXPECT_TRUE(client->IsLoggingActive()); |
| 188 | 210 |
| 189 EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(1); | 211 EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(1); |
| 190 client->LogSavePasswordProgress(kTestText); | 212 client->LogSavePasswordProgress(kTestText); |
| 191 | 213 |
| 192 service_->UnregisterReceiver(&receiver_); | 214 service_->UnregisterReceiver(&receiver_); |
| 193 EXPECT_FALSE(client->IsLoggingActive()); | 215 EXPECT_FALSE(client->IsLoggingActive()); |
| 194 } | 216 } |
| 217 | |
| 218 TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult_Reauth) { | |
| 219 // Make client disallow only reauth requests. | |
| 220 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 221 command_line->AppendSwitch( | |
| 222 password_manager::switches::kDisallowAutofillSyncCredentialForReauth); | |
| 223 scoped_ptr<TestChromePasswordManagerClient> client( | |
| 224 new TestChromePasswordManagerClient(web_contents())); | |
| 225 autofill::PasswordForm form; | |
| 226 | |
| 227 client->SetIsSyncAccountCredential(false); | |
| 228 NavigateAndCommit( | |
| 229 GURL("https://accounts.google.com/login?rart=123&continue=blah")); | |
| 230 EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); | |
| 231 | |
| 232 client->SetIsSyncAccountCredential(true); | |
| 233 NavigateAndCommit( | |
| 234 GURL("https://accounts.google.com/login?rart=123&continue=blah")); | |
| 235 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); | |
| 236 | |
| 237 // This counts as a reauth url, though a valid URL should have a value for | |
| 238 // "rart" | |
| 239 NavigateAndCommit(GURL("https://accounts.google.com/addlogin?rart")); | |
| 240 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); | |
| 241 | |
| 242 NavigateAndCommit(GURL("https://accounts.google.com/login?param=123")); | |
| 243 EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); | |
| 244 | |
| 245 NavigateAndCommit(GURL("https://site.com/login?rart=678")); | |
| 246 EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); | |
| 247 } | |
| 248 | |
| 249 TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult) { | |
| 250 // 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.
| |
| 251 // are the sync credential. | |
| 252 scoped_ptr<TestChromePasswordManagerClient> client( | |
| 253 new TestChromePasswordManagerClient(web_contents())); | |
| 254 autofill::PasswordForm form; | |
| 255 client->SetIsSyncAccountCredential(true); | |
| 256 NavigateAndCommit(GURL("https://accounts.google.com/Login")); | |
| 257 EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); | |
| 258 | |
| 259 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 260 command_line->AppendSwitch( | |
| 261 password_manager::switches::kDisallowAutofillSyncCredential); | |
| 262 client.reset(new TestChromePasswordManagerClient(web_contents())); | |
| 263 client->SetIsSyncAccountCredential(true); | |
| 264 NavigateAndCommit(GURL("https://accounts.google.com/Login")); | |
| 265 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
| |
| 266 } | |
| OLD | NEW |