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

Unified Diff: components/safe_browsing/password_protection/password_protection_service_unittest.cc

Issue 2869253002: Add UMA metrics to phishguard pings (Closed)
Patch Set: fix unittest 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 side-by-side diff with in-line comments
Download patch
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 547f23ceb98afa52e9009b37672e39f46e1c9119..79efbc264cd771aa8e5ed01b9189e250525e2405 100644
--- a/components/safe_browsing/password_protection/password_protection_service_unittest.cc
+++ b/components/safe_browsing/password_protection/password_protection_service_unittest.cc
@@ -23,8 +23,9 @@ const char kPasswordReuseMatchWhitelistHistogramName[] =
"PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist";
const char kWhitelistedUrl[] = "http://inwhitelist.com";
const char kNoneWhitelistedUrl[] = "http://notinwhitelist.com";
-const char kRequestOutcomeHistogramName[] = "PasswordProtection.RequestOutcome";
const char kTargetUrl[] = "http://foo.com";
+const char kVerdictHistogramName[] =
+ "PasswordProtection.Verdict.PasswordFieldOnFocus";
} // namespace
@@ -406,7 +407,7 @@ TEST_F(PasswordProtectionServiceTest, TestCleanUpCachedVerdicts) {
TEST_F(PasswordProtectionServiceTest,
TestNoRequestCreatedIfMainFrameURLIsNotValid) {
ASSERT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
- password_protection_service_->MaybeStartLowReputationRequest(
+ password_protection_service_->MaybeStartPasswordFieldOnFocusRequest(
GURL(), GURL("http://foo.com/submit"), GURL("http://foo.com/frame"));
EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
}
@@ -415,44 +416,45 @@ TEST_F(PasswordProtectionServiceTest,
TestNoRequestCreatedIfMainFrameURLIsNotHttpOrHttps) {
ASSERT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
// If main frame url is data url, don't create request.
- password_protection_service_->MaybeStartLowReputationRequest(
+ password_protection_service_->MaybeStartPasswordFieldOnFocusRequest(
GURL("data:text/html, <p>hellow"), GURL("http://foo.com/submit"),
GURL("http://foo.com/frame"));
EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
// If main frame url is ftp, don't create request.
- password_protection_service_->MaybeStartLowReputationRequest(
+ password_protection_service_->MaybeStartPasswordFieldOnFocusRequest(
GURL("ftp://foo.com:21"), GURL("http://foo.com/submit"),
GURL("http://foo.com/frame"));
EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
}
TEST_F(PasswordProtectionServiceTest, TestNoRequestSentForWhitelistedURL) {
- histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0);
InitializeAndStartRequest(true /* match whitelist */,
10000 /* timeout in ms*/);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(nullptr, password_protection_service_->latest_response());
- EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
- testing::ElementsAre(base::Bucket(4 /* MATCHED_WHITELIST */, 1)));
+ EXPECT_THAT(
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName),
+ testing::ElementsAre(base::Bucket(4 /* MATCHED_WHITELIST */, 1)));
}
TEST_F(PasswordProtectionServiceTest, TestNoRequestSentIfVerdictAlreadyCached) {
- histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0);
CacheVerdict(GURL(kTargetUrl), LoginReputationClientResponse::LOW_REPUTATION,
600, GURL(kTargetUrl).host(), base::Time::Now());
InitializeAndStartRequest(false /* match whitelist */,
10000 /* timeout in ms*/);
base::RunLoop().RunUntilIdle();
EXPECT_THAT(
- histograms_.GetAllSamples(kRequestOutcomeHistogramName),
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName),
testing::ElementsAre(base::Bucket(5 /* RESPONSE_ALREADY_CACHED */, 1)));
EXPECT_EQ(LoginReputationClientResponse::LOW_REPUTATION,
password_protection_service_->latest_response()->verdict_type());
}
TEST_F(PasswordProtectionServiceTest, TestResponseFetchFailed) {
- histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0);
net::TestURLFetcher failed_fetcher(0, GURL("http://bar.com"), nullptr);
// Set up failed response.
failed_fetcher.set_status(
@@ -463,12 +465,13 @@ TEST_F(PasswordProtectionServiceTest, TestResponseFetchFailed) {
request_->OnURLFetchComplete(&failed_fetcher);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(nullptr, password_protection_service_->latest_response());
- EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
- testing::ElementsAre(base::Bucket(9 /* FETCH_FAILED */, 1)));
+ EXPECT_THAT(
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName),
+ testing::ElementsAre(base::Bucket(9 /* FETCH_FAILED */, 1)));
}
TEST_F(PasswordProtectionServiceTest, TestMalformedResponse) {
- histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0);
// Set up malformed response.
net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr);
fetcher.set_status(
@@ -482,22 +485,23 @@ TEST_F(PasswordProtectionServiceTest, TestMalformedResponse) {
base::RunLoop().RunUntilIdle();
EXPECT_EQ(nullptr, password_protection_service_->latest_response());
EXPECT_THAT(
- histograms_.GetAllSamples(kRequestOutcomeHistogramName),
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName),
testing::ElementsAre(base::Bucket(10 /* RESPONSE_MALFORMED */, 1)));
}
TEST_F(PasswordProtectionServiceTest, TestRequestTimedout) {
- histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0);
InitializeAndStartRequest(false /* match whitelist */,
0 /* timeout immediately */);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(nullptr, password_protection_service_->latest_response());
- EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
- testing::ElementsAre(base::Bucket(3 /* TIMEDOUT */, 1)));
+ EXPECT_THAT(
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName),
+ testing::ElementsAre(base::Bucket(3 /* TIMEDOUT */, 1)));
}
TEST_F(PasswordProtectionServiceTest, TestRequestAndResponseSuccessfull) {
- histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0);
// Set up valid response.
net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr);
fetcher.set_status(
@@ -511,8 +515,11 @@ TEST_F(PasswordProtectionServiceTest, TestRequestAndResponseSuccessfull) {
10000 /* timeout in ms*/);
request_->OnURLFetchComplete(&fetcher);
base::RunLoop().RunUntilIdle();
- EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
- testing::ElementsAre(base::Bucket(1 /* SUCCEEDED */, 1)));
+ EXPECT_THAT(
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName),
+ testing::ElementsAre(base::Bucket(1 /* SUCCEEDED */, 1)));
+ EXPECT_THAT(histograms_.GetAllSamples(kVerdictHistogramName),
+ testing::ElementsAre(base::Bucket(3 /* PHISHING */, 1)));
LoginReputationClientResponse* actual_response =
password_protection_service_->latest_response();
EXPECT_EQ(expected_response.verdict_type(), actual_response->verdict_type());
@@ -523,7 +530,7 @@ TEST_F(PasswordProtectionServiceTest, TestRequestAndResponseSuccessfull) {
}
TEST_F(PasswordProtectionServiceTest, TestTearDownWithPendingRequests) {
- histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0);
GURL target_url(kTargetUrl);
EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url))
.WillRepeatedly(testing::Return(false));
@@ -535,7 +542,8 @@ TEST_F(PasswordProtectionServiceTest, TestTearDownWithPendingRequests) {
password_protection_service_.reset();
base::RunLoop().RunUntilIdle();
- EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
- testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1)));
+ EXPECT_THAT(
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName),
+ testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1)));
}
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698