OLD | NEW |
1 <script> | 1 <!-- |
2 // Content settings API test | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
3 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings | 3 * source code is governed by a BSD-style license that can be found in the |
4 | 4 * LICENSE file. |
5 var cs = chrome.contentSettings; | 5 --> |
6 var default_content_settings = { | 6 <script src="test.js"></script> |
7 "cookies": "session_only", | |
8 "images": "allow", | |
9 "javascript": "block", | |
10 "plugins": "allow", | |
11 "popups": "block", | |
12 // TODO(bauerb) | |
13 // "geolocation": "ask", | |
14 "notifications": "ask" | |
15 }; | |
16 | |
17 var settings = { | |
18 "cookies": "block", | |
19 "images": "allow", | |
20 "javascript": "block", | |
21 "plugins": "block", | |
22 "popups": "allow", | |
23 // "geolocation": "block", | |
24 "notifications": "block" | |
25 }; | |
26 | |
27 Object.prototype.forEach = function(f) { | |
28 var k; | |
29 for (k in this) { | |
30 if (this.hasOwnProperty(k)) | |
31 f(k, this[k]); | |
32 } | |
33 }; | |
34 | |
35 function expect(expected, message) { | |
36 return chrome.test.callbackPass(function(value) { | |
37 chrome.test.assertEq(expected, value, message); | |
38 }); | |
39 } | |
40 | |
41 function expectFalse(message) { | |
42 return expect({ | |
43 "value": false, | |
44 "levelOfControl": "controllable_by_this_extension" | |
45 }, message); | |
46 } | |
47 | |
48 chrome.test.runTests([ | |
49 function setDefaultContentSettings() { | |
50 default_content_settings.forEach(function(type, setting) { | |
51 cs[type].set({ | |
52 'primaryPattern': '<all_urls>', | |
53 'secondaryPattern': '<all_urls>', | |
54 'setting': setting | |
55 }, chrome.test.callbackPass()); | |
56 }); | |
57 }, | |
58 function setContentSettings() { | |
59 settings.forEach(function(type, setting) { | |
60 cs[type].set({ | |
61 'primaryPattern': 'http://*.google.com/*', | |
62 'secondaryPattern': 'http://*.google.com/*', | |
63 'setting': setting | |
64 }, chrome.test.callbackPass()); | |
65 }); | |
66 }, | |
67 function getContentSettings() { | |
68 settings.forEach(function(type, setting) { | |
69 var message = "Setting for " + type + " should be " + setting; | |
70 cs[type].get({ | |
71 'primaryUrl': 'http://www.google.com', | |
72 'secondaryUrl': 'http://www.google.com' | |
73 }, expect({'setting':setting}, message)); | |
74 }); | |
75 }, | |
76 function invalidSettings() { | |
77 cs.cookies.get({ | |
78 'primaryUrl': 'moo' | |
79 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); | |
80 cs.plugins.set({ | |
81 'primaryPattern': 'http://example.com/*', | |
82 'secondaryPattern': 'http://example.com/path', | |
83 'setting': 'block' | |
84 }, chrome.test.callbackFail("Specific paths are not allowed.")); | |
85 cs.javascript.set({ | |
86 'primaryPattern': 'http://example.com/*', | |
87 'secondaryPattern': 'file:///home/hansmoleman/*', | |
88 'setting': 'allow' | |
89 }, chrome.test.callbackFail("Path wildcards in file URL patterns are not all
owed.")); | |
90 } | |
91 ]); | |
92 </script> | |
OLD | NEW |