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

Unified Diff: chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc

Issue 2678253002: Add metrics for Safe Browsing blacklist response. (Closed)
Patch Set: Rebase Created 3 years, 10 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: 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 04b412c312322369509e8e1df5b85c8b52bd7e98..061a905ef54f1cc7fa68f21296235c8752f601de 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"
@@ -265,6 +267,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 */,
@@ -277,6 +280,33 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestUpdateEmbargoBlacklist) {
UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url);
EXPECT_TRUE(callback_was_run());
EXPECT_TRUE(last_embargoed_status());
+ histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse",
+ SafeBrowsingResponse::BLACKLISTED, 1);
+ histograms.ExpectTotalCount(
+ "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1);
+}
+
+// Test that an origin that is blacklisted for a permission will not be placed
+// under embargoed for another.
+TEST_F(PermissionDecisionAutoBlockerUnitTest, TestRequestNotBlacklisted) {
+ GURL url("https://www.google.com");
+ clock()->SetNow(base::Time::Now());
+ base::HistogramTester histograms;
+
+ scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager =
+ new MockSafeBrowsingDatabaseManager(true /* perform_callback */,
+ true /* enabled */);
+ std::set<std::string> blacklisted_permissions{"GEOLOCATION"};
+ db_manager->BlacklistUrlPermissions(url, blacklisted_permissions);
+ SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager,
+ 0 /* timeout in ms */);
+
+ UpdateEmbargoedStatus(content::PermissionType::NOTIFICATIONS, url);
+ EXPECT_FALSE(last_embargoed_status());
+ histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse",
+ SafeBrowsingResponse::NOT_BLACKLISTED, 1);
+ histograms.ExpectTotalCount(
+ "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1);
}
// Check that IsUnderEmbargo returns the correct value when the embargo is set
@@ -325,6 +355,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(
@@ -342,6 +373,10 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) {
EXPECT_TRUE(
autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url));
+ histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse",
+ 0);
+ histograms.ExpectTotalCount(
+ "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0);
// Accelerate time forward, check that the embargo status is lifted and the
// request won't be automatically blocked.
clock()->Advance(base::TimeDelta::FromDays(8));
@@ -359,6 +394,16 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) {
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.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse",
+ 0);
+ histograms.ExpectTotalCount(
+ "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0);
}
// Test the logic for a combination of blacklisting and dismissal embargo.
@@ -390,6 +435,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 */,
@@ -404,6 +450,10 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) {
EXPECT_FALSE(last_embargoed_status());
EXPECT_FALSE(
autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url));
+ histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse",
+ SafeBrowsingResponse::TIMEOUT, 1);
+ histograms.ExpectTotalCount(
+ "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1);
db_manager->SetPerformCallback(true);
SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager,
2000 /* timeout in ms */);
@@ -412,7 +462,12 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) {
UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url);
EXPECT_TRUE(callback_was_run());
EXPECT_TRUE(last_embargoed_status());
-
+ histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse",
+ 2);
+ histograms.ExpectTotalCount(
+ "Permissions.AutoBlocker.SafeBrowsingResponseTime", 2);
+ histograms.ExpectBucketCount("Permissions.AutoBlocker.SafeBrowsingResponse",
+ SafeBrowsingResponse::BLACKLISTED, 1);
clock()->Advance(base::TimeDelta::FromDays(1));
EXPECT_TRUE(
autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url));
@@ -505,3 +560,22 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDisabledDatabaseManager) {
EXPECT_TRUE(callback_was_run());
EXPECT_FALSE(last_embargoed_status());
}
+
+TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingResponse) {
+ GURL url("https://www.google.com");
+ clock()->SetNow(base::Time::Now());
+ base::HistogramTester histograms;
+
+ scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager =
+ new MockSafeBrowsingDatabaseManager(true /* perform_callback */,
+ true /* enabled */);
+ std::set<std::string> blacklisted_permissions{"GEOLOCATION"};
+ db_manager->BlacklistUrlPermissions(url, blacklisted_permissions);
+ SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager,
+ 0 /* timeout in ms */);
+
+ UpdateEmbargoedStatus(content::PermissionType::NOTIFICATIONS, url);
+ EXPECT_FALSE(last_embargoed_status());
+ histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse",
+ SafeBrowsingResponse::NOT_BLACKLISTED, 1);
+}
« no previous file with comments | « chrome/browser/permissions/permission_blacklist_client.cc ('k') | chrome/browser/permissions/permission_uma_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698