1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Content settings API test
6 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings
8 var cs = chrome.contentSettings;
9 var default_content_settings = {
10 "cookies": "session_only",
12 "javascript": "block",
16 "notifications": "ask",
19 "unsandboxedPlugins": "ask",
20 "automaticDownloads": "ask"
26 "javascript": "block",
27 "plugins": "detect_important_content",
30 "notifications": "block",
31 "fullscreen": "allow",
33 "unsandboxedPlugins": "block",
34 "automaticDownloads": "block"
37 Object.prototype.forEach = function(f) {
40 if (this.hasOwnProperty(k))
45 function expect(expected, message) {
46 return chrome.test.callbackPass(function(value) {
47 chrome.test.assertEq(expected, value, message);
51 function expectFalse(message) {
54 "levelOfControl": "controllable_by_this_extension"
58 chrome.test.runTests([
59 function setDefaultContentSettings() {
60 default_content_settings.forEach(function(type, setting) {
62 'primaryPattern': '<all_urls>',
63 'secondaryPattern': '<all_urls>',
65 }, chrome.test.callbackPass());
68 function setContentSettings() {
69 settings.forEach(function(type, setting) {
71 'primaryPattern': 'http://*.google.com/*',
72 'secondaryPattern': 'http://*.google.com/*',
74 }, chrome.test.callbackPass());
77 function getContentSettings() {
78 settings.forEach(function(type, setting) {
79 var message = "Setting for " + type + " should be " + setting;
81 'primaryUrl': 'http://www.google.com',
82 'secondaryUrl': 'http://www.google.com'
83 }, expect({'setting':setting}, message));
86 function invalidSettings() {
89 }, chrome.test.callbackFail("The URL \"moo\" is invalid."));
91 'primaryPattern': 'http://example.com/*',
92 'secondaryPattern': 'http://example.com/path',
94 }, chrome.test.callbackFail("Specific paths are not allowed."));
96 'primaryPattern': 'http://example.com/*',
97 'secondaryPattern': 'file:///home/hansmoleman/*',
99 }, chrome.test.callbackFail(
100 "Path wildcards in file URL patterns are not allowed."));