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
3 // found in the LICENSE file.
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.
8 chrome
.test
.getConfig(function(config
) {
12 let isSitePerProcess
= config
.sitePerProcess
;
14 // chrome.storage should exist, since the extension has the permission, and
15 // the storage api is allowed in content scripts.
16 if (!chrome
.storage
) {
17 console
.log("Error: chrome.storage doesn't exist; it should");
21 let checkPrivilegedApi = function(api
, name
) {
22 if (api
&& !isSitePerProcess
) {
23 console
.log("Error: " + name
+
24 " exists, but shouldn't without site-per-process.");
27 if (!api
&& isSitePerProcess
) {
28 console
.log("Error: " + name
+
29 " doesn't exist, but should with site-per-process.");
35 // For other permissions, they should only be available if this is a trusted
36 // extension process - which is the case only with site-per-process.
37 // The whole of chrome.bookmarks (arbitrary unprivileged) is unavailable
38 // without site-per-process.
39 success
= success
&& checkPrivilegedApi(chrome
.bookmarks
, 'chrome.bookmarks');
40 // We test chrome.tabs as a special case, because it's a dependency of the
41 // partially unprivileged chrome.extension.
42 success
= success
&& checkPrivilegedApi(chrome
.tabs
, 'chrome.tabs');
43 // And parts of chrome.extension should be unavailable to unprivileged
45 success
= success
&& checkPrivilegedApi(chrome
.extension
.getViews
,
46 'chrome.extension.getViews');
48 chrome
.extension
.sendRequest({success
: success
});