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

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

Issue 2693373004: Use Smart Lock preference instead of Chrome Password manager preference. (Closed)
Patch Set: Created 3 years, 10 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 ChromeRenderViewHostTestHarness::SetUp(); 186 ChromeRenderViewHostTestHarness::SetUp();
187 187
188 service_manager::InterfaceProvider* remote_interfaces = 188 service_manager::InterfaceProvider* remote_interfaces =
189 web_contents()->GetMainFrame()->GetRemoteInterfaces(); 189 web_contents()->GetMainFrame()->GetRemoteInterfaces();
190 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces); 190 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces);
191 test_api.SetBinderForName(autofill::mojom::PasswordAutofillAgent::Name_, 191 test_api.SetBinderForName(autofill::mojom::PasswordAutofillAgent::Name_,
192 base::Bind(&FakePasswordAutofillAgent::BindRequest, 192 base::Bind(&FakePasswordAutofillAgent::BindRequest,
193 base::Unretained(&fake_agent_))); 193 base::Unretained(&fake_agent_)));
194 194
195 prefs_.registry()->RegisterBooleanPref( 195 prefs_.registry()->RegisterBooleanPref(
196 password_manager::prefs::kPasswordManagerSavingEnabled, true); 196 password_manager::prefs::kCredentialsEnableService, true);
197 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( 197 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
198 web_contents(), nullptr); 198 web_contents(), nullptr);
199 199
200 // Connect our bool for testing. 200 // Connect our bool for testing.
201 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting( 201 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
202 &metrics_enabled_); 202 &metrics_enabled_);
203 } 203 }
204 204
205 void ChromePasswordManagerClientTest::TearDown() { 205 void ChromePasswordManagerClientTest::TearDown() {
206 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr); 206 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 312
313 profile()->ForceIncognito(false); 313 profile()->ForceIncognito(false);
314 EXPECT_FALSE(client->IsOffTheRecord()); 314 EXPECT_FALSE(client->IsOffTheRecord());
315 } 315 }
316 316
317 TEST_F(ChromePasswordManagerClientTest, 317 TEST_F(ChromePasswordManagerClientTest,
318 SavingDependsOnManagerEnabledPreference) { 318 SavingDependsOnManagerEnabledPreference) {
319 // Test that saving passwords depends on the password manager enabled 319 // Test that saving passwords depends on the password manager enabled
320 // preference. 320 // preference.
321 ChromePasswordManagerClient* client = GetClient(); 321 ChromePasswordManagerClient* client = GetClient();
322 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 322 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
323 new base::FundamentalValue(true)); 323 new base::FundamentalValue(true));
324 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); 324 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage());
325 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 325 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
326 new base::FundamentalValue(false)); 326 new base::FundamentalValue(false));
327 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 327 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
328 } 328 }
329 329
330 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) { 330 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) {
331 std::unique_ptr<WebContents> test_web_contents( 331 std::unique_ptr<WebContents> test_web_contents(
332 content::WebContentsTester::CreateTestWebContents( 332 content::WebContentsTester::CreateTestWebContents(
333 web_contents()->GetBrowserContext(), nullptr)); 333 web_contents()->GetBrowserContext(), nullptr));
334 std::unique_ptr<MockChromePasswordManagerClient> client( 334 std::unique_ptr<MockChromePasswordManagerClient> client(
335 new MockChromePasswordManagerClient(test_web_contents.get())); 335 new MockChromePasswordManagerClient(test_web_contents.get()));
336 // Functionality disabled if there is SSL errors. 336 // Functionality disabled if there is SSL errors.
337 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) 337 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors())
338 .WillRepeatedly(Return(true)); 338 .WillRepeatedly(Return(true));
339 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 339 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
340 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); 340 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage());
341 341
342 // Functionality disabled if there are SSL errors and the manager itself is 342 // Functionality disabled if there are SSL errors and the manager itself is
343 // disabled. 343 // disabled.
344 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 344 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
345 new base::FundamentalValue(false)); 345 new base::FundamentalValue(false));
346 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 346 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
347 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); 347 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage());
348 348
349 // Functionality disabled if there are no SSL errors, but the manager itself 349 // Functionality disabled if there are no SSL errors, but the manager itself
350 // is disabled. 350 // is disabled.
351 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) 351 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors())
352 .WillRepeatedly(Return(false)); 352 .WillRepeatedly(Return(false));
353 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 353 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
354 new base::FundamentalValue(false)); 354 new base::FundamentalValue(false));
355 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 355 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
356 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); 356 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
357 357
358 // Functionality enabled if there are no SSL errors and the manager is 358 // Functionality enabled if there are no SSL errors and the manager is
359 // enabled. 359 // enabled.
360 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) 360 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors())
361 .WillRepeatedly(Return(false)); 361 .WillRepeatedly(Return(false));
362 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 362 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
363 new base::FundamentalValue(true)); 363 new base::FundamentalValue(true));
364 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); 364 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage());
365 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); 365 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
366 366
367 // Functionality disabled in Incognito mode. 367 // Functionality disabled in Incognito mode.
368 profile()->ForceIncognito(true); 368 profile()->ForceIncognito(true);
369 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 369 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
370 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); 370 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
371 371
372 // Functionality disabled in Incognito mode also when manager itself is 372 // Functionality disabled in Incognito mode also when manager itself is
373 // enabled. 373 // enabled.
374 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 374 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
375 new base::FundamentalValue(true)); 375 new base::FundamentalValue(true));
376 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 376 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
377 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); 377 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
378 profile()->ForceIncognito(false); 378 profile()->ForceIncognito(false);
379 } 379 }
380 380
381 TEST_F(ChromePasswordManagerClientTest, GetLastCommittedEntryURL_Empty) { 381 TEST_F(ChromePasswordManagerClientTest, GetLastCommittedEntryURL_Empty) {
382 EXPECT_EQ(GURL::EmptyGURL(), GetClient()->GetLastCommittedEntryURL()); 382 EXPECT_EQ(GURL::EmptyGURL(), GetClient()->GetLastCommittedEntryURL());
383 } 383 }
384 384
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 // In particular, this WebContent should not have the 519 // In particular, this WebContent should not have the
520 // ChromePasswordManagerClient. 520 // ChromePasswordManagerClient.
521 ASSERT_FALSE( 521 ASSERT_FALSE(
522 ChromePasswordManagerClient::FromWebContents(web_contents.get())); 522 ChromePasswordManagerClient::FromWebContents(web_contents.get()));
523 523
524 // This call should not crash. 524 // This call should not crash.
525 ChromePasswordManagerClient::BindCredentialManager( 525 ChromePasswordManagerClient::BindCredentialManager(
526 web_contents->GetMainFrame(), 526 web_contents->GetMainFrame(),
527 password_manager::mojom::CredentialManagerRequest()); 527 password_manager::mojom::CredentialManagerRequest());
528 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698