Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: chrome/browser/password_manager/chrome_password_manager_client_unittest.cc

Issue 644053003: [Password Manager] Add UMA stats for custom passphrase users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 GURL("https://accounts.google.com/ServiceLogin?continue=" 326 GURL("https://accounts.google.com/ServiceLogin?continue="
324 "https://mail.google.com&rart=234")); 327 "https://mail.google.com&rart=234"));
325 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); 328 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage());
326 329
327 // Reauth pages are only on accounts.google.com 330 // Reauth pages are only on accounts.google.com
328 NavigateAndCommit( 331 NavigateAndCommit(
329 GURL("https://other.site.com/ServiceLogin?continue=" 332 GURL("https://other.site.com/ServiceLogin?continue="
330 "https://passwords.google.com&rart=234")); 333 "https://passwords.google.com&rart=234"));
331 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); 334 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage());
332 } 335 }
336
337 TEST_F(ChromePasswordManagerClientTest, IsPasswordSyncEnabled) {
338 ChromePasswordManagerClient* client = GetClient();
339
340 ProfileSyncServiceMock* mock_sync_service =
341 static_cast<ProfileSyncServiceMock*>(
342 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
343 profile(), ProfileSyncServiceMock::BuildMockProfileSyncService));
344
345 syncer::ModelTypeSet active_types;
346 active_types.Put(syncer::PASSWORDS);
347 EXPECT_CALL(*mock_sync_service, HasSyncSetupCompleted())
348 .WillRepeatedly(Return(true));
349 EXPECT_CALL(*mock_sync_service, sync_initialized())
350 .WillRepeatedly(Return(true));
351 EXPECT_CALL(*mock_sync_service, GetActiveDataTypes())
352 .WillRepeatedly(Return(active_types));
353 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
354 .WillRepeatedly(Return(false));
355
356 // Passwords are syncing and custom passphrase isn't used.
357 EXPECT_FALSE(client->IsPasswordSyncEnabled(
358 password_manager::ONLY_CUSTOM_PASSPHRASE_USERS));
359 EXPECT_TRUE(client->IsPasswordSyncEnabled(
360 password_manager::EXCLUDE_CUSTOM_PASSPHRASE_USERS));
361
362 // Again, using a custom passphrase.
363 EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
364 .WillRepeatedly(Return(true));
365
366 EXPECT_TRUE(client->IsPasswordSyncEnabled(
367 password_manager::ONLY_CUSTOM_PASSPHRASE_USERS));
368 EXPECT_FALSE(client->IsPasswordSyncEnabled(
369 password_manager::EXCLUDE_CUSTOM_PASSPHRASE_USERS));
370
371 // Always return false if we aren't syncing passwords.
372 active_types.Remove(syncer::PASSWORDS);
373 active_types.Put(syncer::BOOKMARKS);
374 EXPECT_CALL(*mock_sync_service, GetActiveDataTypes())
375 .WillRepeatedly(Return(active_types));
376
377 EXPECT_FALSE(client->IsPasswordSyncEnabled(
vabr (Chromium) 2014/10/13 09:24:18 Should you also mock the two possible values of Is
Garrett Casto 2014/10/13 20:57:56 Sure, done.
378 password_manager::ONLY_CUSTOM_PASSPHRASE_USERS));
379 EXPECT_FALSE(client->IsPasswordSyncEnabled(
380 password_manager::EXCLUDE_CUSTOM_PASSPHRASE_USERS));
381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698