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

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

Issue 2833193002: Trigger Password Protection ping on username/password field on focus (Closed)
Patch Set: Add tests Created 3 years, 7 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 FakePasswordProtectionService
70 : public safe_browsing::PasswordProtectionService {
71 public:
72 FakePasswordProtectionService()
73 : PasswordProtectionService(nullptr, nullptr, nullptr, nullptr),
74 called_maybe_start_low_reputation_request_(false) {}
75
76 void FillReferrerChain(
77 const GURL& event_url,
78 int event_tab_id,
79 safe_browsing::LoginReputationClientRequest::Frame* frame) override {}
80
81 bool IsExtendedReporting() override { return true; }
82
83 bool IsIncognito() override { return false; }
84
85 bool IsPingingEnabled() override { return true; }
86
87 void MaybeStartLowReputationRequest(
dvadym 2017/04/28 12:14:40 Nit: Would it be possible to use gmock for mocking
Jialiu Lin 2017/04/28 18:38:46 Changed to MOCK methods instead.
88 const GURL& main_frame_url,
89 const GURL& password_form_action,
90 const GURL& password_form_frame_url) override {
91 called_maybe_start_low_reputation_request_ = true;
92 }
93
94 bool called_maybe_start_low_reputation_request() {
95 return called_maybe_start_low_reputation_request_;
96 }
97 ~FakePasswordProtectionService() override {}
98
99 private:
100 bool called_maybe_start_low_reputation_request_;
101 DISALLOW_COPY_AND_ASSIGN(FakePasswordProtectionService);
102 };
103 #endif
63 104
64 // TODO(vabr): Get rid of the mocked client in the client's own test, see 105 // TODO(vabr): Get rid of the mocked client in the client's own test, see
65 // http://crbug.com/474577. 106 // http://crbug.com/474577.
66 class MockChromePasswordManagerClient : public ChromePasswordManagerClient { 107 class MockChromePasswordManagerClient : public ChromePasswordManagerClient {
67 public: 108 public:
68 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); 109 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
69 110
70 explicit MockChromePasswordManagerClient(content::WebContents* web_contents) 111 explicit MockChromePasswordManagerClient(content::WebContents* web_contents)
71 : ChromePasswordManagerClient(web_contents, nullptr) { 112 : ChromePasswordManagerClient(web_contents, nullptr) {
72 ON_CALL(*this, DidLastPageLoadEncounterSSLErrors()) 113 ON_CALL(*this, DidLastPageLoadEncounterSSLErrors())
73 .WillByDefault(testing::Return(false)); 114 .WillByDefault(testing::Return(false));
115 #if defined(SAFE_BROWSING_DB_LOCAL)
116 fake_password_protection_service_ =
117 base::MakeUnique<FakePasswordProtectionService>();
118 #endif
74 } 119 }
75 ~MockChromePasswordManagerClient() override {} 120 ~MockChromePasswordManagerClient() override {}
76 121
122 #if defined(SAFE_BROWSING_DB_LOCAL)
123 safe_browsing::PasswordProtectionService* GetPasswordProtectionService()
124 const override {
125 return fake_password_protection_service_.get();
126 }
127
128 bool called_maybe_start_low_reputation_request() {
129 return fake_password_protection_service_
130 ->called_maybe_start_low_reputation_request();
131 }
132 #endif
133
77 private: 134 private:
135 #if defined(SAFE_BROWSING_DB_LOCAL)
136 std::unique_ptr<FakePasswordProtectionService>
137 fake_password_protection_service_;
138 #endif
78 DISALLOW_COPY_AND_ASSIGN(MockChromePasswordManagerClient); 139 DISALLOW_COPY_AND_ASSIGN(MockChromePasswordManagerClient);
79 }; 140 };
80 141
81 class DummyLogReceiver : public password_manager::LogReceiver { 142 class DummyLogReceiver : public password_manager::LogReceiver {
82 public: 143 public:
83 DummyLogReceiver() = default; 144 DummyLogReceiver() = default;
84 145
85 void LogSavePasswordProgress(const std::string& text) override {} 146 void LogSavePasswordProgress(const std::string& text) override {}
86 147
87 private: 148 private:
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 }; 611 };
551 612
552 for (const TestCase& test_case : kTestCases) { 613 for (const TestCase& test_case : kTestCases) {
553 // CanShowBubbleOnURL currently only depends on the scheme. 614 // CanShowBubbleOnURL currently only depends on the scheme.
554 GURL url(base::StringPrintf("%s://example.org", test_case.scheme)); 615 GURL url(base::StringPrintf("%s://example.org", test_case.scheme));
555 SCOPED_TRACE(url.possibly_invalid_spec()); 616 SCOPED_TRACE(url.possibly_invalid_spec());
556 EXPECT_EQ(test_case.can_show_bubble, 617 EXPECT_EQ(test_case.can_show_bubble,
557 ChromePasswordManagerClient::CanShowBubbleOnURL(url)); 618 ChromePasswordManagerClient::CanShowBubbleOnURL(url));
558 } 619 }
559 } 620 }
621
622 TEST_F(ChromePasswordManagerClientTest,
623 VerifyMaybeStartLowReputationRequestCalled) {
624 std::unique_ptr<WebContents> test_web_contents(
625 content::WebContentsTester::CreateTestWebContents(
626 web_contents()->GetBrowserContext(), nullptr));
627 std::unique_ptr<MockChromePasswordManagerClient> client(
628 new MockChromePasswordManagerClient(test_web_contents.get()));
629 ASSERT_FALSE(client->called_maybe_start_low_reputation_request());
630 client->CheckSafeBrowsingReputation(GURL("http://foo.com/submit"),
631 GURL("http://foo.com/iframe.html"));
632 EXPECT_TRUE(client->called_maybe_start_low_reputation_request());
633 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698