| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "content/public/test/web_contents_tester.h" | 44 #include "content/public/test/web_contents_tester.h" |
| 45 #include "mojo/public/cpp/bindings/binding.h" | 45 #include "mojo/public/cpp/bindings/binding.h" |
| 46 #include "services/service_manager/public/cpp/interface_provider.h" | 46 #include "services/service_manager/public/cpp/interface_provider.h" |
| 47 #include "testing/gmock/include/gmock/gmock.h" | 47 #include "testing/gmock/include/gmock/gmock.h" |
| 48 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
| 49 | 49 |
| 50 #if BUILDFLAG(ENABLE_EXTENSIONS) | 50 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 51 #include "extensions/common/constants.h" | 51 #include "extensions/common/constants.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 55 #include "components/safe_browsing/password_protection/password_protection_servi
ce.h" |
| 56 #include "components/safe_browsing_db/database_manager.h" |
| 57 #endif |
| 58 |
| 54 using browser_sync::ProfileSyncServiceMock; | 59 using browser_sync::ProfileSyncServiceMock; |
| 55 using content::BrowserContext; | 60 using content::BrowserContext; |
| 56 using content::WebContents; | 61 using content::WebContents; |
| 57 using sessions::GetPasswordStateFromNavigation; | 62 using sessions::GetPasswordStateFromNavigation; |
| 58 using sessions::SerializedNavigationEntry; | 63 using sessions::SerializedNavigationEntry; |
| 59 using testing::Return; | 64 using testing::Return; |
| 60 using testing::_; | 65 using testing::_; |
| 61 | 66 |
| 62 namespace { | 67 namespace { |
| 68 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 69 class MockPasswordProtectionService |
| 70 : public safe_browsing::PasswordProtectionService { |
| 71 public: |
| 72 MockPasswordProtectionService() |
| 73 : safe_browsing::PasswordProtectionService(nullptr, |
| 74 nullptr, |
| 75 nullptr, |
| 76 nullptr) {} |
| 77 |
| 78 ~MockPasswordProtectionService() override {} |
| 79 |
| 80 MOCK_METHOD3(FillReferrerChain, |
| 81 void(const GURL&, |
| 82 int, |
| 83 safe_browsing::LoginReputationClientRequest::Frame*)); |
| 84 MOCK_METHOD0(IsExtendedReporting, bool()); |
| 85 MOCK_METHOD0(IsIncognito, bool()); |
| 86 MOCK_METHOD0(IsPingingEnabled, bool()); |
| 87 MOCK_METHOD3(MaybeStartLowReputationRequest, |
| 88 void(const GURL&, const GURL&, const GURL&)); |
| 89 |
| 90 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(MockPasswordProtectionService); |
| 92 }; |
| 93 #endif |
| 63 | 94 |
| 64 // TODO(vabr): Get rid of the mocked client in the client's own test, see | 95 // TODO(vabr): Get rid of the mocked client in the client's own test, see |
| 65 // http://crbug.com/474577. | 96 // http://crbug.com/474577. |
| 66 class MockChromePasswordManagerClient : public ChromePasswordManagerClient { | 97 class MockChromePasswordManagerClient : public ChromePasswordManagerClient { |
| 67 public: | 98 public: |
| 68 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); | 99 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
| 69 | 100 |
| 70 explicit MockChromePasswordManagerClient(content::WebContents* web_contents) | 101 explicit MockChromePasswordManagerClient(content::WebContents* web_contents) |
| 71 : ChromePasswordManagerClient(web_contents, nullptr) { | 102 : ChromePasswordManagerClient(web_contents, nullptr) { |
| 72 ON_CALL(*this, DidLastPageLoadEncounterSSLErrors()) | 103 ON_CALL(*this, DidLastPageLoadEncounterSSLErrors()) |
| 73 .WillByDefault(testing::Return(false)); | 104 .WillByDefault(testing::Return(false)); |
| 105 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 106 password_protection_service_ = |
| 107 base::MakeUnique<MockPasswordProtectionService>(); |
| 108 #endif |
| 74 } | 109 } |
| 75 ~MockChromePasswordManagerClient() override {} | 110 ~MockChromePasswordManagerClient() override {} |
| 76 | 111 |
| 112 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 113 safe_browsing::PasswordProtectionService* GetPasswordProtectionService() |
| 114 const override { |
| 115 return password_protection_service_.get(); |
| 116 } |
| 117 |
| 118 MockPasswordProtectionService* password_protection_service() { |
| 119 return password_protection_service_.get(); |
| 120 } |
| 121 #endif |
| 122 |
| 77 private: | 123 private: |
| 124 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 125 std::unique_ptr<MockPasswordProtectionService> password_protection_service_; |
| 126 #endif |
| 78 DISALLOW_COPY_AND_ASSIGN(MockChromePasswordManagerClient); | 127 DISALLOW_COPY_AND_ASSIGN(MockChromePasswordManagerClient); |
| 79 }; | 128 }; |
| 80 | 129 |
| 81 class DummyLogReceiver : public password_manager::LogReceiver { | 130 class DummyLogReceiver : public password_manager::LogReceiver { |
| 82 public: | 131 public: |
| 83 DummyLogReceiver() = default; | 132 DummyLogReceiver() = default; |
| 84 | 133 |
| 85 void LogSavePasswordProgress(const std::string& text) override {} | 134 void LogSavePasswordProgress(const std::string& text) override {} |
| 86 | 135 |
| 87 private: | 136 private: |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 }; | 599 }; |
| 551 | 600 |
| 552 for (const TestCase& test_case : kTestCases) { | 601 for (const TestCase& test_case : kTestCases) { |
| 553 // CanShowBubbleOnURL currently only depends on the scheme. | 602 // CanShowBubbleOnURL currently only depends on the scheme. |
| 554 GURL url(base::StringPrintf("%s://example.org", test_case.scheme)); | 603 GURL url(base::StringPrintf("%s://example.org", test_case.scheme)); |
| 555 SCOPED_TRACE(url.possibly_invalid_spec()); | 604 SCOPED_TRACE(url.possibly_invalid_spec()); |
| 556 EXPECT_EQ(test_case.can_show_bubble, | 605 EXPECT_EQ(test_case.can_show_bubble, |
| 557 ChromePasswordManagerClient::CanShowBubbleOnURL(url)); | 606 ChromePasswordManagerClient::CanShowBubbleOnURL(url)); |
| 558 } | 607 } |
| 559 } | 608 } |
| 609 |
| 610 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 611 TEST_F(ChromePasswordManagerClientTest, |
| 612 VerifyMaybeStartLowReputationRequestCalled) { |
| 613 std::unique_ptr<WebContents> test_web_contents( |
| 614 content::WebContentsTester::CreateTestWebContents( |
| 615 web_contents()->GetBrowserContext(), nullptr)); |
| 616 std::unique_ptr<MockChromePasswordManagerClient> client( |
| 617 new MockChromePasswordManagerClient(test_web_contents.get())); |
| 618 EXPECT_CALL(*client->password_protection_service(), |
| 619 MaybeStartLowReputationRequest(_, _, _)) |
| 620 .Times(1); |
| 621 client->CheckSafeBrowsingReputation(GURL("http://foo.com/submit"), |
| 622 GURL("http://foo.com/iframe.html")); |
| 623 } |
| 624 #endif |
| OLD | NEW |