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

Side by Side Diff: chrome/browser/content_settings/content_settings_pref_provider_unittest.cc

Issue 2428433002: Delete fullscreen/mouselock pref data. (Closed)
Patch Set: Fix test by avoiding JS update calls. Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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
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 static const char kMouselockPrefPath[] =
140 "profile.content_settings.exceptions.mouselock";
141 static const char kGeolocationPrefPath[] =
142 "profile.content_settings.exceptions.geolocation";
143 static const char kPattern[] = "[*.]example.com";
144
145 TestingProfile profile;
146 PrefService* prefs = profile.GetPrefs();
147
148 // Set some pref data. Each content setting type has the following value:
149 // {"[*.]example.com": {"setting": 1}}
150 base::DictionaryValue pref_data;
151 auto data_for_pattern = base::MakeUnique<base::DictionaryValue>();
152 data_for_pattern->SetInteger("setting", CONTENT_SETTING_ALLOW);
153 pref_data.SetWithoutPathExpansion(kPattern, std::move(data_for_pattern));
154 prefs->Set(kFullscreenPrefPath, pref_data);
155 prefs->Set(kMouselockPrefPath, pref_data);
156 prefs->Set(kGeolocationPrefPath, pref_data);
157
158 // Instantiate a new PrefProvider here, because we want to test the
159 // constructor's behavior after setting the above.
160 PrefProvider provider(prefs, false);
161 provider.ShutdownOnUIThread();
162
163 // Check that fullscreen and mouselock have been reset back to defaults.
164 // TODO(mgiuca): These should be fully deleted, except that they keep being
165 // recreated due to the content settings enum still existing. Delete the enum,
166 // then update this test to expect full deletion. https://crbug.com/591896.
167 // EXPECT_FALSE(prefs->HasPrefPath(kFullscreenPrefPath));
168 // EXPECT_FALSE(prefs->HasPrefPath(kMouselockPrefPath));
169 GURL primary_url("http://example.com/");
170 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
171 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
172 CONTENT_SETTINGS_TYPE_FULLSCREEN,
173 std::string(), false));
174 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
175 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
176 CONTENT_SETTINGS_TYPE_MOUSELOCK,
177 std::string(), false));
178 EXPECT_TRUE(prefs->HasPrefPath(kGeolocationPrefPath));
179 EXPECT_EQ(CONTENT_SETTING_ALLOW,
180 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
181 CONTENT_SETTINGS_TYPE_GEOLOCATION,
182 std::string(), false));
183 }
184
135 // Test for regression in which the PrefProvider modified the user pref store 185 // Test for regression in which the PrefProvider modified the user pref store
136 // of the OTR unintentionally: http://crbug.com/74466. 186 // of the OTR unintentionally: http://crbug.com/74466.
137 TEST_F(PrefProviderTest, Incognito) { 187 TEST_F(PrefProviderTest, Incognito) {
138 PersistentPrefStore* user_prefs = new TestingPrefStore(); 188 PersistentPrefStore* user_prefs = new TestingPrefStore();
139 OverlayUserPrefStore* otr_user_prefs = 189 OverlayUserPrefStore* otr_user_prefs =
140 new OverlayUserPrefStore(user_prefs); 190 new OverlayUserPrefStore(user_prefs);
141 191
142 syncable_prefs::PrefServiceMockFactory factory; 192 syncable_prefs::PrefServiceMockFactory factory;
143 factory.set_user_prefs(make_scoped_refptr(user_prefs)); 193 factory.set_user_prefs(make_scoped_refptr(user_prefs));
144 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 194 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 for (const char* pref : nonempty_prefs) { 572 for (const char* pref : nonempty_prefs) {
523 DictionaryPrefUpdate update(&prefs, pref); 573 DictionaryPrefUpdate update(&prefs, pref);
524 const base::DictionaryValue* dictionary = update.Get(); 574 const base::DictionaryValue* dictionary = update.Get();
525 EXPECT_EQ(1u, dictionary->size()); 575 EXPECT_EQ(1u, dictionary->size());
526 } 576 }
527 577
528 provider.ShutdownOnUIThread(); 578 provider.ShutdownOnUIThread();
529 } 579 }
530 580
531 } // namespace content_settings 581 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698