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

Side by Side Diff: components/safe_browsing/password_protection/password_protection_service_unittest.cc

Issue 2856033002: Add finch control of user population in low reputation requests (Closed)
Patch Set: nit 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "components/safe_browsing/password_protection/password_protection_servi ce.h" 4 #include "components/safe_browsing/password_protection/password_protection_servi ce.h"
5 5
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "base/test/null_task_runner.h" 10 #include "base/test/null_task_runner.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 bool IsExtendedReporting() override { return is_extended_reporting_; } 90 bool IsExtendedReporting() override { return is_extended_reporting_; }
91 91
92 bool IsIncognito() override { return is_incognito_; } 92 bool IsIncognito() override { return is_incognito_; }
93 93
94 void set_extended_reporting(bool enabled) { 94 void set_extended_reporting(bool enabled) {
95 is_extended_reporting_ = enabled; 95 is_extended_reporting_ = enabled;
96 } 96 }
97 97
98 void set_incognito(bool enabled) { is_incognito_ = enabled; } 98 void set_incognito(bool enabled) { is_incognito_ = enabled; }
99 99
100 bool IsPingingEnabled() override { return true; } 100 bool IsPingingEnabled(const base::Feature& feature) override { return true; }
101
102 bool IsHistorySyncEnabled() override { return false; }
101 103
102 LoginReputationClientResponse* latest_response() { 104 LoginReputationClientResponse* latest_response() {
103 return latest_response_.get(); 105 return latest_response_.get();
104 } 106 }
105 107
106 ~TestPasswordProtectionService() override {} 108 ~TestPasswordProtectionService() override {}
107 109
108 size_t GetPendingRequestsCount() { return requests_.size(); } 110 size_t GetPendingRequestsCount() { return requests_.size(); }
109 111
110 private: 112 private:
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 GURL("http://foo.com/frame")); 419 GURL("http://foo.com/frame"));
418 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount()); 420 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
419 421
420 // If main frame url is ftp, don't create request. 422 // If main frame url is ftp, don't create request.
421 password_protection_service_->MaybeStartLowReputationRequest( 423 password_protection_service_->MaybeStartLowReputationRequest(
422 GURL("ftp://foo.com:21"), GURL("http://foo.com/submit"), 424 GURL("ftp://foo.com:21"), GURL("http://foo.com/submit"),
423 GURL("http://foo.com/frame")); 425 GURL("http://foo.com/frame"));
424 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount()); 426 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
425 } 427 }
426 428
427 TEST_F(PasswordProtectionServiceTest, TestNoRequestSentForIncognito) {
428 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
429 password_protection_service_->set_incognito(true);
430 password_protection_service_->StartRequest(
431 GURL(kTargetUrl), GURL("http://foo.com/submit"),
432 GURL("http://foo.com/frame"),
433 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
434 base::RunLoop().RunUntilIdle();
435 EXPECT_EQ(nullptr, password_protection_service_->latest_response());
436 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
437 testing::ElementsAre(base::Bucket(7 /* INCOGNITO */, 1)));
438 }
439
440 TEST_F(PasswordProtectionServiceTest,
441 TestNoRequestSentForNonExtendedReporting) {
442 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
443 password_protection_service_->set_extended_reporting(false);
444 password_protection_service_->StartRequest(
445 GURL(kTargetUrl), GURL("http://foo.com/submit"),
446 GURL("http://foo.com/frame"),
447 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
448
449 base::RunLoop().RunUntilIdle();
450 EXPECT_EQ(nullptr, password_protection_service_->latest_response());
451 EXPECT_THAT(
452 histograms_.GetAllSamples(kRequestOutcomeHistogramName),
453 testing::ElementsAre(base::Bucket(6 /* NO_EXTENDED_REPORTING */, 1)));
454 }
455
456 TEST_F(PasswordProtectionServiceTest, TestNoRequestSentForWhitelistedURL) { 429 TEST_F(PasswordProtectionServiceTest, TestNoRequestSentForWhitelistedURL) {
457 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0); 430 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
458 InitializeAndStartRequest(true /* match whitelist */, 431 InitializeAndStartRequest(true /* match whitelist */,
459 10000 /* timeout in ms*/); 432 10000 /* timeout in ms*/);
460 base::RunLoop().RunUntilIdle(); 433 base::RunLoop().RunUntilIdle();
461 EXPECT_EQ(nullptr, password_protection_service_->latest_response()); 434 EXPECT_EQ(nullptr, password_protection_service_->latest_response());
462 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName), 435 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
463 testing::ElementsAre(base::Bucket(4 /* MATCHED_WHITELIST */, 1))); 436 testing::ElementsAre(base::Bucket(4 /* MATCHED_WHITELIST */, 1)));
464 } 437 }
465 438
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); 531 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
559 532
560 // Destroy password_protection_service_ while there is one request pending. 533 // Destroy password_protection_service_ while there is one request pending.
561 password_protection_service_.reset(); 534 password_protection_service_.reset();
562 base::RunLoop().RunUntilIdle(); 535 base::RunLoop().RunUntilIdle();
563 536
564 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName), 537 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
565 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); 538 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1)));
566 } 539 }
567 } // namespace safe_browsing 540 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698