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

Unified Diff: chrome/browser/content_settings/content_settings_pref_provider_unittest.cc

Issue 1005303003: Split the aggregate dictionary of content settings exceptions into per-type dictionaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Memory leak in last test. Created 5 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/content_settings/content_settings_pref_provider_unittest.cc
diff --git a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
index f3811d71f772b9ba6e4955e0be877cac74e99184..0409cc74f15ad3b6f382356d575c8c24d229ac94 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
+++ b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
@@ -43,10 +43,7 @@ class DeadlockCheckerThread : public base::PlatformThread::Delegate {
: provider_(provider) {}
void ThreadMain() override {
- bool got_lock = provider_->content_settings_pref()->lock_.Try();
- EXPECT_TRUE(got_lock);
- if (got_lock)
- provider_->content_settings_pref()->lock_.Release();
+ EXPECT_TRUE(provider_->TestAllLocks());
}
private:
PrefProvider* provider_;
@@ -465,4 +462,276 @@ TEST(PrefProviderTest, LastUsage) {
pref_content_settings_provider.ShutdownOnUIThread();
}
+
+// TODO(msramek): This tests the correct migration behavior between the old
+// aggregate dictionary preferences for all content settings types and the new
+// dictionary preferences for individual types. Remove this when the migration
+// period is over.
+TEST(PrefProviderTest, SyncingOldToNew) {
+ TestingPrefServiceSyncable prefs;
+ PrefProvider::RegisterProfilePrefs(prefs.registry());
+ PrefProvider provider(&prefs, false);
+
+ const std::string pattern = "google.com,*";
+ const std::string resource_id = "abcde12345";
+ base::DictionaryValue* exceptions = new base::DictionaryValue();
+ base::DictionaryValue* plugin_resources = new base::DictionaryValue();
+
+ // Add exceptions for images and app banner.
+ exceptions->SetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_IMAGES), CONTENT_SETTING_ALLOW);
+ exceptions->SetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_ALLOW);
+
+ // Add a regular exception for plugins, then one with a resource identifier.
+ exceptions->SetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_PLUGINS), CONTENT_SETTING_ALLOW);
+ plugin_resources->SetIntegerWithoutPathExpansion(
+ resource_id, CONTENT_SETTING_BLOCK);
+ exceptions->SetWithoutPathExpansion(
+ "per_plugin", plugin_resources);
+
+ // Change the old dictionary preference and observe changes
+ // in the new preferences.
+ {
+ DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
+ base::DictionaryValue* old_dictionary = update.Get();
+ old_dictionary->SetWithoutPathExpansion(pattern, exceptions);
+ }
+
+ // The images exception was synced.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsImagesPatternPairs);
+ const base::DictionaryValue* images_dictionary = update.Get();
+
+ EXPECT_EQ(1u, images_dictionary->size());
+ const base::DictionaryValue* images_exception;
+ EXPECT_TRUE(images_dictionary->GetDictionaryWithoutPathExpansion(
+ pattern, &images_exception));
+
+ // And it has a correct value.
+ int images_exception_value = CONTENT_SETTING_DEFAULT;
+ EXPECT_TRUE(images_exception->GetIntegerWithoutPathExpansion(
+ "setting", &images_exception_value));
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, images_exception_value);
+ }
+
+ // The app banner exception was not synced.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsAppBannerPatternPairs);
+ const base::DictionaryValue* app_banner_dictionary = update.Get();
+ EXPECT_TRUE(app_banner_dictionary->empty());
+ }
+
+ // The plugins exception was synced, together with the resource identifiers.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsPluginsPatternPairs);
+ const base::DictionaryValue* plugins_dictionary = update.Get();
+ EXPECT_EQ(1u, plugins_dictionary->size());
+
+ const base::DictionaryValue* plugins_exception;
+ EXPECT_TRUE(plugins_dictionary->GetDictionaryWithoutPathExpansion(
+ pattern, &plugins_exception));
+
+ int plugins_exception_value = CONTENT_SETTING_DEFAULT;
+ EXPECT_TRUE(plugins_exception->GetIntegerWithoutPathExpansion(
+ "setting", &plugins_exception_value));
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, plugins_exception_value);
+
+ int resource_exception_value = CONTENT_SETTING_DEFAULT;
+ const base::DictionaryValue* resource_exception;
+ EXPECT_TRUE(plugins_exception->GetDictionaryWithoutPathExpansion(
+ "per_resource", &resource_exception));
+ EXPECT_TRUE(resource_exception->GetIntegerWithoutPathExpansion(
+ resource_id, &resource_exception_value));
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, resource_exception_value);
+ }
+
+ provider.ShutdownOnUIThread();
+}
+
+TEST(PrefProviderTest, SyncingNewToOld) {
+ TestingPrefServiceSyncable prefs;
+ PrefProvider::RegisterProfilePrefs(prefs.registry());
+ PrefProvider provider(&prefs, false);
+
+ const std::string pattern = "google.com,*";
+ const std::string resource_id = "abcde12345";
+ base::DictionaryValue block_exception;
+ block_exception.SetIntegerWithoutPathExpansion(
+ "setting", CONTENT_SETTING_BLOCK);
+
+ // Add a mouselock exception.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsMouseLockPatternPairs);
+ base::DictionaryValue* mouselock_dictionary = update.Get();
+
+ mouselock_dictionary->SetWithoutPathExpansion(
+ pattern, block_exception.DeepCopy());
+ }
+
+ // Add a microphone exception.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsMediaStreamMicPatternPairs);
+ base::DictionaryValue* microphone_dictionary = update.Get();
+
+ microphone_dictionary->SetWithoutPathExpansion(
+ pattern, block_exception.DeepCopy());
+ }
+
+ // Add a plugin exception with resource identifiers.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsPluginsPatternPairs);
+ base::DictionaryValue* plugins_dictionary = update.Get();
+
+ base::DictionaryValue* plugin_exception = block_exception.DeepCopy();
+ plugins_dictionary->SetWithoutPathExpansion(
+ pattern, plugin_exception);
+
+ base::DictionaryValue* resource_exception = new base::DictionaryValue();
+ resource_exception->SetIntegerWithoutPathExpansion(
+ resource_id, CONTENT_SETTING_ALLOW);
+
+ plugin_exception->SetWithoutPathExpansion(
+ "per_resource", resource_exception);
+ }
+
+ // Only the notifications and plugin exceptions should appear in the
+ // old dictionary. We should also have a resource identifiers section
+ // for plugins.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsPatternPairs);
+ const base::DictionaryValue* old_dictionary = update.Get();
+
+ const base::DictionaryValue* exception;
+ EXPECT_TRUE(old_dictionary->GetDictionaryWithoutPathExpansion(
+ pattern, &exception));
+ EXPECT_EQ(3u, exception->size());
+ EXPECT_FALSE(exception->HasKey(
+ GetTypeName(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)));
+
+ int mouselock_exception_value = CONTENT_SETTING_DEFAULT;
+ exception->GetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_MOUSELOCK),
+ &mouselock_exception_value);
+ DCHECK_EQ(CONTENT_SETTING_BLOCK, mouselock_exception_value);
+
+ int plugins_exception_value = CONTENT_SETTING_DEFAULT;
+ exception->GetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_PLUGINS),
+ &plugins_exception_value);
+ DCHECK_EQ(CONTENT_SETTING_BLOCK, plugins_exception_value);
+
+ int resource_exception_value = CONTENT_SETTING_DEFAULT;
+ const base::DictionaryValue* resource_values;
+ exception->GetDictionaryWithoutPathExpansion(
+ "per_plugin", &resource_values);
+ resource_values->GetIntegerWithoutPathExpansion(
+ resource_id, &resource_exception_value);
+ DCHECK_EQ(CONTENT_SETTING_ALLOW, resource_exception_value);
+ }
+
+ provider.ShutdownOnUIThread();
+}
+
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
+TEST(PrefProviderTest, PMIMigrateOnlyAllow) {
+ TestingPrefServiceSyncable prefs;
+ PrefProvider::RegisterProfilePrefs(prefs.registry());
+
+ const std::string pattern_1 = "google.com,*";
+ const std::string pattern_2 = "www.google.com,*";
+ base::DictionaryValue* exception_1 = new base::DictionaryValue();
+ base::DictionaryValue* exception_2 = new base::DictionaryValue();
+
+ // Add both an "allow" and "block" exception for PMI.
+ exception_1->SetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER),
+ CONTENT_SETTING_ALLOW);
+ exception_2->SetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER),
+ CONTENT_SETTING_BLOCK);
+
+ // Change the old dictionary preference.
+ {
+ DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
+ base::DictionaryValue* old_dictionary = update.Get();
+ old_dictionary->SetWithoutPathExpansion(pattern_1, exception_1);
+ old_dictionary->SetWithoutPathExpansion(pattern_2, exception_2);
+ }
+
+ // Create the PrefProvider. It should migrate the settings.
+ PrefProvider provider(&prefs, false);
+
+ // The "block" exception for PMI was migrated, but "allow" was not.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsProtectedMediaIdentifierPatternPairs);
+ const base::DictionaryValue* pmi_dictionary = update.Get();
+ EXPECT_FALSE(pmi_dictionary->HasKey(pattern_1));
+ EXPECT_TRUE(pmi_dictionary->HasKey(pattern_2));
+ }
+
+ provider.ShutdownOnUIThread();
+}
+#endif
+
+TEST(PrefProviderTest, PrefsMigrateVerbatim) {
+ TestingPrefServiceSyncable prefs;
+ PrefProvider::RegisterProfilePrefs(prefs.registry());
+
+ const std::string pattern_1 = "google.com,*";
+ const std::string pattern_2 = "www.google.com,*";
+ base::DictionaryValue* exception_1 = new base::DictionaryValue();
+ base::DictionaryValue* exception_2 = new base::DictionaryValue();
+ scoped_ptr<base::DictionaryValue> old_dictionary;
+
+ // Add two exceptions.
+ exception_1->SetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_COOKIES),
+ CONTENT_SETTING_ALLOW);
+ exception_2->SetIntegerWithoutPathExpansion(
+ GetTypeName(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS),
+ CONTENT_SETTING_BLOCK);
+
+ // Change the old dictionary preference.
+ {
+ DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
+ base::DictionaryValue* dictionary = update.Get();
+ dictionary->SetWithoutPathExpansion(pattern_1, exception_1);
+ dictionary->SetWithoutPathExpansion(pattern_2, exception_2);
+ old_dictionary.reset(dictionary->DeepCopy());
+ }
+
+ // Create the PrefProvider. It should copy the settings from the old
+ // preference to the new ones.
+ PrefProvider provider(&prefs, false);
+
+ // Force copying back from the new preferences to the old one.
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsCookiesPatternPairs);
+ }
+ {
+ DictionaryPrefUpdate update(
+ &prefs, prefs::kContentSettingsAutomaticDownloadsPatternPairs);
+ }
+
+ // Test if the value after copying there and back is the same.
+ {
+ DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
+ base::DictionaryValue* new_dictionary = update.Get();
+ EXPECT_TRUE(old_dictionary->Equals(new_dictionary));
+ }
+
+ provider.ShutdownOnUIThread();
+}
+
} // namespace content_settings

Powered by Google App Engine
This is Rietveld 408576698