Elim cr-checkbox
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / content_settings / standard / test.js
blob856ff20559b1c0ff0111fbc5091ca00426c00cce
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",
11 "images": "allow",
12 "javascript": "block",
13 "plugins": "allow",
14 "popups": "block",
15 "location": "ask",
16 "notifications": "ask",
17 "fullscreen": "ask",
18 "mouselock": "ask",
19 "microphone": "ask",
20 "camera": "ask",
21 "unsandboxedPlugins": "ask",
22 "automaticDownloads": "ask"
25 var settings = {
26 "cookies": "block",
27 "images": "allow",
28 "javascript": "block",
29 "plugins": "detect_important_content",
30 "popups": "allow",
31 "location": "block",
32 "notifications": "block",
33 "fullscreen": "allow",
34 "mouselock": "block",
35 "microphone": "block",
36 "camera": "block",
37 "unsandboxedPlugins": "block",
38 "automaticDownloads": "block"
41 Object.prototype.forEach = function(f) {
42 var k;
43 for (k in this) {
44 if (this.hasOwnProperty(k))
45 f(k, this[k]);
49 function expect(expected, message) {
50 return chrome.test.callbackPass(function(value) {
51 chrome.test.assertEq(expected, value, message);
52 });
55 function expectFalse(message) {
56 return expect({
57 "value": false,
58 "levelOfControl": "controllable_by_this_extension"
59 }, message);
62 chrome.test.runTests([
63 function setDefaultContentSettings() {
64 default_content_settings.forEach(function(type, setting) {
65 cs[type].set({
66 'primaryPattern': '<all_urls>',
67 'secondaryPattern': '<all_urls>',
68 'setting': setting
69 }, chrome.test.callbackPass());
70 });
72 function setContentSettings() {
73 settings.forEach(function(type, setting) {
74 cs[type].set({
75 'primaryPattern': 'http://*.google.com/*',
76 'secondaryPattern': 'http://*.google.com/*',
77 'setting': setting
78 }, chrome.test.callbackPass());
79 });
81 function getContentSettings() {
82 settings.forEach(function(type, setting) {
83 var message = "Setting for " + type + " should be " + setting;
84 cs[type].get({
85 'primaryUrl': 'http://www.google.com',
86 'secondaryUrl': 'http://www.google.com'
87 }, expect({'setting':setting}, message));
88 });
90 function invalidSettings() {
91 cs.cookies.get({
92 'primaryUrl': 'moo'
93 }, chrome.test.callbackFail("The URL \"moo\" is invalid."));
94 cs.plugins.set({
95 'primaryPattern': 'http://example.com/*',
96 'secondaryPattern': 'http://example.com/path',
97 'setting': 'block'
98 }, chrome.test.callbackFail("Specific paths are not allowed."));
99 cs.javascript.set({
100 'primaryPattern': 'http://example.com/*',
101 'secondaryPattern': 'file:///home/hansmoleman/*',
102 'setting': 'allow'
103 }, chrome.test.callbackFail(
104 "Path wildcards in file URL patterns are not allowed."));