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

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

Issue 2790473004: Permissions: Clear embargo if user changes an embargoed permission's setting. (Closed)
Patch Set: Created 3 years, 9 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 e62eebb311866c64f25fb678d187034dc6c8854e..3275731deeeb65e5130bb1cd67fce18dc8441d27 100644
--- a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
+++ b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
@@ -159,6 +159,127 @@ class PermissionDecisionAutoBlockerUnitTest
bool callback_was_run_;
};
+// Check removing the the emargo for a single permission on a site works, and
dominickn 2017/04/03 01:35:31 sp. embargo
Patti Lor 2017/04/05 08:34:27 Done.
+// that it doesn't interfere with other embargoed permissions or the same
+// permission embargoed on other sites.
+TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveEmbargoByURL) {
dominickn 2017/04/03 01:35:30 Url
Patti Lor 2017/04/05 08:34:27 Done.
+ GURL url1("https://www.google.com");
+ GURL url2("https://www.example.com");
+
+ // Record dismissals for location and notifications in |url1|.
+ autoblocker()->RecordDismissAndEmbargo(url1,
dominickn 2017/04/03 01:35:31 I'd EXPECT_FALSE / EXPECT_TRUE all of these calls
Patti Lor 2017/04/05 08:34:27 Done.
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url1,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url1,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url1,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url1,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ autoblocker()->RecordDismissAndEmbargo(url1,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ autoblocker()->RecordDismissAndEmbargo(url1,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ autoblocker()->RecordDismissAndEmbargo(url1,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ // Record dismissals for location in |url2|.
+ autoblocker()->RecordDismissAndEmbargo(url2,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url2,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url2,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url2,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+
+ // Verify all dismissals recorded above resulted in embargo.
+ PermissionResult result =
+ autoblocker()->GetEmbargoResult(url1, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source);
+ result = autoblocker()->GetEmbargoResult(url1,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source);
+ result =
+ autoblocker()->GetEmbargoResult(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source);
+
+ // Remove the embargo on notifications. Verify it is no longer under embargo,
+ // but location still is.
+ autoblocker()->RemoveEmbargoByURL(url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ result =
+ autoblocker()->GetEmbargoResult(url1, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source);
+ // Notification's default setting is |CONTENT_SETTING_ASK|.
+ result = autoblocker()->GetEmbargoResult(url1,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source);
+ // Verify |url2|'s embargo is still intact as well.
+ result =
+ autoblocker()->GetEmbargoResult(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source);
+}
+
+// Test that removing embargo from blacklisted permissions also works.
+TEST_F(PermissionDecisionAutoBlockerUnitTest,
+ RemoveEmbargoByURLForBlacklistedPermission) {
+ GURL url("https://www.example.com");
+
+ // Place under embargo and verify.
+ PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ PermissionResult result =
+ autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source);
+
+ // Remove embargo and verify.
+ autoblocker()->RemoveEmbargoByURL(url, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ result =
+ autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source);
+}
+
+// Test it still only takes one more dismissal to re-trigger embargo after
+// removing the embargo status for a site.
+TEST_F(PermissionDecisionAutoBlockerUnitTest,
+ DismissAfterRemovingEmbargoByURL) {
+ GURL url("https://www.example.com");
+
+ // Record dismissals for location.
+ autoblocker()->RecordDismissAndEmbargo(url,
dominickn 2017/04/03 01:35:31 EXPECT_TRUE / EXPECT_FALSE these calls
Patti Lor 2017/04/05 08:34:27 Done.
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ autoblocker()->RecordDismissAndEmbargo(url,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+
+ // Verify location is under embargo.
+ PermissionResult result =
+ autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source);
+
+ // Remove embargo.
+ autoblocker()->RemoveEmbargoByURL(url, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+
dominickn 2017/04/03 01:35:31 Nit: verify that it's not under embargo here
Patti Lor 2017/04/05 08:34:27 Done.
+ // Record another dismissal and verify location is under embargo again.
+ autoblocker()->RecordDismissAndEmbargo(url,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ result =
+ autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting);
+ EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source);
+}
+
TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) {
GURL url1("https://www.google.com");
GURL url2("https://www.example.com");

Powered by Google App Engine
This is Rietveld 408576698