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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
diff --git a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
index 9b8bc587ebcb9e0589944e6527d9775a30986fbd..0ff72017de7a0fb7a5a0343771a41044e61dceb1 100644
--- a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
+++ b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
@@ -51,6 +51,11 @@
#include "extensions/common/constants.h"
#endif
+#if defined(SAFE_BROWSING_DB_LOCAL)
+#include "components/safe_browsing/password_protection/password_protection_service.h"
+#include "components/safe_browsing_db/database_manager.h"
+#endif
+
using browser_sync::ProfileSyncServiceMock;
using content::BrowserContext;
using content::WebContents;
@@ -60,6 +65,42 @@ using testing::Return;
using testing::_;
namespace {
+#if defined(SAFE_BROWSING_DB_LOCAL)
+class FakePasswordProtectionService
+ : public safe_browsing::PasswordProtectionService {
+ public:
+ FakePasswordProtectionService()
+ : PasswordProtectionService(nullptr, nullptr, nullptr, nullptr),
+ called_maybe_start_low_reputation_request_(false) {}
+
+ void FillReferrerChain(
+ const GURL& event_url,
+ int event_tab_id,
+ safe_browsing::LoginReputationClientRequest::Frame* frame) override {}
+
+ bool IsExtendedReporting() override { return true; }
+
+ bool IsIncognito() override { return false; }
+
+ bool IsPingingEnabled() override { return true; }
+
+ 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.
+ const GURL& main_frame_url,
+ const GURL& password_form_action,
+ const GURL& password_form_frame_url) override {
+ called_maybe_start_low_reputation_request_ = true;
+ }
+
+ bool called_maybe_start_low_reputation_request() {
+ return called_maybe_start_low_reputation_request_;
+ }
+ ~FakePasswordProtectionService() override {}
+
+ private:
+ bool called_maybe_start_low_reputation_request_;
+ DISALLOW_COPY_AND_ASSIGN(FakePasswordProtectionService);
+};
+#endif
// TODO(vabr): Get rid of the mocked client in the client's own test, see
// http://crbug.com/474577.
@@ -71,10 +112,30 @@ class MockChromePasswordManagerClient : public ChromePasswordManagerClient {
: ChromePasswordManagerClient(web_contents, nullptr) {
ON_CALL(*this, DidLastPageLoadEncounterSSLErrors())
.WillByDefault(testing::Return(false));
+#if defined(SAFE_BROWSING_DB_LOCAL)
+ fake_password_protection_service_ =
+ base::MakeUnique<FakePasswordProtectionService>();
+#endif
}
~MockChromePasswordManagerClient() override {}
+#if defined(SAFE_BROWSING_DB_LOCAL)
+ safe_browsing::PasswordProtectionService* GetPasswordProtectionService()
+ const override {
+ return fake_password_protection_service_.get();
+ }
+
+ bool called_maybe_start_low_reputation_request() {
+ return fake_password_protection_service_
+ ->called_maybe_start_low_reputation_request();
+ }
+#endif
+
private:
+#if defined(SAFE_BROWSING_DB_LOCAL)
+ std::unique_ptr<FakePasswordProtectionService>
+ fake_password_protection_service_;
+#endif
DISALLOW_COPY_AND_ASSIGN(MockChromePasswordManagerClient);
};
@@ -557,3 +618,16 @@ TEST_F(ChromePasswordManagerClientTest, CanShowBubbleOnURL) {
ChromePasswordManagerClient::CanShowBubbleOnURL(url));
}
}
+
+TEST_F(ChromePasswordManagerClientTest,
+ VerifyMaybeStartLowReputationRequestCalled) {
+ std::unique_ptr<WebContents> test_web_contents(
+ content::WebContentsTester::CreateTestWebContents(
+ web_contents()->GetBrowserContext(), nullptr));
+ std::unique_ptr<MockChromePasswordManagerClient> client(
+ new MockChromePasswordManagerClient(test_web_contents.get()));
+ ASSERT_FALSE(client->called_maybe_start_low_reputation_request());
+ client->CheckSafeBrowsingReputation(GURL("http://foo.com/submit"),
+ GURL("http://foo.com/iframe.html"));
+ EXPECT_TRUE(client->called_maybe_start_low_reputation_request());
+}

Powered by Google App Engine
This is Rietveld 408576698