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 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 19 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
20 #include "chrome/browser/sync/profile_sync_test_util.h" | 21 #include "chrome/browser/sync/profile_sync_test_util.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 profile()->ForceIncognito(false); | 301 profile()->ForceIncognito(false); |
301 EXPECT_FALSE(client->IsOffTheRecord()); | 302 EXPECT_FALSE(client->IsOffTheRecord()); |
302 } | 303 } |
303 | 304 |
304 TEST_F(ChromePasswordManagerClientTest, | 305 TEST_F(ChromePasswordManagerClientTest, |
305 SavingDependsOnManagerEnabledPreference) { | 306 SavingDependsOnManagerEnabledPreference) { |
306 // Test that saving passwords depends on the password manager enabled | 307 // Test that saving passwords depends on the password manager enabled |
307 // preference. | 308 // preference. |
308 ChromePasswordManagerClient* client = GetClient(); | 309 ChromePasswordManagerClient* client = GetClient(); |
309 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, | 310 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, |
310 new base::Value(true)); | 311 base::MakeUnique<base::Value>(true)); |
311 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); | 312 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); |
312 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, | 313 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, |
313 new base::Value(false)); | 314 base::MakeUnique<base::Value>(false)); |
314 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); | 315 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); |
315 } | 316 } |
316 | 317 |
317 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) { | 318 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) { |
318 std::unique_ptr<WebContents> test_web_contents( | 319 std::unique_ptr<WebContents> test_web_contents( |
319 content::WebContentsTester::CreateTestWebContents( | 320 content::WebContentsTester::CreateTestWebContents( |
320 web_contents()->GetBrowserContext(), nullptr)); | 321 web_contents()->GetBrowserContext(), nullptr)); |
321 std::unique_ptr<MockChromePasswordManagerClient> client( | 322 std::unique_ptr<MockChromePasswordManagerClient> client( |
322 new MockChromePasswordManagerClient(test_web_contents.get())); | 323 new MockChromePasswordManagerClient(test_web_contents.get())); |
323 // Functionality disabled if there is SSL errors. | 324 // Functionality disabled if there is SSL errors. |
324 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) | 325 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) |
325 .WillRepeatedly(Return(true)); | 326 .WillRepeatedly(Return(true)); |
326 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); | 327 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); |
327 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); | 328 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); |
328 | 329 |
329 // Functionality disabled if there are SSL errors and the manager itself is | 330 // Functionality disabled if there are SSL errors and the manager itself is |
330 // disabled. | 331 // disabled. |
331 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, | 332 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, |
332 new base::Value(false)); | 333 base::MakeUnique<base::Value>(false)); |
333 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); | 334 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); |
334 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); | 335 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); |
335 | 336 |
336 // Functionality disabled if there are no SSL errors, but the manager itself | 337 // Functionality disabled if there are no SSL errors, but the manager itself |
337 // is disabled. | 338 // is disabled. |
338 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) | 339 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) |
339 .WillRepeatedly(Return(false)); | 340 .WillRepeatedly(Return(false)); |
340 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, | 341 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, |
341 new base::Value(false)); | 342 base::MakeUnique<base::Value>(false)); |
342 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); | 343 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); |
343 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); | 344 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); |
344 | 345 |
345 // Functionality enabled if there are no SSL errors and the manager is | 346 // Functionality enabled if there are no SSL errors and the manager is |
346 // enabled. | 347 // enabled. |
347 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) | 348 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) |
348 .WillRepeatedly(Return(false)); | 349 .WillRepeatedly(Return(false)); |
349 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, | 350 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, |
350 new base::Value(true)); | 351 base::MakeUnique<base::Value>(true)); |
351 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); | 352 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); |
352 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); | 353 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); |
353 | 354 |
354 // Functionality disabled in Incognito mode. | 355 // Functionality disabled in Incognito mode. |
355 profile()->ForceIncognito(true); | 356 profile()->ForceIncognito(true); |
356 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); | 357 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); |
357 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); | 358 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); |
358 | 359 |
359 // Functionality disabled in Incognito mode also when manager itself is | 360 // Functionality disabled in Incognito mode also when manager itself is |
360 // enabled. | 361 // enabled. |
361 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, | 362 prefs()->SetUserPref(password_manager::prefs::kCredentialsEnableService, |
362 new base::Value(true)); | 363 base::MakeUnique<base::Value>(true)); |
363 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); | 364 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); |
364 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); | 365 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); |
365 profile()->ForceIncognito(false); | 366 profile()->ForceIncognito(false); |
366 } | 367 } |
367 | 368 |
368 TEST_F(ChromePasswordManagerClientTest, SavingDependsOnAutomation) { | 369 TEST_F(ChromePasswordManagerClientTest, SavingDependsOnAutomation) { |
369 // Test that saving passwords UI is disabled for automated tests. | 370 // Test that saving passwords UI is disabled for automated tests. |
370 ChromePasswordManagerClient* client = GetClient(); | 371 ChromePasswordManagerClient* client = GetClient(); |
371 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); | 372 EXPECT_TRUE(client->IsSavingAndFillingEnabledForCurrentPage()); |
372 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 373 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 }; | 550 }; |
550 | 551 |
551 for (const TestCase& test_case : kTestCases) { | 552 for (const TestCase& test_case : kTestCases) { |
552 // CanShowBubbleOnURL currently only depends on the scheme. | 553 // CanShowBubbleOnURL currently only depends on the scheme. |
553 GURL url(base::StringPrintf("%s://example.org", test_case.scheme)); | 554 GURL url(base::StringPrintf("%s://example.org", test_case.scheme)); |
554 SCOPED_TRACE(url.possibly_invalid_spec()); | 555 SCOPED_TRACE(url.possibly_invalid_spec()); |
555 EXPECT_EQ(test_case.can_show_bubble, | 556 EXPECT_EQ(test_case.can_show_bubble, |
556 ChromePasswordManagerClient::CanShowBubbleOnURL(url)); | 557 ChromePasswordManagerClient::CanShowBubbleOnURL(url)); |
557 } | 558 } |
558 } | 559 } |
OLD | NEW |