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 "chrome/browser/password_manager/chrome_password_manager_client.h" | 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/sync/profile_sync_service_factory.h" | 10 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 explicit TestChromePasswordManagerClient(content::WebContents* web_contents) | 43 explicit TestChromePasswordManagerClient(content::WebContents* web_contents) |
| 44 : ChromePasswordManagerClient(web_contents, nullptr), | 44 : ChromePasswordManagerClient(web_contents, nullptr), |
| 45 is_sync_account_credential_(false) {} | 45 is_sync_account_credential_(false) {} |
| 46 ~TestChromePasswordManagerClient() override {} | 46 ~TestChromePasswordManagerClient() override {} |
| 47 | 47 |
| 48 bool IsSyncAccountCredential(const std::string& username, | 48 bool IsSyncAccountCredential(const std::string& username, |
| 49 const std::string& origin) const override { | 49 const std::string& origin) const override { |
| 50 return is_sync_account_credential_; | 50 return is_sync_account_credential_; |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool DidLastPageLoadEncounterSSLErrors() const override { | |
| 54 return ssl_errors_; | |
| 55 } | |
| 56 | |
| 57 bool IsPasswordManagerEnabledForCurrentPage() const override { | |
| 58 return is_password_manager_enabled_for_current_page_; | |
| 59 } | |
| 60 | |
| 53 void set_is_sync_account_credential(bool is_sync_account_credential) { | 61 void set_is_sync_account_credential(bool is_sync_account_credential) { |
| 54 is_sync_account_credential_ = is_sync_account_credential; | 62 is_sync_account_credential_ = is_sync_account_credential; |
| 55 } | 63 } |
| 56 | 64 |
| 65 void set_ssl_errors(bool ssl_errors) { ssl_errors_ = ssl_errors; } | |
| 66 | |
| 67 void set_is_password_manager_enabled_for_current_page( | |
| 68 bool is_password_manager_enabled_for_current_page) { | |
| 69 is_password_manager_enabled_for_current_page_ = | |
| 70 is_password_manager_enabled_for_current_page; | |
| 71 } | |
| 72 | |
| 57 private: | 73 private: |
| 58 bool is_sync_account_credential_; | 74 bool is_sync_account_credential_; |
| 75 bool is_password_manager_enabled_for_current_page_; | |
| 76 bool ssl_errors_; | |
| 59 | 77 |
| 60 DISALLOW_COPY_AND_ASSIGN(TestChromePasswordManagerClient); | 78 DISALLOW_COPY_AND_ASSIGN(TestChromePasswordManagerClient); |
| 61 }; | 79 }; |
| 62 | 80 |
| 63 } // namespace | 81 } // namespace |
| 64 | 82 |
| 65 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { | 83 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { |
| 66 public: | 84 public: |
| 67 ChromePasswordManagerClientTest(); | 85 ChromePasswordManagerClientTest(); |
| 68 | 86 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 // Adding disallow switch should cause sync credential to be filtered. | 285 // Adding disallow switch should cause sync credential to be filtered. |
| 268 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 286 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 269 command_line->AppendSwitch( | 287 command_line->AppendSwitch( |
| 270 password_manager::switches::kDisallowAutofillSyncCredential); | 288 password_manager::switches::kDisallowAutofillSyncCredential); |
| 271 client.reset(new TestChromePasswordManagerClient(web_contents())); | 289 client.reset(new TestChromePasswordManagerClient(web_contents())); |
| 272 client->set_is_sync_account_credential(true); | 290 client->set_is_sync_account_credential(true); |
| 273 NavigateAndCommit(GURL("https://accounts.google.com/Login")); | 291 NavigateAndCommit(GURL("https://accounts.google.com/Login")); |
| 274 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); | 292 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); |
| 275 } | 293 } |
| 276 | 294 |
| 295 TEST_F(ChromePasswordManagerClientTest, IsEnabledForCurrentPage) { | |
|
vabr (Chromium)
2015/03/26 14:51:59
If you get rid of IsEnabledForCurrentPage, then of
melandory
2015/03/30 09:50:17
Done.
| |
| 296 scoped_ptr<TestChromePasswordManagerClient> client( | |
| 297 new TestChromePasswordManagerClient(web_contents())); | |
| 298 client->set_ssl_errors(true); | |
| 299 client->set_is_password_manager_enabled_for_current_page(true); | |
| 300 EXPECT_FALSE(client->IsEnabledForCurrentPage()); | |
| 301 | |
| 302 client->set_ssl_errors(true); | |
| 303 client->set_is_password_manager_enabled_for_current_page(false); | |
| 304 EXPECT_FALSE(client->IsEnabledForCurrentPage()); | |
| 305 | |
| 306 client->set_ssl_errors(false); | |
| 307 client->set_is_password_manager_enabled_for_current_page(false); | |
| 308 EXPECT_FALSE(client->IsEnabledForCurrentPage()); | |
| 309 | |
| 310 client->set_ssl_errors(false); | |
| 311 client->set_is_password_manager_enabled_for_current_page(true); | |
| 312 EXPECT_TRUE(client->IsEnabledForCurrentPage()); | |
| 313 } | |
| 314 | |
| 277 TEST_F(ChromePasswordManagerClientTest, | 315 TEST_F(ChromePasswordManagerClientTest, |
| 278 IsPasswordManagerEnabledForCurrentPage) { | 316 IsPasswordManagerEnabledForCurrentPage) { |
| 279 ChromePasswordManagerClient* client = GetClient(); | 317 ChromePasswordManagerClient* client = GetClient(); |
| 280 NavigateAndCommit( | 318 NavigateAndCommit( |
| 281 GURL("https://accounts.google.com/ServiceLogin?continue=" | 319 GURL("https://accounts.google.com/ServiceLogin?continue=" |
| 282 "https://passwords.google.com/settings&rart=123")); | 320 "https://passwords.google.com/settings&rart=123")); |
| 283 EXPECT_FALSE(client->IsPasswordManagerEnabledForCurrentPage()); | 321 EXPECT_FALSE(client->IsPasswordManagerEnabledForCurrentPage()); |
| 284 | 322 |
| 285 // Password site is inaccesible via HTTP, but because of HSTS the following | 323 // Password site is inaccesible via HTTP, but because of HSTS the following |
| 286 // link should still continue to https://passwords.google.com. | 324 // link should still continue to https://passwords.google.com. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 | 419 |
| 382 // Again, without a custom passphrase. | 420 // Again, without a custom passphrase. |
| 383 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | 421 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
| 384 .WillRepeatedly(Return(false)); | 422 .WillRepeatedly(Return(false)); |
| 385 | 423 |
| 386 EXPECT_FALSE( | 424 EXPECT_FALSE( |
| 387 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); | 425 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); |
| 388 EXPECT_FALSE(client->IsPasswordSyncEnabled( | 426 EXPECT_FALSE(client->IsPasswordSyncEnabled( |
| 389 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); | 427 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); |
| 390 } | 428 } |
| OLD | NEW |