OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 // Content settings API test |
| 6 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings |
| 7 |
| 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 // TODO(bauerb) |
| 16 // "geolocation": "ask", |
| 17 "notifications": "ask" |
| 18 }; |
| 19 |
| 20 var settings = { |
| 21 "cookies": "block", |
| 22 "images": "allow", |
| 23 "javascript": "block", |
| 24 "plugins": "block", |
| 25 "popups": "allow", |
| 26 // "geolocation": "block", |
| 27 "notifications": "block" |
| 28 }; |
| 29 |
| 30 Object.prototype.forEach = function(f) { |
| 31 var k; |
| 32 for (k in this) { |
| 33 if (this.hasOwnProperty(k)) |
| 34 f(k, this[k]); |
| 35 } |
| 36 }; |
| 37 |
| 38 function expect(expected, message) { |
| 39 return chrome.test.callbackPass(function(value) { |
| 40 chrome.test.assertEq(expected, value, message); |
| 41 }); |
| 42 } |
| 43 |
| 44 function expectFalse(message) { |
| 45 return expect({ |
| 46 "value": false, |
| 47 "levelOfControl": "controllable_by_this_extension" |
| 48 }, message); |
| 49 } |
| 50 |
| 51 chrome.test.runTests([ |
| 52 function setDefaultContentSettings() { |
| 53 default_content_settings.forEach(function(type, setting) { |
| 54 cs[type].set({ |
| 55 'primaryPattern': '<all_urls>', |
| 56 'secondaryPattern': '<all_urls>', |
| 57 'setting': setting |
| 58 }, chrome.test.callbackPass()); |
| 59 }); |
| 60 }, |
| 61 function setContentSettings() { |
| 62 settings.forEach(function(type, setting) { |
| 63 cs[type].set({ |
| 64 'primaryPattern': 'http://*.google.com/*', |
| 65 'secondaryPattern': 'http://*.google.com/*', |
| 66 'setting': setting |
| 67 }, chrome.test.callbackPass()); |
| 68 }); |
| 69 }, |
| 70 function getContentSettings() { |
| 71 settings.forEach(function(type, setting) { |
| 72 var message = "Setting for " + type + " should be " + setting; |
| 73 cs[type].get({ |
| 74 'primaryUrl': 'http://www.google.com', |
| 75 'secondaryUrl': 'http://www.google.com' |
| 76 }, expect({'setting':setting}, message)); |
| 77 }); |
| 78 }, |
| 79 function invalidSettings() { |
| 80 cs.cookies.get({ |
| 81 'primaryUrl': 'moo' |
| 82 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); |
| 83 cs.plugins.set({ |
| 84 'primaryPattern': 'http://example.com/*', |
| 85 'secondaryPattern': 'http://example.com/path', |
| 86 'setting': 'block' |
| 87 }, chrome.test.callbackFail("Specific paths are not allowed.")); |
| 88 cs.javascript.set({ |
| 89 'primaryPattern': 'http://example.com/*', |
| 90 'secondaryPattern': 'file:///home/hansmoleman/*', |
| 91 'setting': 'allow' |
| 92 }, chrome.test.callbackFail( |
| 93 "Path wildcards in file URL patterns are not allowed.")); |
| 94 } |
| 95 ]); |
OLD | NEW |