| 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..df926c6d9acb9c20ab123f54bdac760b78476124 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,155 @@ 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,*";
|
| + base::DictionaryValue* exceptions = 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);
|
| +
|
| + // 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());
|
| + }
|
| +
|
| + 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 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());
|
| + }
|
| +
|
| + // 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 mouselock_exception_value = CONTENT_SETTING_DEFAULT;
|
| + exception->GetIntegerWithoutPathExpansion(
|
| + GetTypeName(CONTENT_SETTINGS_TYPE_MOUSELOCK),
|
| + &mouselock_exception_value);
|
| + DCHECK_EQ(CONTENT_SETTING_BLOCK, mouselock_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
|
| +
|
| } // namespace content_settings
|
|
|