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

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: rebase 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 GURL("http://foo.com/frame")); 420 GURL("http://foo.com/frame"));
419 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount()); 421 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
420 422
421 // If main frame url is ftp, don't create request. 423 // If main frame url is ftp, don't create request.
422 password_protection_service_->MaybeStartLowReputationRequest( 424 password_protection_service_->MaybeStartLowReputationRequest(
423 GURL("ftp://foo.com:21"), GURL("http://foo.com/submit"), 425 GURL("ftp://foo.com:21"), GURL("http://foo.com/submit"),
424 GURL("http://foo.com/frame")); 426 GURL("http://foo.com/frame"));
425 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount()); 427 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount());
426 } 428 }
427 429
428 TEST_F(PasswordProtectionServiceTest, TestNoRequestSentForIncognito) {
429 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
430 password_protection_service_->set_incognito(true);
431 password_protection_service_->StartRequest(
432 GURL(kTargetUrl), GURL("http://foo.com/submit"),
433 GURL("http://foo.com/frame"),
434 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
435 base::RunLoop().RunUntilIdle();
436 EXPECT_EQ(nullptr, password_protection_service_->latest_response());
437 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
438 testing::ElementsAre(base::Bucket(7 /* INCOGNITO */, 1)));
439 }
440
441 TEST_F(PasswordProtectionServiceTest,
442 TestNoRequestSentForNonExtendedReporting) {
443 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
444 password_protection_service_->set_extended_reporting(false);
445 password_protection_service_->StartRequest(
446 GURL(kTargetUrl), GURL("http://foo.com/submit"),
447 GURL("http://foo.com/frame"),
448 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
449
450 base::RunLoop().RunUntilIdle();
451 EXPECT_EQ(nullptr, password_protection_service_->latest_response());
452 EXPECT_THAT(
453 histograms_.GetAllSamples(kRequestOutcomeHistogramName),
454 testing::ElementsAre(base::Bucket(6 /* NO_EXTENDED_REPORTING */, 1)));
455 }
456
457 TEST_F(PasswordProtectionServiceTest, TestNoRequestSentForWhitelistedURL) { 430 TEST_F(PasswordProtectionServiceTest, TestNoRequestSentForWhitelistedURL) {
458 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0); 431 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0);
459 InitializeAndStartRequest(true /* match whitelist */, 432 InitializeAndStartRequest(true /* match whitelist */,
460 10000 /* timeout in ms*/); 433 10000 /* timeout in ms*/);
461 base::RunLoop().RunUntilIdle(); 434 base::RunLoop().RunUntilIdle();
462 EXPECT_EQ(nullptr, password_protection_service_->latest_response()); 435 EXPECT_EQ(nullptr, password_protection_service_->latest_response());
463 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName), 436 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
464 testing::ElementsAre(base::Bucket(4 /* MATCHED_WHITELIST */, 1))); 437 testing::ElementsAre(base::Bucket(4 /* MATCHED_WHITELIST */, 1)));
465 } 438 }
466 439
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); 532 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
560 533
561 // Destroy password_protection_service_ while there is one request pending. 534 // Destroy password_protection_service_ while there is one request pending.
562 password_protection_service_.reset(); 535 password_protection_service_.reset();
563 base::RunLoop().RunUntilIdle(); 536 base::RunLoop().RunUntilIdle();
564 537
565 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName), 538 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName),
566 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); 539 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1)));
567 } 540 }
568 } // namespace safe_browsing 541 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698