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

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

Issue 2651123002: Migrate content setting PROMPT_NO_DECISION_COUNT to PERMISSION_AUTOBLOCKER_DATA (Closed)
Patch Set: Rename pref Created 3 years, 11 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 dfc0242e28c5a2db446de20fde5beed451d46c60..e1ddba59ba1235f5fb21aaeaf13f7feb2ea5a214 100644
--- a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
+++ b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/safe_browsing_db/test_database_manager.h"
#include "content/public/browser/permission_type.h"
@@ -131,6 +132,14 @@ class PermissionDecisionAutoBlockerUnitTest
base::SimpleTestClock* clock() { return clock_; }
+ const char* GetDismissKey() {
+ return PermissionDecisionAutoBlocker::kPromptDismissCountKey;
+ }
+
+ const char* GetIgnoreKey() {
+ return PermissionDecisionAutoBlocker::kPromptIgnoreCountKey;
+ }
+
private:
PermissionDecisionAutoBlocker* autoblocker_;
base::test::ScopedFeatureList feature_list_;
@@ -392,3 +401,75 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) {
EXPECT_TRUE(
autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url));
}
+
+// TODO(raymes): See crbug.com/681709. Remove after M60.
+TEST_F(PermissionDecisionAutoBlockerUnitTest,
+ MigrateNoDecisionCountToPermissionAutoBlockerData) {
+ GURL url("https://www.google.com");
+ auto* map = HostContentSettingsMapFactory::GetForProfile(profile());
+
+ // Write to the old content setting.
+ base::DictionaryValue permissions_dict;
+ permissions_dict.SetInteger(GetDismissKey(), 100);
+ permissions_dict.SetInteger(GetIgnoreKey(), 50);
+
+ base::DictionaryValue origin_dict;
+ origin_dict.Set(
+ PermissionUtil::GetPermissionString(content::PermissionType::GEOLOCATION),
+ permissions_dict.CreateDeepCopy());
+ map->SetWebsiteSettingDefaultScope(
+ url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT,
+ std::string(), origin_dict.CreateDeepCopy());
+
+ // Nothing should be migrated yet, so the current values should be 0.
+ EXPECT_EQ(0, autoblocker()->GetDismissCount(
+ url, content::PermissionType::GEOLOCATION));
+ EXPECT_EQ(0, autoblocker()->GetIgnoreCount(
+ url, content::PermissionType::GEOLOCATION));
+
+ // Trigger pref migration which happens at the creation of the
+ // HostContentSettingsMap.
+ {
+ scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap(
+ profile()->GetPrefs(), false /* is_incognito_profile */,
+ false /* is_guest_profile */));
+ temp_map->ShutdownOnUIThread();
+ }
+
+ // The values should now be migrated.
+ EXPECT_EQ(100, autoblocker()->GetDismissCount(
+ url, content::PermissionType::GEOLOCATION));
+ EXPECT_EQ(50, autoblocker()->GetIgnoreCount(
+ url, content::PermissionType::GEOLOCATION));
+
+ // The old pref should be deleted.
+ std::unique_ptr<base::DictionaryValue> old_dict =
+ base::DictionaryValue::From(map->GetWebsiteSetting(
+ url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT,
+ std::string(), nullptr));
+ EXPECT_EQ(nullptr, old_dict);
+
+ // Write to the old content setting again, but with different numbers.
+ permissions_dict.SetInteger(GetDismissKey(), 99);
+ permissions_dict.SetInteger(GetIgnoreKey(), 99);
+
+ origin_dict.Set(
+ PermissionUtil::GetPermissionString(content::PermissionType::GEOLOCATION),
+ permissions_dict.CreateDeepCopy());
+ map->SetWebsiteSettingDefaultScope(
+ url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT,
+ std::string(), origin_dict.CreateDeepCopy());
+
+ // Ensure that migrating again does nothing.
+ {
+ scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap(
+ profile()->GetPrefs(), false /* is_incognito_profile */,
+ false /* is_guest_profile */));
+ temp_map->ShutdownOnUIThread();
+ }
+
+ EXPECT_EQ(100, autoblocker()->GetDismissCount(
+ url, content::PermissionType::GEOLOCATION));
+ EXPECT_EQ(50, autoblocker()->GetIgnoreCount(
+ url, content::PermissionType::GEOLOCATION));
+}

Powered by Google App Engine
This is Rietveld 408576698