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

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

Issue 1273053002: Use Smart Lock preference instead of Chrome Password manager preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@reconcile_yolo_settings
Patch Set: Use Smart Lock preference instead of Chrome Password manager preference. 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 ChromeRenderViewHostTestHarness::SetUp(); 193 ChromeRenderViewHostTestHarness::SetUp();
194 194
195 service_manager::InterfaceProvider* remote_interfaces = 195 service_manager::InterfaceProvider* remote_interfaces =
196 web_contents()->GetMainFrame()->GetRemoteInterfaces(); 196 web_contents()->GetMainFrame()->GetRemoteInterfaces();
197 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces); 197 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces);
198 test_api.SetBinderForName(autofill::mojom::PasswordAutofillAgent::Name_, 198 test_api.SetBinderForName(autofill::mojom::PasswordAutofillAgent::Name_,
199 base::Bind(&FakePasswordAutofillAgent::BindRequest, 199 base::Bind(&FakePasswordAutofillAgent::BindRequest,
200 base::Unretained(&fake_agent_))); 200 base::Unretained(&fake_agent_)));
201 201
202 prefs_.registry()->RegisterBooleanPref( 202 prefs_.registry()->RegisterBooleanPref(
203 password_manager::prefs::kPasswordManagerSavingEnabled, true); 203 password_manager::prefs::kCredentialsEnableService, true);
204 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( 204 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
205 web_contents(), nullptr); 205 web_contents(), nullptr);
206 206
207 // Connect our bool for testing. 207 // Connect our bool for testing.
208 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting( 208 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
209 &metrics_enabled_); 209 &metrics_enabled_);
210 } 210 }
211 211
212 void ChromePasswordManagerClientTest::TearDown() { 212 void ChromePasswordManagerClientTest::TearDown() {
213 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr); 213 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 319
320 profile()->ForceIncognito(false); 320 profile()->ForceIncognito(false);
321 EXPECT_FALSE(client->IsOffTheRecord()); 321 EXPECT_FALSE(client->IsOffTheRecord());
322 } 322 }
323 323
324 TEST_F(ChromePasswordManagerClientTest, 324 TEST_F(ChromePasswordManagerClientTest,
325 SavingDependsOnManagerEnabledPreference) { 325 SavingDependsOnManagerEnabledPreference) {
326 // Test that saving passwords depends on the password manager enabled 326 // Test that saving passwords depends on the password manager enabled
327 // preference. 327 // preference.
328 ChromePasswordManagerClient* client = GetClient(); 328 ChromePasswordManagerClient* client = GetClient();
329 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 329 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
330 new base::FundamentalValue(true)); 330 new base::FundamentalValue(true));
331 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); 331 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage());
332 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 332 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
333 new base::FundamentalValue(false)); 333 new base::FundamentalValue(false));
334 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 334 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
335 } 335 }
336 336
337 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) { 337 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) {
338 std::unique_ptr<WebContents> test_web_contents( 338 std::unique_ptr<WebContents> test_web_contents(
339 content::WebContentsTester::CreateTestWebContents( 339 content::WebContentsTester::CreateTestWebContents(
340 web_contents()->GetBrowserContext(), nullptr)); 340 web_contents()->GetBrowserContext(), nullptr));
341 std::unique_ptr<MockChromePasswordManagerClient> client( 341 std::unique_ptr<MockChromePasswordManagerClient> client(
342 new MockChromePasswordManagerClient(test_web_contents.get())); 342 new MockChromePasswordManagerClient(test_web_contents.get()));
343 // Functionality disabled if there is SSL errors. 343 // Functionality disabled if there is SSL errors.
344 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) 344 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors())
345 .WillRepeatedly(Return(true)); 345 .WillRepeatedly(Return(true));
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 SSL errors and the manager itself is 349 // Functionality disabled if there are SSL errors and the manager itself is
350 // disabled. 350 // disabled.
351 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 351 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
352 new base::FundamentalValue(false)); 352 new base::FundamentalValue(false));
353 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 353 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
354 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); 354 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage());
355 355
356 // Functionality disabled if there are no SSL errors, but the manager itself 356 // Functionality disabled if there are no SSL errors, but the manager itself
357 // is disabled. 357 // is disabled.
358 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) 358 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors())
359 .WillRepeatedly(Return(false)); 359 .WillRepeatedly(Return(false));
360 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 360 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
361 new base::FundamentalValue(false)); 361 new base::FundamentalValue(false));
362 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 362 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
363 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); 363 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
364 364
365 // Functionality enabled if there are no SSL errors and the manager is 365 // Functionality enabled if there are no SSL errors and the manager is
366 // enabled. 366 // enabled.
367 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) 367 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors())
368 .WillRepeatedly(Return(false)); 368 .WillRepeatedly(Return(false));
369 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 369 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
370 new base::FundamentalValue(true)); 370 new base::FundamentalValue(true));
371 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); 371 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage());
372 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); 372 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
373 373
374 // Functionality disabled in Incognito mode. 374 // Functionality disabled in Incognito mode.
375 profile()->ForceIncognito(true); 375 profile()->ForceIncognito(true);
376 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 376 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
377 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); 377 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
378 378
379 // Functionality disabled in Incognito mode also when manager itself is 379 // Functionality disabled in Incognito mode also when manager itself is
380 // enabled. 380 // enabled.
381 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, 381 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService,
382 new base::FundamentalValue(true)); 382 new base::FundamentalValue(true));
383 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); 383 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage());
384 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); 384 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage());
385 profile()->ForceIncognito(false); 385 profile()->ForceIncognito(false);
386 } 386 }
387 387
388 TEST_F(ChromePasswordManagerClientTest, GetLastCommittedEntryURL_Empty) { 388 TEST_F(ChromePasswordManagerClientTest, GetLastCommittedEntryURL_Empty) {
389 EXPECT_EQ(GURL::EmptyGURL(), GetClient()->GetLastCommittedEntryURL()); 389 EXPECT_EQ(GURL::EmptyGURL(), GetClient()->GetLastCommittedEntryURL());
390 } 390 }
391 391
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 }; 560 };
561 561
562 for (const TestCase& test_case : kTestCases) { 562 for (const TestCase& test_case : kTestCases) {
563 // CanShowBubbleOnURL currently only depends on the scheme. 563 // CanShowBubbleOnURL currently only depends on the scheme.
564 GURL url(base::StringPrintf("%s://example.org", test_case.scheme)); 564 GURL url(base::StringPrintf("%s://example.org", test_case.scheme));
565 SCOPED_TRACE(url.possibly_invalid_spec()); 565 SCOPED_TRACE(url.possibly_invalid_spec());
566 EXPECT_EQ(test_case.can_show_bubble, 566 EXPECT_EQ(test_case.can_show_bubble,
567 ChromePasswordManagerClient::CanShowBubbleOnURL(url)); 567 ChromePasswordManagerClient::CanShowBubbleOnURL(url));
568 } 568 }
569 } 569 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698