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" |
| 11 #include "chrome/browser/sync/profile_sync_service_mock.h" |
10 #include "chrome/common/chrome_version_info.h" | 12 #include "chrome/common/chrome_version_info.h" |
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
12 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
13 #include "components/autofill/content/common/autofill_messages.h" | 15 #include "components/autofill/content/common/autofill_messages.h" |
14 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" | 16 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" |
15 #include "components/password_manager/content/common/credential_manager_messages
.h" | 17 #include "components/password_manager/content/common/credential_manager_messages
.h" |
16 #include "components/password_manager/content/common/credential_manager_types.h" | 18 #include "components/password_manager/content/common/credential_manager_types.h" |
17 #include "components/password_manager/core/browser/log_receiver.h" | 19 #include "components/password_manager/core/browser/log_receiver.h" |
18 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" | 20 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" |
19 #include "components/password_manager/core/common/password_manager_switches.h" | 21 #include "components/password_manager/core/common/password_manager_switches.h" |
20 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "content/public/test/mock_render_process_host.h" | 24 #include "content/public/test/mock_render_process_host.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
25 | 27 |
26 using content::BrowserContext; | 28 using content::BrowserContext; |
27 using content::WebContents; | 29 using content::WebContents; |
| 30 using testing::Return; |
28 | 31 |
29 namespace { | 32 namespace { |
30 | 33 |
31 const char kTestText[] = "abcd1234"; | 34 const char kTestText[] = "abcd1234"; |
32 | 35 |
33 class MockLogReceiver : public password_manager::LogReceiver { | 36 class MockLogReceiver : public password_manager::LogReceiver { |
34 public: | 37 public: |
35 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); | 38 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
36 }; | 39 }; |
37 | 40 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 GURL("https://accounts.google.com/ServiceLogin?continue=" | 325 GURL("https://accounts.google.com/ServiceLogin?continue=" |
323 "https://mail.google.com&rart=234")); | 326 "https://mail.google.com&rart=234")); |
324 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); | 327 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); |
325 | 328 |
326 // Reauth pages are only on accounts.google.com | 329 // Reauth pages are only on accounts.google.com |
327 NavigateAndCommit( | 330 NavigateAndCommit( |
328 GURL("https://other.site.com/ServiceLogin?continue=" | 331 GURL("https://other.site.com/ServiceLogin?continue=" |
329 "https://passwords.google.com&rart=234")); | 332 "https://passwords.google.com&rart=234")); |
330 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); | 333 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); |
331 } | 334 } |
| 335 |
| 336 TEST_F(ChromePasswordManagerClientTest, IsPasswordSyncEnabled) { |
| 337 ChromePasswordManagerClient* client = GetClient(); |
| 338 |
| 339 ProfileSyncServiceMock* mock_sync_service = |
| 340 static_cast<ProfileSyncServiceMock*>( |
| 341 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 342 profile(), ProfileSyncServiceMock::BuildMockProfileSyncService)); |
| 343 |
| 344 syncer::ModelTypeSet active_types; |
| 345 active_types.Put(syncer::PASSWORDS); |
| 346 EXPECT_CALL(*mock_sync_service, HasSyncSetupCompleted()) |
| 347 .WillRepeatedly(Return(true)); |
| 348 EXPECT_CALL(*mock_sync_service, SyncActive()).WillRepeatedly(Return(true)); |
| 349 EXPECT_CALL(*mock_sync_service, GetActiveDataTypes()) |
| 350 .WillRepeatedly(Return(active_types)); |
| 351 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
| 352 .WillRepeatedly(Return(false)); |
| 353 |
| 354 // Passwords are syncing and custom passphrase isn't used. |
| 355 EXPECT_FALSE( |
| 356 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); |
| 357 EXPECT_TRUE(client->IsPasswordSyncEnabled( |
| 358 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); |
| 359 |
| 360 // Again, using a custom passphrase. |
| 361 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
| 362 .WillRepeatedly(Return(true)); |
| 363 |
| 364 EXPECT_TRUE( |
| 365 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); |
| 366 EXPECT_FALSE(client->IsPasswordSyncEnabled( |
| 367 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); |
| 368 |
| 369 // Always return false if we aren't syncing passwords. |
| 370 active_types.Remove(syncer::PASSWORDS); |
| 371 active_types.Put(syncer::BOOKMARKS); |
| 372 EXPECT_CALL(*mock_sync_service, GetActiveDataTypes()) |
| 373 .WillRepeatedly(Return(active_types)); |
| 374 |
| 375 EXPECT_FALSE( |
| 376 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); |
| 377 EXPECT_FALSE(client->IsPasswordSyncEnabled( |
| 378 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); |
| 379 |
| 380 // Again, without a custom passphrase. |
| 381 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
| 382 .WillRepeatedly(Return(false)); |
| 383 |
| 384 EXPECT_FALSE( |
| 385 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); |
| 386 EXPECT_FALSE(client->IsPasswordSyncEnabled( |
| 387 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); |
| 388 } |
OLD | NEW |