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 function runsWithException(f) { | 8 function runsWithException(f) { |
9 try { | 9 try { |
10 var foo = f(); | 10 var foo = f(); |
11 console.log('Error: ' + f + '" doesn\'t throw exception.'); | 11 console.log('Error: ' + f + '" doesn\'t throw exception.'); |
12 return false; | 12 return false; |
13 } catch (e) { | 13 } catch (e) { |
14 if (e.message.indexOf(' can only be used in extension processes.') > -1) { | 14 if (e.message.indexOf(' cannot be used in this context.') > -1) { |
15 return true; | 15 return true; |
16 } else { | 16 } else { |
17 console.log('Error: incorrect exception message: ' + e.message); | 17 console.log('Error: incorrect exception message: ' + e.message); |
18 return false; | 18 return false; |
19 } | 19 } |
20 } | 20 } |
21 } | 21 } |
22 | 22 |
23 var success = true; | 23 var success = true; |
24 | 24 |
25 // The whole of chrome.storage (arbitrary unprivileged) is unavailable. | 25 // The whole of chrome.storage (arbitrary unprivileged) is unavailable. |
26 if (chrome.storage) { | 26 if (chrome.storage) { |
27 console.log('Error: chrome.storage exists, it shouldn\'t.'); | 27 console.log('Error: chrome.storage exists, it shouldn\'t.'); |
28 success = false; | 28 success = false; |
29 } | 29 } |
30 | 30 |
31 // Ditto chrome.tabs, though it's special because it's a dependency of the | 31 // Ditto all children of chrome.tabs. |
32 // partially unprivileged chrome.extension. | 32 for (p in chrome.tabs) { |
33 if (chrome.tabs) { | 33 if (chrome.tabs.hasOwnProperty(p)) { |
34 console.log('Error: chrome.tabs exists, it shouldn\'t.'); | 34 if (["remove", "create", "update"].indexOf(p) == -1) { |
35 success = false; | 35 if (!runsWithException( |
| 36 function(p) { return chrome.tabs[p]; }.bind(null, p))) { |
| 37 console.log(p); |
| 38 success = false; |
| 39 break; |
| 40 } |
| 41 } |
| 42 } |
36 } | 43 } |
37 | 44 |
38 // Parts of chrome.extension are unavailable. | 45 // Parts of chrome.extension are unavailable. |
39 if (!runsWithException(function() { return chrome.extension.getViews; })) | 46 if (!runsWithException(function() { return chrome.extension.getViews; })) |
40 success = false; | 47 success = false; |
41 | 48 |
42 chrome.extension.sendRequest({success: success}); | 49 chrome.extension.sendRequest({success: success}); |
OLD | NEW |