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..403a0f0ce834e0028a1efd2360a682cc88bd3965 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,132 @@ 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_1 = "google.com,*"; |
+ const std::string pattern_2 = "www.google.com,*"; |
+ base::DictionaryValue* exceptions_1 = new base::DictionaryValue(); |
+ base::DictionaryValue* exceptions_2 = new base::DictionaryValue(); |
+ |
+ // Add exceptions for images and app banner. |
+ exceptions_1->SetIntegerWithoutPathExpansion( |
+ GetTypeName(CONTENT_SETTINGS_TYPE_IMAGES), CONTENT_SETTING_ALLOW); |
+ exceptions_1->SetIntegerWithoutPathExpansion( |
+ GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_ALLOW); |
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
+ // Add both an "allow" and "block" exception for PMI. |
+ exceptions_1->SetIntegerWithoutPathExpansion( |
+ GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_ALLOW); |
+ exceptions_2->SetIntegerWithoutPathExpansion( |
+ GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_BLOCK); |
+#endif |
+ |
+ // 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_1, exceptions_1); |
+ old_dictionary->SetWithoutPathExpansion(pattern_2, exceptions_2); |
+ } |
+ |
+ // 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_1, &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); |
+ base::DictionaryValue* app_banner_dictionary = update.Get(); |
+ EXPECT_TRUE(app_banner_dictionary->empty()); |
+ } |
+ |
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
+ // The "block" exception for PMI was migrated, but "allow" was not. |
+ DictionaryPrefUpdate update( |
+ &prefs, prefs::kContentSettingsProtectedMediaIdentifierPatternPairs); |
+ const base::DictionaryValue* pmi_dictionary = update.Get(); |
+ EXPECT_TRUE(pmi_dictionary->HasKey(pattern_1)); |
+ EXPECT_FALSE(pmi_dictionary->HasKey(pattern_2)); |
+#endif |
+ |
+ provider.ShutdownOnUIThread(); |
+} |
+ |
+TEST(PrefProviderTest, SyncingNewToOld) { |
+ TestingPrefServiceSyncable prefs; |
+ PrefProvider::RegisterProfilePrefs(prefs.registry()); |
+ PrefProvider provider(&prefs, false); |
+ |
+ const std::string pattern = "google.com,*"; |
+ base::DictionaryValue block_exception; |
+ block_exception.SetIntegerWithoutPathExpansion( |
+ "setting", CONTENT_SETTING_BLOCK); |
+ |
+ // Add a notifications exception. |
+ { |
+ DictionaryPrefUpdate update( |
+ &prefs, prefs::kContentSettingsNotificationsPatternPairs); |
+ base::DictionaryValue* notifications_dictionary = update.Get(); |
+ |
+ notifications_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()); |
+ } |
+ |
+ // Only the notifications exception should appear in the old dictionary. |
+ { |
+ 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(1u, exception->size()); |
+ EXPECT_FALSE(exception->HasKey( |
+ GetTypeName(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC))); |
+ |
+ int notifications_exception_value = CONTENT_SETTING_DEFAULT; |
+ exception->GetIntegerWithoutPathExpansion( |
+ GetTypeName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS), |
+ ¬ifications_exception_value); |
+ DCHECK_EQ(CONTENT_SETTING_BLOCK, notifications_exception_value); |
+ } |
+ |
+ provider.ShutdownOnUIThread(); |
+} |
+ |
} // namespace content_settings |