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

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

Issue 2472363002: Remove experiment support for PasswordManagerSettingsBehaviourChange (Closed)
Patch Set: Fix punctuation Created 4 years, 1 month 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 using browser_sync::ProfileSyncServiceMock; 48 using browser_sync::ProfileSyncServiceMock;
49 using content::BrowserContext; 49 using content::BrowserContext;
50 using content::WebContents; 50 using content::WebContents;
51 using sessions::GetPasswordStateFromNavigation; 51 using sessions::GetPasswordStateFromNavigation;
52 using sessions::SerializedNavigationEntry; 52 using sessions::SerializedNavigationEntry;
53 using testing::Return; 53 using testing::Return;
54 using testing::_; 54 using testing::_;
55 55
56 namespace { 56 namespace {
57 57
58 const char kPasswordManagerSettingsBehaviourChangeFieldTrialName[] =
59 "PasswordManagerSettingsBehaviourChange";
60 const char kPasswordManagerSettingsBehaviourChangeEnabledGroupName[] =
61 "PasswordManagerSettingsBehaviourChange.Active";
62 const char kPasswordManagerSettingsBehaviourChangeDisabledGroupName[] =
63 "PasswordManagerSettingsBehaviourChange.NotActive";
64
65 // TODO(vabr): Get rid of the mocked client in the client's own test, see 58 // TODO(vabr): Get rid of the mocked client in the client's own test, see
66 // http://crbug.com/474577. 59 // http://crbug.com/474577.
67 class MockChromePasswordManagerClient : public ChromePasswordManagerClient { 60 class MockChromePasswordManagerClient : public ChromePasswordManagerClient {
68 public: 61 public:
69 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); 62 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
70 63
71 explicit MockChromePasswordManagerClient(content::WebContents* web_contents) 64 explicit MockChromePasswordManagerClient(content::WebContents* web_contents)
72 : ChromePasswordManagerClient(web_contents, nullptr) { 65 : ChromePasswordManagerClient(web_contents, nullptr) {
73 ON_CALL(*this, DidLastPageLoadEncounterSSLErrors()) 66 ON_CALL(*this, DidLastPageLoadEncounterSSLErrors())
74 .WillByDefault(testing::Return(false)); 67 .WillByDefault(testing::Return(false));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 public: 137 public:
145 ChromePasswordManagerClientTest() 138 ChromePasswordManagerClientTest()
146 : field_trial_list_(nullptr), metrics_enabled_(false) {} 139 : field_trial_list_(nullptr), metrics_enabled_(false) {}
147 void SetUp() override; 140 void SetUp() override;
148 void TearDown() override; 141 void TearDown() override;
149 142
150 sync_preferences::TestingPrefServiceSyncable* prefs() { 143 sync_preferences::TestingPrefServiceSyncable* prefs() {
151 return profile()->GetTestingPrefService(); 144 return profile()->GetTestingPrefService();
152 } 145 }
153 146
154 void EnforcePasswordManagerSettingsBehaviourChangeExperimentGroup(
155 const char* name) {
156 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
157 kPasswordManagerSettingsBehaviourChangeFieldTrialName, name));
158 }
159
160 // Caller does not own the returned pointer. 147 // Caller does not own the returned pointer.
161 ProfileSyncServiceMock* SetupBasicMockSync() { 148 ProfileSyncServiceMock* SetupBasicMockSync() {
162 ProfileSyncServiceMock* mock_sync_service = 149 ProfileSyncServiceMock* mock_sync_service =
163 static_cast<ProfileSyncServiceMock*>( 150 static_cast<ProfileSyncServiceMock*>(
164 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 151 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
165 profile(), BuildMockProfileSyncService)); 152 profile(), BuildMockProfileSyncService));
166 153
167 EXPECT_CALL(*mock_sync_service, IsFirstSetupComplete()) 154 EXPECT_CALL(*mock_sync_service, IsFirstSetupComplete())
168 .WillRepeatedly(Return(true)); 155 .WillRepeatedly(Return(true));
169 EXPECT_CALL(*mock_sync_service, IsSyncActive()) 156 EXPECT_CALL(*mock_sync_service, IsSyncActive())
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // preference. 320 // preference.
334 ChromePasswordManagerClient* client = GetClient(); 321 ChromePasswordManagerClient* client = GetClient();
335 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 322 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled,
336 new base::FundamentalValue(true)); 323 new base::FundamentalValue(true));
337 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); 324 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage());
338 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 325 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled,
339 new base::FundamentalValue(false)); 326 new base::FundamentalValue(false));
340 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 327 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
341 } 328 }
342 329
343 TEST_F(ChromePasswordManagerClientTest,
344 FillingDependsOnManagerEnabledPreferenceAndExperimentEnabled) {
345 // Test that filing of passwords depends on the password manager enabled
346 // preference and is the user participated in behavior change experiment.
347 ChromePasswordManagerClient* client = GetClient();
348 EnforcePasswordManagerSettingsBehaviourChangeExperimentGroup(
349 kPasswordManagerSettingsBehaviourChangeEnabledGroupName);
350 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled,
351 new base::FundamentalValue(true));
352 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage());
353 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
354 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled,
355 new base::FundamentalValue(false));
356 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
357 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage());
358 }
359
360 TEST_F(ChromePasswordManagerClientTest,
361 FillingDependsOnManagerEnabledPreferenceAndExperimentDisabled) {
362 // Test that filing of passwords depends on the password manager enabled
363 // preference and is the user participated in behavior change experiment.
364 ChromePasswordManagerClient* client = GetClient();
365 EnforcePasswordManagerSettingsBehaviourChangeExperimentGroup(
366 kPasswordManagerSettingsBehaviourChangeDisabledGroupName);
367 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled,
368 new base::FundamentalValue(true));
369 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
370 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled,
371 new base::FundamentalValue(false));
372 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
373 }
374
375 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) { 330 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) {
376 std::unique_ptr<WebContents> test_web_contents( 331 std::unique_ptr<WebContents> test_web_contents(
377 content::WebContentsTester::CreateTestWebContents( 332 content::WebContentsTester::CreateTestWebContents(
378 web_contents()->GetBrowserContext(), nullptr)); 333 web_contents()->GetBrowserContext(), nullptr));
379 std::unique_ptr<MockChromePasswordManagerClient> client( 334 std::unique_ptr<MockChromePasswordManagerClient> client(
380 new MockChromePasswordManagerClient(test_web_contents.get())); 335 new MockChromePasswordManagerClient(test_web_contents.get()));
381 // Functionality disabled if there is SSL errors. 336 // Functionality disabled if there is SSL errors.
382 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) 337 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors())
383 .WillRepeatedly(Return(true)); 338 .WillRepeatedly(Return(true));
384 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 339 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // In particular, this WebContent should not have the 519 // In particular, this WebContent should not have the
565 // ChromePasswordManagerClient. 520 // ChromePasswordManagerClient.
566 ASSERT_FALSE( 521 ASSERT_FALSE(
567 ChromePasswordManagerClient::FromWebContents(web_contents.get())); 522 ChromePasswordManagerClient::FromWebContents(web_contents.get()));
568 523
569 // This call should not crash. 524 // This call should not crash.
570 ChromePasswordManagerClient::BindCredentialManager( 525 ChromePasswordManagerClient::BindCredentialManager(
571 web_contents->GetMainFrame(), 526 web_contents->GetMainFrame(),
572 password_manager::mojom::CredentialManagerRequest()); 527 password_manager::mojom::CredentialManagerRequest());
573 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698