Chromium Code Reviews| Index: chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc |
| diff --git a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc |
| index dfc0242e28c5a2db446de20fde5beed451d46c60..1fa24279b034d7c1165aab1cac0d7f95947afe55 100644 |
| --- a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc |
| +++ b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc |
| @@ -8,9 +8,11 @@ |
| #include "base/bind.h" |
| #include "base/run_loop.h" |
| +#include "base/test/histogram_tester.h" |
| #include "base/test/scoped_feature_list.h" |
| #include "base/test/simple_test_clock.h" |
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| +#include "chrome/browser/permissions/permission_uma_util.h" |
| #include "chrome/browser/permissions/permission_util.h" |
| #include "chrome/common/chrome_features.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| @@ -245,6 +247,7 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { |
| // Test that an origin that has been blacklisted for a permission is embargoed. |
| TEST_F(PermissionDecisionAutoBlockerUnitTest, TestUpdateEmbargoBlacklist) { |
| GURL url("https://www.google.com"); |
| + base::HistogramTester histograms; |
| scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| new MockSafeBrowsingDatabaseManager(true /* perform_callback */); |
| @@ -252,9 +255,16 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestUpdateEmbargoBlacklist) { |
| db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 2000 /* timeout in ms */); |
| - |
| UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url); |
| EXPECT_TRUE(last_embargoed_status()); |
| + histograms.ExpectTotalCount("Permissions.AutoBlocker.EmbargoReason", 1); |
| + histograms.ExpectBucketCount( |
| + "Permissions.AutoBlocker.EmbargoReason", |
| + PermissionEmbargoReason::PERMISSIONS_BLACKLISTING, 1); |
| + histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| + 1); |
| + histograms.ExpectBucketCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| + SafeBrowsingResponse::BLACKLISTED, 1); |
| } |
| // Check that IsUnderEmbargo returns the correct value when the embargo is set |
| @@ -303,6 +313,7 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { |
| TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) { |
| GURL url("https://www.google.com"); |
| clock()->SetNow(base::Time::Now()); |
| + base::HistogramTester histograms; |
| // Record some dismisses. |
| EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| @@ -319,6 +330,8 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) { |
| url, content::PermissionType::GEOLOCATION)); |
| EXPECT_TRUE( |
| autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); |
| + histograms.ExpectBucketCount("Permissions.AutoBlocker.EmbargoReason", |
| + PermissionEmbargoReason::REPEATED_DISMISSALS, 1); |
| // Accelerate time forward, check that the embargo status is lifted and the |
| // request won't be automatically blocked. |
| @@ -331,12 +344,26 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) { |
| url, content::PermissionType::GEOLOCATION)); |
| EXPECT_TRUE( |
| autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); |
| + histograms.ExpectBucketCount("Permissions.AutoBlocker.EmbargoReason", |
| + PermissionEmbargoReason::REPEATED_DISMISSALS, 2); |
| + histograms.ExpectBucketCount("Permissions.AutoBlocker.RepeatedEmbargo", |
| + PermissionEmbargoReason::REPEATED_DISMISSALS, 1); |
| // Accelerate time again, check embargo is lifted and another permission |
| // request is let through. |
| clock()->Advance(base::TimeDelta::FromDays(8)); |
| EXPECT_FALSE( |
| autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); |
| + |
| + // Record another dismiss, subsequent requests should be autoblocked again. |
| + EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
| + url, content::PermissionType::GEOLOCATION)); |
| + EXPECT_TRUE( |
| + autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); |
| + histograms.ExpectBucketCount("Permissions.AutoBlocker.EmbargoReason", |
| + PermissionEmbargoReason::REPEATED_DISMISSALS, 3); |
| + histograms.ExpectBucketCount("Permissions.AutoBlocker.RepeatedEmbargo", |
| + PermissionEmbargoReason::REPEATED_DISMISSALS, 2); |
| } |
| // Test the logic for a combination of blacklisting and dismissal embargo. |
| @@ -368,6 +395,7 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiredBlacklistEmbargo) { |
| TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { |
| GURL url("https://www.google.com"); |
| clock()->SetNow(base::Time::Now()); |
| + base::HistogramTester histograms; |
| scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| new MockSafeBrowsingDatabaseManager(false /* perform_callback */); |
| @@ -380,6 +408,10 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { |
| EXPECT_FALSE(last_embargoed_status()); |
| EXPECT_FALSE( |
| autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); |
| + histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| + 1); |
| + histograms.ExpectBucketCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
|
dominickn
2017/01/27 06:05:47
I'm not sure if this bucket check will be racy or
meredithl
2017/01/29 23:48:29
Done.
|
| + SafeBrowsingResponse::TIMEOUT, 1); |
| db_manager->SetPerformCallback(true); |
| SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 2000 /* timeout in ms */); |
| @@ -387,6 +419,13 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { |
| clock()->Advance(base::TimeDelta::FromDays(1)); |
| UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url); |
| EXPECT_TRUE(last_embargoed_status()); |
| + histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| + 2); |
| + histograms.ExpectBucketCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
|
dominickn
2017/01/27 06:05:47
Ditto.
meredithl
2017/01/29 23:48:29
Done.
|
| + SafeBrowsingResponse::BLACKLISTED, 1); |
| + histograms.ExpectBucketCount( |
| + "Permissions.AutoBlocker.EmbargoReason", |
| + PermissionEmbargoReason::PERMISSIONS_BLACKLISTING, 1); |
| clock()->Advance(base::TimeDelta::FromDays(1)); |
| EXPECT_TRUE( |