| 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/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/scoped_feature_list.h" | 17 #include "base/test/scoped_feature_list.h" |
| 17 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 19 #include "chrome/browser/sync/profile_sync_test_util.h" | 20 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 20 #include "chrome/common/channel_info.h" | 21 #include "chrome/common/channel_info.h" |
| 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 23 #include "components/autofill/content/common/autofill_agent.mojom.h" | 24 #include "components/autofill/content/common/autofill_agent.mojom.h" |
| 24 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" | 25 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" |
| 25 #include "components/password_manager/core/browser/credentials_filter.h" | 26 #include "components/password_manager/core/browser/credentials_filter.h" |
| 26 #include "components/password_manager/core/browser/log_manager.h" | 27 #include "components/password_manager/core/browser/log_manager.h" |
| 27 #include "components/password_manager/core/browser/log_receiver.h" | 28 #include "components/password_manager/core/browser/log_receiver.h" |
| 28 #include "components/password_manager/core/browser/log_router.h" | 29 #include "components/password_manager/core/browser/log_router.h" |
| 29 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" | 30 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" |
| 30 #include "components/password_manager/core/browser/password_manager_test_utils.h
" | 31 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
| 31 #include "components/password_manager/core/common/credential_manager_types.h" | 32 #include "components/password_manager/core/common/credential_manager_types.h" |
| 32 #include "components/password_manager/core/common/password_manager_features.h" | 33 #include "components/password_manager/core/common/password_manager_features.h" |
| 33 #include "components/password_manager/core/common/password_manager_pref_names.h" | 34 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 34 #include "components/prefs/pref_registry_simple.h" | 35 #include "components/prefs/pref_registry_simple.h" |
| 35 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 36 #include "components/prefs/testing_pref_service.h" | 37 #include "components/prefs/testing_pref_service.h" |
| 37 #include "components/sessions/content/content_record_password_state.h" | 38 #include "components/sessions/content/content_record_password_state.h" |
| 38 #include "components/sync_preferences/testing_pref_service_syncable.h" | 39 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 39 #include "components/version_info/version_info.h" | 40 #include "components/version_info/version_info.h" |
| 40 #include "content/public/browser/browser_context.h" | 41 #include "content/public/browser/browser_context.h" |
| 41 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/url_constants.h" |
| 42 #include "content/public/test/web_contents_tester.h" | 44 #include "content/public/test/web_contents_tester.h" |
| 45 #include "extensions/features/features.h" |
| 43 #include "mojo/public/cpp/bindings/binding.h" | 46 #include "mojo/public/cpp/bindings/binding.h" |
| 44 #include "services/service_manager/public/cpp/interface_provider.h" | 47 #include "services/service_manager/public/cpp/interface_provider.h" |
| 45 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
| 47 | 50 |
| 51 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 52 #include "extensions/common/constants.h" |
| 53 #endif |
| 54 |
| 48 using browser_sync::ProfileSyncServiceMock; | 55 using browser_sync::ProfileSyncServiceMock; |
| 49 using content::BrowserContext; | 56 using content::BrowserContext; |
| 50 using content::WebContents; | 57 using content::WebContents; |
| 51 using sessions::GetPasswordStateFromNavigation; | 58 using sessions::GetPasswordStateFromNavigation; |
| 52 using sessions::SerializedNavigationEntry; | 59 using sessions::SerializedNavigationEntry; |
| 53 using testing::Return; | 60 using testing::Return; |
| 54 using testing::_; | 61 using testing::_; |
| 55 | 62 |
| 56 namespace { | 63 namespace { |
| 57 | 64 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 // In particular, this WebContent should not have the | 526 // In particular, this WebContent should not have the |
| 520 // ChromePasswordManagerClient. | 527 // ChromePasswordManagerClient. |
| 521 ASSERT_FALSE( | 528 ASSERT_FALSE( |
| 522 ChromePasswordManagerClient::FromWebContents(web_contents.get())); | 529 ChromePasswordManagerClient::FromWebContents(web_contents.get())); |
| 523 | 530 |
| 524 // This call should not crash. | 531 // This call should not crash. |
| 525 ChromePasswordManagerClient::BindCredentialManager( | 532 ChromePasswordManagerClient::BindCredentialManager( |
| 526 web_contents->GetMainFrame(), | 533 web_contents->GetMainFrame(), |
| 527 password_manager::mojom::CredentialManagerRequest()); | 534 password_manager::mojom::CredentialManagerRequest()); |
| 528 } | 535 } |
| 536 |
| 537 TEST_F(ChromePasswordManagerClientTest, CanShowBubbleOnURL) { |
| 538 struct TestCase { |
| 539 const char* scheme; |
| 540 bool can_show_bubble; |
| 541 } kTestCases[] = { |
| 542 {url::kHttpScheme, true}, |
| 543 {url::kHttpsScheme, true}, |
| 544 {url::kFtpScheme, true}, |
| 545 {url::kDataScheme, true}, |
| 546 {"feed", true}, |
| 547 {url::kBlobScheme, true}, |
| 548 {url::kFileSystemScheme, true}, |
| 549 |
| 550 {"invalid-scheme-i-just-made-up", false}, |
| 551 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 552 {extensions::kExtensionScheme, false}, |
| 553 #endif |
| 554 {url::kAboutScheme, false}, |
| 555 {content::kChromeDevToolsScheme, false}, |
| 556 {content::kChromeUIScheme, false}, |
| 557 {url::kJavaScriptScheme, false}, |
| 558 {url::kMailToScheme, false}, |
| 559 {content::kViewSourceScheme, false}, |
| 560 }; |
| 561 |
| 562 for (const TestCase& test_case : kTestCases) { |
| 563 // CanShowBubbleOnURL currently only depends on the scheme. |
| 564 GURL url(base::StringPrintf("%s://example.org", test_case.scheme)); |
| 565 SCOPED_TRACE(url.possibly_invalid_spec()); |
| 566 EXPECT_EQ(test_case.can_show_bubble, |
| 567 ChromePasswordManagerClient::CanShowBubbleOnURL(url)); |
| 568 } |
| 569 } |
| OLD | NEW |