| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/content_settings/core/browser/content_settings_pref_provide
r.h" | 5 #include "components/content_settings/core/browser/content_settings_pref_provide
r.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 pref_content_settings_provider.AddObserver(&mock_observer); | 125 pref_content_settings_provider.AddObserver(&mock_observer); |
| 126 | 126 |
| 127 pref_content_settings_provider.SetWebsiteSetting( | 127 pref_content_settings_provider.SetWebsiteSetting( |
| 128 pattern, ContentSettingsPattern::Wildcard(), | 128 pattern, ContentSettingsPattern::Wildcard(), |
| 129 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 129 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 130 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 130 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); |
| 131 | 131 |
| 132 pref_content_settings_provider.ShutdownOnUIThread(); | 132 pref_content_settings_provider.ShutdownOnUIThread(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Tests that fullscreen and mouselock content settings are cleared. |
| 136 TEST_F(PrefProviderTest, DiscardObsoletePreferences) { |
| 137 static const char kFullscreenPrefPath[] = |
| 138 "profile.content_settings.exceptions.fullscreen"; |
| 139 #if !defined(OS_ANDROID) |
| 140 static const char kMouselockPrefPath[] = |
| 141 "profile.content_settings.exceptions.mouselock"; |
| 142 #endif |
| 143 static const char kGeolocationPrefPath[] = |
| 144 "profile.content_settings.exceptions.geolocation"; |
| 145 static const char kPattern[] = "[*.]example.com"; |
| 146 |
| 147 TestingProfile profile; |
| 148 PrefService* prefs = profile.GetPrefs(); |
| 149 |
| 150 // Set some pref data. Each content setting type has the following value: |
| 151 // {"[*.]example.com": {"setting": 1}} |
| 152 base::DictionaryValue pref_data; |
| 153 auto data_for_pattern = base::MakeUnique<base::DictionaryValue>(); |
| 154 data_for_pattern->SetInteger("setting", CONTENT_SETTING_ALLOW); |
| 155 pref_data.SetWithoutPathExpansion(kPattern, std::move(data_for_pattern)); |
| 156 prefs->Set(kFullscreenPrefPath, pref_data); |
| 157 #if !defined(OS_ANDROID) |
| 158 prefs->Set(kMouselockPrefPath, pref_data); |
| 159 #endif |
| 160 prefs->Set(kGeolocationPrefPath, pref_data); |
| 161 |
| 162 // Instantiate a new PrefProvider here, because we want to test the |
| 163 // constructor's behavior after setting the above. |
| 164 PrefProvider provider(prefs, false); |
| 165 provider.ShutdownOnUIThread(); |
| 166 |
| 167 // Check that fullscreen and mouselock have been reset back to defaults. |
| 168 // TODO(mgiuca): These should be fully deleted, except that they keep being |
| 169 // recreated due to the content settings enum still existing. Delete the enum, |
| 170 // then update this test to expect full deletion. https://crbug.com/591896. |
| 171 // EXPECT_FALSE(prefs->HasPrefPath(kFullscreenPrefPath)); |
| 172 // EXPECT_FALSE(prefs->HasPrefPath(kMouselockPrefPath)); |
| 173 GURL primary_url("http://example.com/"); |
| 174 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 175 TestUtils::GetContentSetting(&provider, primary_url, primary_url, |
| 176 CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| 177 std::string(), false)); |
| 178 #if !defined(OS_ANDROID) |
| 179 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 180 TestUtils::GetContentSetting(&provider, primary_url, primary_url, |
| 181 CONTENT_SETTINGS_TYPE_MOUSELOCK, |
| 182 std::string(), false)); |
| 183 #endif |
| 184 EXPECT_TRUE(prefs->HasPrefPath(kGeolocationPrefPath)); |
| 185 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 186 TestUtils::GetContentSetting(&provider, primary_url, primary_url, |
| 187 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 188 std::string(), false)); |
| 189 } |
| 190 |
| 135 // Test for regression in which the PrefProvider modified the user pref store | 191 // Test for regression in which the PrefProvider modified the user pref store |
| 136 // of the OTR unintentionally: http://crbug.com/74466. | 192 // of the OTR unintentionally: http://crbug.com/74466. |
| 137 TEST_F(PrefProviderTest, Incognito) { | 193 TEST_F(PrefProviderTest, Incognito) { |
| 138 PersistentPrefStore* user_prefs = new TestingPrefStore(); | 194 PersistentPrefStore* user_prefs = new TestingPrefStore(); |
| 139 OverlayUserPrefStore* otr_user_prefs = | 195 OverlayUserPrefStore* otr_user_prefs = |
| 140 new OverlayUserPrefStore(user_prefs); | 196 new OverlayUserPrefStore(user_prefs); |
| 141 | 197 |
| 142 sync_preferences::PrefServiceMockFactory factory; | 198 sync_preferences::PrefServiceMockFactory factory; |
| 143 factory.set_user_prefs(make_scoped_refptr(user_prefs)); | 199 factory.set_user_prefs(make_scoped_refptr(user_prefs)); |
| 144 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( | 200 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 for (const char* pref : nonempty_prefs) { | 578 for (const char* pref : nonempty_prefs) { |
| 523 DictionaryPrefUpdate update(&prefs, pref); | 579 DictionaryPrefUpdate update(&prefs, pref); |
| 524 const base::DictionaryValue* dictionary = update.Get(); | 580 const base::DictionaryValue* dictionary = update.Get(); |
| 525 EXPECT_EQ(1u, dictionary->size()); | 581 EXPECT_EQ(1u, dictionary->size()); |
| 526 } | 582 } |
| 527 | 583 |
| 528 provider.ShutdownOnUIThread(); | 584 provider.ShutdownOnUIThread(); |
| 529 } | 585 } |
| 530 | 586 |
| 531 } // namespace content_settings | 587 } // namespace content_settings |
| OLD | NEW |