OLD | NEW |
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 // Simple success test: we want content-script APIs to be available (like | 5 // Simple success test: we want content-script APIs to be available (like |
6 // sendRequest), but other APIs to be undefined or throw exceptions on access. | 6 // sendRequest), but other APIs to be undefined or throw exceptions on access. |
7 | 7 |
8 chrome.test.getConfig(function(config) { | 8 chrome.test.getConfig(function(config) { |
9 'use strict'; | 9 'use strict'; |
10 | 10 |
11 let success = true; | 11 let success = true; |
12 let areExtensionsIsolated = config.isolateExtensions; | |
13 | 12 |
14 // chrome.storage should exist, since the extension has the permission, and | 13 // chrome.storage should exist, since the extension has the permission, and |
15 // the storage api is allowed in content scripts. | 14 // the storage api is allowed in content scripts. |
16 if (!chrome.storage) { | 15 if (!chrome.storage) { |
17 console.log("Error: chrome.storage doesn't exist; it should"); | 16 console.log("Error: chrome.storage doesn't exist; it should"); |
18 success = false; | 17 success = false; |
19 } | 18 } |
20 | 19 |
21 let checkPrivilegedApi = function(api, name) { | 20 let checkPrivilegedApi = function(api, name) { |
22 if (api && !areExtensionsIsolated) { | 21 if (api) |
23 console.log("Error: " + name + | 22 return true; |
24 " exists, but shouldn't without isolated extensions."); | 23 |
25 return false; | 24 console.log('Error: ' + name + ' doesn\'t exist, but should.'); |
26 } | 25 return false; |
27 if (!api && areExtensionsIsolated) { | |
28 console.log("Error: " + name + | |
29 " doesn't exist, but should with isolated extensions."); | |
30 return false; | |
31 } | |
32 return true; | |
33 }; | 26 }; |
34 | 27 |
35 // For other permissions, they should only be available if this is a trusted | 28 // For other permissions, they should only be available if this is a trusted |
36 // extension process - which is the case only when site isolation is enabled | 29 // extension process - which is the case only when site isolation is enabled |
37 // for extensions. The whole of chrome.bookmarks (arbitrary unprivileged) is | 30 // for extensions. The whole of chrome.bookmarks (arbitrary unprivileged) is |
38 // unavailable without site isolation. | 31 // unavailable without site isolation. |
39 success = success && checkPrivilegedApi(chrome.bookmarks, 'chrome.bookmarks'); | 32 success = success && checkPrivilegedApi(chrome.bookmarks, 'chrome.bookmarks'); |
40 // We test chrome.tabs as a special case, because it's a dependency of the | 33 // We test chrome.tabs as a special case, because it's a dependency of the |
41 // partially unprivileged chrome.extension. | 34 // partially unprivileged chrome.extension. |
42 success = success && checkPrivilegedApi(chrome.tabs, 'chrome.tabs'); | 35 success = success && checkPrivilegedApi(chrome.tabs, 'chrome.tabs'); |
43 // And parts of chrome.extension should be unavailable to unprivileged | 36 // And parts of chrome.extension should be unavailable to unprivileged |
44 // contexts. | 37 // contexts. |
45 success = success && checkPrivilegedApi(chrome.extension.getViews, | 38 success = success && checkPrivilegedApi(chrome.extension.getViews, |
46 'chrome.extension.getViews'); | 39 'chrome.extension.getViews'); |
47 | 40 |
48 chrome.extension.sendRequest({success: success}); | 41 chrome.extension.sendRequest({success: success}); |
49 }); | 42 }); |
OLD | NEW |