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

Side by Side Diff: chrome/browser/extensions/api/content_settings/content_settings_store_unittest.cc

Issue 2423003002: Delete fullscreen/mouselock pref data associated with extensions. (Closed)
Patch Set: Fix confusing wording. 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
« no previous file with comments | « chrome/browser/extensions/api/content_settings/content_settings_store.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/extensions/api/content_settings/content_settings_store. h" 5 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/memory/ptr_util.h"
12 #include "base/values.h"
13 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co nstants.h"
14 #include "components/content_settings/core/browser/content_settings_registry.h"
11 #include "components/content_settings/core/browser/content_settings_rule.h" 15 #include "components/content_settings/core/browser/content_settings_rule.h"
12 #include "components/content_settings/core/browser/content_settings_utils.h" 16 #include "components/content_settings/core/browser/content_settings_utils.h"
13 #include "components/content_settings/core/test/content_settings_test_utils.h" 17 #include "components/content_settings/core/test/content_settings_test_utils.h"
14 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h" 20 #include "url/gurl.h"
17 21
18 using ::testing::Mock; 22 using ::testing::Mock;
19 23
20 namespace extensions { 24 namespace extensions {
21 25
26 namespace keys = content_settings_api_constants;
27
22 namespace { 28 namespace {
23 29
24 void CheckRule(const content_settings::Rule& rule, 30 void CheckRule(const content_settings::Rule& rule,
25 const ContentSettingsPattern& primary_pattern, 31 const ContentSettingsPattern& primary_pattern,
26 const ContentSettingsPattern& secondary_pattern, 32 const ContentSettingsPattern& secondary_pattern,
27 ContentSetting setting) { 33 ContentSetting setting) {
28 EXPECT_EQ(primary_pattern.ToString(), rule.primary_pattern.ToString()); 34 EXPECT_EQ(primary_pattern.ToString(), rule.primary_pattern.ToString());
29 EXPECT_EQ(secondary_pattern.ToString(), rule.secondary_pattern.ToString()); 35 EXPECT_EQ(secondary_pattern.ToString(), rule.secondary_pattern.ToString());
30 EXPECT_EQ(setting, content_settings::ValueToContentSetting(rule.value.get())); 36 EXPECT_EQ(setting, content_settings::ValueToContentSetting(rule.value.get()));
31 } 37 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 CheckRule(rules[0], pattern_2, pattern_2, CONTENT_SETTING_BLOCK); 254 CheckRule(rules[0], pattern_2, pattern_2, CONTENT_SETTING_BLOCK);
249 255
250 // Uninstall second extension. 256 // Uninstall second extension.
251 store()->UnregisterExtension(ext_id_2); 257 store()->UnregisterExtension(ext_id_2);
252 258
253 rules = GetSettingsForOneTypeFromStore(store(), CONTENT_SETTINGS_TYPE_COOKIES, 259 rules = GetSettingsForOneTypeFromStore(store(), CONTENT_SETTINGS_TYPE_COOKIES,
254 std::string(), incognito); 260 std::string(), incognito);
255 ASSERT_EQ(0u, rules.size()); 261 ASSERT_EQ(0u, rules.size());
256 } 262 }
257 263
264 TEST_F(ContentSettingsStoreTest, SetFromList) {
265 // Force creation of ContentSettingsRegistry, so that the string to content
266 // setting type lookup can succeed.
267 content_settings::ContentSettingsRegistry::GetInstance();
268
269 ::testing::StrictMock<MockContentSettingsStoreObserver> observer;
270 store()->AddObserver(&observer);
271
272 GURL url("http://www.youtube.com");
273
274 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
275 GetContentSettingFromStore(store(),
276 url,
277 url,
278 CONTENT_SETTINGS_TYPE_COOKIES,
279 std::string(),
280 false));
281
282 // Register first extension
283 std::string ext_id("my_extension");
284 RegisterExtension(ext_id);
285
286 // Set setting via a list
287 ContentSettingsPattern pattern =
288 ContentSettingsPattern::FromURL(GURL("http://www.youtube.com"));
289 EXPECT_CALL(observer, OnContentSettingChanged(ext_id, false));
290
291 // Build a preference list in JSON format.
292 base::ListValue pref_list;
293 // {"primaryPattern": pattern, "secondaryPattern": pattern, "type": "cookies",
294 // "setting": "allow"}
295 auto dict_value = base::MakeUnique<base::DictionaryValue>();
296 dict_value->SetString(keys::kPrimaryPatternKey, pattern.ToString());
297 dict_value->SetString(keys::kSecondaryPatternKey, pattern.ToString());
298 dict_value->SetString(keys::kContentSettingsTypeKey, "cookies");
299 dict_value->SetString(keys::kContentSettingKey, "allow");
300 pref_list.Append(std::move(dict_value));
301 // Test content settings types that have been removed. Should be ignored.
302 // {"primaryPattern": pattern, "secondaryPattern": pattern,
303 // "type": "fullscreen", "setting": "allow"}
304 dict_value = base::MakeUnique<base::DictionaryValue>();
305 dict_value->SetString(keys::kPrimaryPatternKey, pattern.ToString());
306 dict_value->SetString(keys::kSecondaryPatternKey, pattern.ToString());
307 dict_value->SetString(keys::kContentSettingsTypeKey, "fullscreen");
308 dict_value->SetString(keys::kContentSettingKey, "allow");
309 pref_list.Append(std::move(dict_value));
310 // {"primaryPattern": pattern, "secondaryPattern": pattern,
311 // "type": "mouselock", "setting": "allow"}
312 dict_value = base::MakeUnique<base::DictionaryValue>();
313 dict_value->SetString(keys::kPrimaryPatternKey, pattern.ToString());
314 dict_value->SetString(keys::kSecondaryPatternKey, pattern.ToString());
315 dict_value->SetString(keys::kContentSettingsTypeKey, "mouselock");
316 dict_value->SetString(keys::kContentSettingKey, "allow");
317 pref_list.Append(std::move(dict_value));
318
319 store()->SetExtensionContentSettingFromList(ext_id, &pref_list,
320 kExtensionPrefsScopeRegular);
321 Mock::VerifyAndClear(&observer);
322
323 EXPECT_EQ(CONTENT_SETTING_ALLOW,
324 GetContentSettingFromStore(store(),
325 url,
326 url,
327 CONTENT_SETTINGS_TYPE_COOKIES,
328 std::string(),
329 false));
330 // The fullscreen and mouselock settings should have been ignored.
331 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
332 GetContentSettingFromStore(store(),
333 url,
334 url,
335 CONTENT_SETTINGS_TYPE_FULLSCREEN,
336 std::string(),
337 false));
338 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
339 GetContentSettingFromStore(store(),
340 url,
341 url,
342 CONTENT_SETTINGS_TYPE_MOUSELOCK,
343 std::string(),
344 false));
345
346 store()->RemoveObserver(&observer);
347 }
348
258 } // namespace extensions 349 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/content_settings/content_settings_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698