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 var assertFalse
= chrome
.test
.assertFalse
;
6 var assertTrue
= chrome
.test
.assertTrue
;
7 var assertEq
= chrome
.test
.assertEq
;
8 var pass
= chrome
.test
.callbackPass
;
10 var NO_BOOKMARKS_PERMISSION
=
11 "You do not have permission to use 'bookmarks.getTree'.";
13 chrome
.test
.getConfig(function(config
) {
15 function doReq(domain
, callback
) {
16 var req
= new XMLHttpRequest();
17 var url
= domain
+ ":PORT/extensions/test_file.txt";
18 url
= url
.replace(/PORT/, config
.testServer
.port
);
20 chrome
.test
.log("Requesting url: " + url
);
21 req
.open("GET", url
, true);
23 req
.onload = function() {
24 assertEq(200, req
.status
);
25 assertEq("Hello!", req
.responseText
);
29 req
.onerror = function() {
30 chrome
.test
.log("status: " + req
.status
);
31 chrome
.test
.log("text: " + req
.responseText
);
38 chrome
.test
.runTests([
39 function denyRequest() {
40 chrome
.permissions
.request(
41 {permissions
: ['bookmarks'], origins
: ['http://*.c.com/*']},
42 pass(function(granted
) {
43 // They were not granted, and there should be no error.
45 assertTrue(chrome
.runtime
.lastError
=== undefined);
47 // Make sure they weren't granted...
48 chrome
.permissions
.contains(
49 {permissions
: ['bookmarks'], origins
:['http://*.c.com/*']},
50 pass(function(result
) { assertFalse(result
); }));
52 assertEq(undefined, chrome
.bookmarks
);
53 doReq('http://b.c.com/', pass(function(result
) {
59 function noPromptForActivePermissions() {
60 // We shouldn't prompt if the extension already has the permissions.
61 chrome
.permissions
.request(
62 {permissions
: ["management"]},
63 pass(function(granted
) {