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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/scoped_feature_list.h" | 16 #include "base/test/scoped_feature_list.h" |
| 17 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | |
| 17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 18 #include "chrome/browser/sync/profile_sync_test_util.h" | 19 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 19 #include "chrome/common/channel_info.h" | 20 #include "chrome/common/channel_info.h" |
| 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/autofill/content/common/autofill_messages.h" | 23 #include "components/autofill/content/common/autofill_messages.h" |
| 23 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" | 24 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" |
| 24 #include "components/password_manager/core/browser/credentials_filter.h" | 25 #include "components/password_manager/core/browser/credentials_filter.h" |
| 25 #include "components/password_manager/core/browser/log_manager.h" | 26 #include "components/password_manager/core/browser/log_manager.h" |
| 26 #include "components/password_manager/core/browser/log_receiver.h" | 27 #include "components/password_manager/core/browser/log_receiver.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile()); | 346 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile()); |
| 346 DummyLogReceiver log_receiver; | 347 DummyLogReceiver log_receiver; |
| 347 EXPECT_EQ(std::string(), log_router->RegisterReceiver(&log_receiver)); | 348 EXPECT_EQ(std::string(), log_router->RegisterReceiver(&log_receiver)); |
| 348 | 349 |
| 349 // But then navigate to a WebUI, there the logging should not be active. | 350 // But then navigate to a WebUI, there the logging should not be active. |
| 350 NavigateAndCommit(GURL("about:password-manager-internals")); | 351 NavigateAndCommit(GURL("about:password-manager-internals")); |
| 351 EXPECT_FALSE(GetClient()->GetLogManager()->IsLoggingActive()); | 352 EXPECT_FALSE(GetClient()->GetLogManager()->IsLoggingActive()); |
| 352 | 353 |
| 353 log_router->UnregisterReceiver(&log_receiver); | 354 log_router->UnregisterReceiver(&log_receiver); |
| 354 } | 355 } |
| 356 | |
| 357 TEST_F(ChromePasswordManagerClientTest, ShouldAnnotateNavigationEntry) { | |
| 358 ProfileSyncServiceMock* mock_sync_service = | |
| 359 static_cast<ProfileSyncServiceMock*>( | |
| 360 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 361 profile(), BuildMockProfileSyncService)); | |
| 362 | |
| 363 EXPECT_CALL(*mock_sync_service, IsFirstSetupComplete()) | |
| 364 .WillRepeatedly(Return(true)); | |
| 365 EXPECT_CALL(*mock_sync_service, IsSyncActive()).WillRepeatedly(Return(true)); | |
| 366 | |
| 367 // Connect our bool for testing. | |
| 368 bool metrics_enabled = false; | |
| 369 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting( | |
| 370 &metrics_enabled); | |
| 371 | |
| 372 // Metrics disabled w/ non-custom passphrase: do not annotate | |
| 373 metrics_enabled = false; | |
| 374 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | |
| 375 .WillRepeatedly(Return(false)); | |
| 376 EXPECT_FALSE( | |
| 377 ChromePasswordManagerClient::ShouldAnnotateNavigationEntries(profile())); | |
| 378 | |
| 379 // Metrics enabled w/ non-custom passphrase: do annotate | |
|
vabr (Chromium)
2016/09/02 09:12:20
Please split the 4 blocks at lines 373, 379, 386 a
Nathan Parker
2016/09/02 22:42:36
Done. And I split apart the new test I added.
| |
| 380 metrics_enabled = true; | |
| 381 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | |
| 382 .WillRepeatedly(Return(false)); | |
| 383 EXPECT_TRUE( | |
| 384 ChromePasswordManagerClient::ShouldAnnotateNavigationEntries(profile())); | |
| 385 | |
| 386 // Metrics enabled w/ custom passphrase: do not annotate | |
| 387 metrics_enabled = true; | |
| 388 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | |
| 389 .WillRepeatedly(Return(true)); | |
| 390 EXPECT_FALSE( | |
| 391 ChromePasswordManagerClient::ShouldAnnotateNavigationEntries(profile())); | |
| 392 | |
| 393 // Metrics disabled w/ custom passphrase: do not annotate | |
| 394 metrics_enabled = false; | |
| 395 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) | |
| 396 .WillRepeatedly(Return(true)); | |
| 397 EXPECT_FALSE( | |
| 398 ChromePasswordManagerClient::ShouldAnnotateNavigationEntries(profile())); | |
| 399 | |
| 400 // Disconnect our bool for testing. | |
| 401 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr); | |
| 402 } | |
| OLD | NEW |