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/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 "https://mail.google.com&rart=234")); | 350 "https://mail.google.com&rart=234")); |
351 EXPECT_TRUE(client->IsPasswordManagementEnabledForCurrentPage()); | 351 EXPECT_TRUE(client->IsPasswordManagementEnabledForCurrentPage()); |
352 | 352 |
353 // Reauth pages are only on accounts.google.com | 353 // Reauth pages are only on accounts.google.com |
354 NavigateAndCommit( | 354 NavigateAndCommit( |
355 GURL("https://other.site.com/ServiceLogin?continue=" | 355 GURL("https://other.site.com/ServiceLogin?continue=" |
356 "https://passwords.google.com&rart=234")); | 356 "https://passwords.google.com&rart=234")); |
357 EXPECT_TRUE(client->IsPasswordManagementEnabledForCurrentPage()); | 357 EXPECT_TRUE(client->IsPasswordManagementEnabledForCurrentPage()); |
358 } | 358 } |
359 | 359 |
360 TEST_F(ChromePasswordManagerClientTest, IsPasswordSyncEnabled) { | 360 TEST_F(ChromePasswordManagerClientTest, GetPasswordSyncState) { |
361 ChromePasswordManagerClient* client = GetClient(); | 361 ChromePasswordManagerClient* client = GetClient(); |
362 | 362 |
363 ProfileSyncServiceMock* mock_sync_service = | 363 ProfileSyncServiceMock* mock_sync_service = |
364 static_cast<ProfileSyncServiceMock*>( | 364 static_cast<ProfileSyncServiceMock*>( |
365 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 365 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
366 profile(), ProfileSyncServiceMock::BuildMockProfileSyncService)); | 366 profile(), ProfileSyncServiceMock::BuildMockProfileSyncService)); |
367 | 367 |
368 syncer::ModelTypeSet active_types; | 368 syncer::ModelTypeSet active_types; |
369 active_types.Put(syncer::PASSWORDS); | 369 active_types.Put(syncer::PASSWORDS); |
370 EXPECT_CALL(*mock_sync_service, HasSyncSetupCompleted()) | 370 EXPECT_CALL(*mock_sync_service, HasSyncSetupCompleted()) |
371 .WillRepeatedly(Return(true)); | 371 .WillRepeatedly(Return(true)); |
372 EXPECT_CALL(*mock_sync_service, SyncActive()).WillRepeatedly(Return(true)); | 372 EXPECT_CALL(*mock_sync_service, SyncActive()).WillRepeatedly(Return(true)); |
373 EXPECT_CALL(*mock_sync_service, GetActiveDataTypes()) | 373 EXPECT_CALL(*mock_sync_service, GetActiveDataTypes()) |
374 .WillRepeatedly(Return(active_types)); | 374 .WillRepeatedly(Return(active_types)); |
375 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | 375 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
376 .WillRepeatedly(Return(false)); | 376 .WillRepeatedly(Return(false)); |
377 | 377 |
378 // Passwords are syncing and custom passphrase isn't used. | 378 // Passwords are syncing and custom passphrase isn't used. |
379 EXPECT_FALSE( | 379 EXPECT_EQ(password_manager::SYNCING_NORMAL_ENCRYPTION, |
380 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); | 380 client->GetPasswordSyncState()); |
381 EXPECT_TRUE(client->IsPasswordSyncEnabled( | |
382 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); | |
383 | 381 |
384 // Again, using a custom passphrase. | 382 // Again, using a custom passphrase. |
385 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | 383 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
386 .WillRepeatedly(Return(true)); | 384 .WillRepeatedly(Return(true)); |
387 | 385 |
388 EXPECT_TRUE( | 386 EXPECT_EQ(password_manager::SYNCING_WITH_CUSTOM_PASSPHRASE, |
389 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); | 387 client->GetPasswordSyncState()); |
390 EXPECT_FALSE(client->IsPasswordSyncEnabled( | |
391 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); | |
392 | 388 |
393 // Always return false if we aren't syncing passwords. | 389 // Report correctly if we aren't syncing passwords. |
394 active_types.Remove(syncer::PASSWORDS); | 390 active_types.Remove(syncer::PASSWORDS); |
395 active_types.Put(syncer::BOOKMARKS); | 391 active_types.Put(syncer::BOOKMARKS); |
396 EXPECT_CALL(*mock_sync_service, GetActiveDataTypes()) | 392 EXPECT_CALL(*mock_sync_service, GetActiveDataTypes()) |
397 .WillRepeatedly(Return(active_types)); | 393 .WillRepeatedly(Return(active_types)); |
398 | 394 |
399 EXPECT_FALSE( | 395 EXPECT_EQ(password_manager::NOT_SYNCING_PASSWORDS, |
400 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); | 396 client->GetPasswordSyncState()); |
401 EXPECT_FALSE(client->IsPasswordSyncEnabled( | |
402 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); | |
403 | 397 |
404 // Again, without a custom passphrase. | 398 // Again, without a custom passphrase. |
405 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | 399 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) |
406 .WillRepeatedly(Return(false)); | 400 .WillRepeatedly(Return(false)); |
407 | 401 |
408 EXPECT_FALSE( | 402 EXPECT_EQ(password_manager::NOT_SYNCING_PASSWORDS, |
409 client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); | 403 client->GetPasswordSyncState()); |
410 EXPECT_FALSE(client->IsPasswordSyncEnabled( | |
411 password_manager::WITHOUT_CUSTOM_PASSPHRASE)); | |
412 } | 404 } |
413 | 405 |
414 TEST_F(ChromePasswordManagerClientTest, IsOffTheRecordTest) { | 406 TEST_F(ChromePasswordManagerClientTest, IsOffTheRecordTest) { |
415 ChromePasswordManagerClient* client = GetClient(); | 407 ChromePasswordManagerClient* client = GetClient(); |
416 | 408 |
417 profile()->ForceIncognito(true); | 409 profile()->ForceIncognito(true); |
418 EXPECT_TRUE(client->IsOffTheRecord()); | 410 EXPECT_TRUE(client->IsOffTheRecord()); |
419 | 411 |
420 profile()->ForceIncognito(false); | 412 profile()->ForceIncognito(false); |
421 EXPECT_FALSE(client->IsOffTheRecord()); | 413 EXPECT_FALSE(client->IsOffTheRecord()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 profile()->ForceIncognito(true); | 460 profile()->ForceIncognito(true); |
469 EXPECT_FALSE(client->IsSavingEnabledForCurrentPage()); | 461 EXPECT_FALSE(client->IsSavingEnabledForCurrentPage()); |
470 | 462 |
471 // Functionality disabled in Incognito mode also when manager itself is | 463 // Functionality disabled in Incognito mode also when manager itself is |
472 // enabled. | 464 // enabled. |
473 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, | 465 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, |
474 new base::FundamentalValue(true)); | 466 new base::FundamentalValue(true)); |
475 EXPECT_FALSE(client->IsSavingEnabledForCurrentPage()); | 467 EXPECT_FALSE(client->IsSavingEnabledForCurrentPage()); |
476 profile()->ForceIncognito(false); | 468 profile()->ForceIncognito(false); |
477 } | 469 } |
OLD | NEW |