Index: components/safe_browsing/password_protection/password_protection_service_unittest.cc |
diff --git a/components/safe_browsing/password_protection/password_protection_service_unittest.cc b/components/safe_browsing/password_protection/password_protection_service_unittest.cc |
index 3deb72a2720a8fb36af52612dc0dabb1c83de3ee..034d3530b1113805122cff864e5e80f8462fb599 100644 |
--- a/components/safe_browsing/password_protection/password_protection_service_unittest.cc |
+++ b/components/safe_browsing/password_protection/password_protection_service_unittest.cc |
@@ -14,6 +14,7 @@ |
#include "components/safe_browsing_db/test_database_manager.h" |
#include "components/sync_preferences/testing_pref_service_syncable.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
+#include "google_apis/gaia/gaia_urls.h" |
#include "net/url_request/test_url_fetcher_factory.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -171,14 +172,15 @@ class PasswordProtectionServiceTest : public testing::Test { |
request_->Start(); |
} |
- void InitializeAndStartPasswordEntryRequest(bool match_whitelist, |
+ void InitializeAndStartPasswordEntryRequest(const std::string& saved_domain, |
+ bool match_whitelist, |
int timeout_in_ms) { |
GURL target_url(kTargetUrl); |
EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
.WillRepeatedly(testing::Return(match_whitelist)); |
request_ = new PasswordProtectionRequest( |
- nullptr, target_url, GURL(), GURL(), std::string(kSavedDomain), |
+ nullptr, target_url, GURL(), GURL(), saved_domain, |
LoginReputationClientRequest::PASSWORD_REUSE_EVENT, |
password_protection_service_.get(), timeout_in_ms); |
request_->Start(); |
@@ -623,7 +625,7 @@ TEST_F(PasswordProtectionServiceTest, VerifyPasswordOnFocusRequestProto) { |
} |
TEST_F(PasswordProtectionServiceTest, |
- VerifyProtectedPasswordEntryRequestProto) { |
+ VerifyChromeSiginPasswordEntryRequestProto) { |
// Set up valid response. |
net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr); |
fetcher.set_status( |
@@ -632,7 +634,37 @@ TEST_F(PasswordProtectionServiceTest, |
LoginReputationClientResponse expected_response = CreateVerdictProto( |
LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host()); |
fetcher.SetResponseString(expected_response.SerializeAsString()); |
- InitializeAndStartPasswordEntryRequest(false /* match whitelist */, |
+ InitializeAndStartPasswordEntryRequest( |
+ GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec(), |
+ false /* match whitelist */, 100000 /* timeout in ms*/); |
+ base::RunLoop().RunUntilIdle(); |
+ request_->OnURLFetchComplete(&fetcher); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ LoginReputationClientRequest* actual_request = |
+ password_protection_service_->GetLatestRequestProto(); |
+ EXPECT_EQ(kTargetUrl, actual_request->page_url()); |
+ EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT, |
+ actual_request->trigger_type()); |
+ EXPECT_EQ(1, actual_request->frames_size()); |
+ EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); |
+ ASSERT_TRUE(actual_request->has_password_reuse_event()); |
+ EXPECT_TRUE( |
vakh (use Gerrit instead)
2017/06/01 00:02:25
I think this should be an ASSERT
Jialiu Lin
2017/06/01 01:22:01
Done.
|
+ actual_request->password_reuse_event().is_chrome_signin_password()); |
+} |
+ |
+TEST_F(PasswordProtectionServiceTest, |
+ VerifyPasswordManagerPasswordEntryRequestProto) { |
+ // Set up valid response. |
+ net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr); |
vakh (use Gerrit instead)
2017/06/01 00:02:25
There's plenty of overlap in these tests. Do you t
Jialiu Lin
2017/06/01 01:22:01
I'll combine these two tests, such that they can s
|
+ fetcher.set_status( |
+ net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); |
+ fetcher.set_response_code(200); |
+ LoginReputationClientResponse expected_response = CreateVerdictProto( |
+ LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host()); |
+ fetcher.SetResponseString(expected_response.SerializeAsString()); |
+ InitializeAndStartPasswordEntryRequest(std::string(kSavedDomain), |
+ false /* match whitelist */, |
100000 /* timeout in ms*/); |
base::RunLoop().RunUntilIdle(); |
request_->OnURLFetchComplete(&fetcher); |
@@ -645,8 +677,9 @@ TEST_F(PasswordProtectionServiceTest, |
actual_request->trigger_type()); |
EXPECT_EQ(1, actual_request->frames_size()); |
EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); |
- // TODO(jialiul): Update this test when we're ready to fill more fields. |
- ASSERT_FALSE(actual_request->has_password_reuse_event()); |
+ ASSERT_TRUE(actual_request->has_password_reuse_event()); |
+ EXPECT_FALSE( |
+ actual_request->password_reuse_event().is_chrome_signin_password()); |
} |
} // namespace safe_browsing |