| 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 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "components/password_manager/core/common/password_manager_features.h" | 32 #include "components/password_manager/core/common/password_manager_features.h" |
| 33 #include "components/password_manager/core/common/password_manager_pref_names.h" | 33 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 34 #include "components/prefs/pref_registry_simple.h" | 34 #include "components/prefs/pref_registry_simple.h" |
| 35 #include "components/prefs/pref_service.h" | 35 #include "components/prefs/pref_service.h" |
| 36 #include "components/prefs/testing_pref_service.h" | 36 #include "components/prefs/testing_pref_service.h" |
| 37 #include "components/sessions/content/content_record_password_state.h" | 37 #include "components/sessions/content/content_record_password_state.h" |
| 38 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 38 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 39 #include "components/version_info/version_info.h" | 39 #include "components/version_info/version_info.h" |
| 40 #include "content/public/browser/browser_context.h" | 40 #include "content/public/browser/browser_context.h" |
| 41 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 42 #include "content/public/test/web_contents_tester.h" |
| 42 #include "mojo/public/cpp/bindings/binding.h" | 43 #include "mojo/public/cpp/bindings/binding.h" |
| 43 #include "services/shell/public/cpp/interface_provider.h" | 44 #include "services/shell/public/cpp/interface_provider.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 46 | 47 |
| 47 using browser_sync::ProfileSyncServiceMock; | 48 using browser_sync::ProfileSyncServiceMock; |
| 48 using content::BrowserContext; | 49 using content::BrowserContext; |
| 49 using content::WebContents; | 50 using content::WebContents; |
| 50 using sessions::GetPasswordStateFromNavigation; | 51 using sessions::GetPasswordStateFromNavigation; |
| 51 using sessions::SerializedNavigationEntry; | 52 using sessions::SerializedNavigationEntry; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 kPasswordManagerSettingsBehaviourChangeDisabledGroupName); | 366 kPasswordManagerSettingsBehaviourChangeDisabledGroupName); |
| 366 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, | 367 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, |
| 367 new base::FundamentalValue(true)); | 368 new base::FundamentalValue(true)); |
| 368 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); | 369 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); |
| 369 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, | 370 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, |
| 370 new base::FundamentalValue(false)); | 371 new base::FundamentalValue(false)); |
| 371 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); | 372 EXPECT_TRUE(client->IsFillingEnabledForCurrentPage()); |
| 372 } | 373 } |
| 373 | 374 |
| 374 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) { | 375 TEST_F(ChromePasswordManagerClientTest, SavingAndFillingEnabledConditionsTest) { |
| 376 std::unique_ptr<WebContents> test_web_contents( |
| 377 content::WebContentsTester::CreateTestWebContents( |
| 378 web_contents()->GetBrowserContext(), nullptr)); |
| 375 std::unique_ptr<MockChromePasswordManagerClient> client( | 379 std::unique_ptr<MockChromePasswordManagerClient> client( |
| 376 new MockChromePasswordManagerClient(web_contents())); | 380 new MockChromePasswordManagerClient(test_web_contents.get())); |
| 377 // Functionality disabled if there is SSL errors. | 381 // Functionality disabled if there is SSL errors. |
| 378 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) | 382 EXPECT_CALL(*client, DidLastPageLoadEncounterSSLErrors()) |
| 379 .WillRepeatedly(Return(true)); | 383 .WillRepeatedly(Return(true)); |
| 380 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); | 384 EXPECT_FALSE(client->IsSavingAndFillingEnabledForCurrentPage()); |
| 381 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); | 385 EXPECT_FALSE(client->IsFillingEnabledForCurrentPage()); |
| 382 | 386 |
| 383 // Functionality disabled if there are SSL errors and the manager itself is | 387 // Functionality disabled if there are SSL errors and the manager itself is |
| 384 // disabled. | 388 // disabled. |
| 385 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, | 389 prefs()->SetUserPref(password_manager::prefs::kPasswordManagerSavingEnabled, |
| 386 new base::FundamentalValue(false)); | 390 new base::FundamentalValue(false)); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // In particular, this WebContent should not have the | 564 // In particular, this WebContent should not have the |
| 561 // ChromePasswordManagerClient. | 565 // ChromePasswordManagerClient. |
| 562 ASSERT_FALSE( | 566 ASSERT_FALSE( |
| 563 ChromePasswordManagerClient::FromWebContents(web_contents.get())); | 567 ChromePasswordManagerClient::FromWebContents(web_contents.get())); |
| 564 | 568 |
| 565 // This call should not crash. | 569 // This call should not crash. |
| 566 ChromePasswordManagerClient::BindCredentialManager( | 570 ChromePasswordManagerClient::BindCredentialManager( |
| 567 web_contents->GetMainFrame(), | 571 web_contents->GetMainFrame(), |
| 568 password_manager::mojom::CredentialManagerRequest()); | 572 password_manager::mojom::CredentialManagerRequest()); |
| 569 } | 573 } |
| OLD | NEW |