| 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 var assertFalse = chrome.test.assertFalse; | 5 var assertFalse = chrome.test.assertFalse; |
| 6 var assertTrue = chrome.test.assertTrue; | 6 var assertTrue = chrome.test.assertTrue; |
| 7 var pass = chrome.test.callbackPass; | 7 var pass = chrome.test.callbackPass; |
| 8 | 8 |
| 9 var NO_TABS_PERMISSION = | 9 var NO_BOOKMARKS_PERMISSION = |
| 10 "You do not have permission to use 'windows.getAll'."; | 10 "You do not have permission to use 'bookmarks.getTree'."; |
| 11 | 11 |
| 12 chrome.test.getConfig(function(config) { | 12 chrome.test.getConfig(function(config) { |
| 13 | 13 |
| 14 function doReq(domain, callback) { | 14 function doReq(domain, callback) { |
| 15 var req = new XMLHttpRequest(); | 15 var req = new XMLHttpRequest(); |
| 16 var url = domain + ":PORT/files/extensions/test_file.txt"; | 16 var url = domain + ":PORT/files/extensions/test_file.txt"; |
| 17 url = url.replace(/PORT/, config.testServer.port); | 17 url = url.replace(/PORT/, config.testServer.port); |
| 18 | 18 |
| 19 chrome.test.log("Requesting url: " + url); | 19 chrome.test.log("Requesting url: " + url); |
| 20 req.open("GET", url, true); | 20 req.open("GET", url, true); |
| 21 | 21 |
| 22 req.onload = function() { | 22 req.onload = function() { |
| 23 assertEq(200, req.status); | 23 assertEq(200, req.status); |
| 24 assertEq("Hello!", req.responseText); | 24 assertEq("Hello!", req.responseText); |
| 25 callback(true); | 25 callback(true); |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 req.onerror = function() { | 28 req.onerror = function() { |
| 29 chrome.test.log("status: " + req.status); | 29 chrome.test.log("status: " + req.status); |
| 30 chrome.test.log("text: " + req.responseText); | 30 chrome.test.log("text: " + req.responseText); |
| 31 callback(false); | 31 callback(false); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 req.send(null); | 34 req.send(null); |
| 35 } | 35 } |
| 36 | 36 |
| 37 chrome.test.runTests([ | 37 chrome.test.runTests([ |
| 38 function denyRequest() { | 38 function denyRequest() { |
| 39 chrome.permissions.request( | 39 chrome.permissions.request( |
| 40 {permissions: ['tabs'], origins: ['http://*.c.com/*']}, | 40 {permissions: ['bookmarks'], origins: ['http://*.c.com/*']}, |
| 41 pass(function(granted) { | 41 pass(function(granted) { |
| 42 // They were not granted, and there should be no error. | 42 // They were not granted, and there should be no error. |
| 43 assertFalse(granted); | 43 assertFalse(granted); |
| 44 assertTrue(chrome.extension.lastError === undefined); | 44 assertTrue(chrome.extension.lastError === undefined); |
| 45 | 45 |
| 46 // Make sure they weren't granted... | 46 // Make sure they weren't granted... |
| 47 chrome.permissions.contains( | 47 chrome.permissions.contains( |
| 48 {permissions: ['tabs'], origins:['http://*.c.com/*']}, | 48 {permissions: ['bookmarks'], origins:['http://*.c.com/*']}, |
| 49 pass(function(result) { assertFalse(result); })); | 49 pass(function(result) { assertFalse(result); })); |
| 50 | 50 |
| 51 try { | 51 try { |
| 52 chrome.windows.getAll({populate: true}, function() { | 52 chrome.bookmarks.getTree(function() { |
| 53 chrome.test.fail("Should not have tabs API permission."); | 53 chrome.test.fail("Should not have bookmarks API permission."); |
| 54 }); | 54 }); |
| 55 } catch (e) { | 55 } catch (e) { |
| 56 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0); | 56 assertTrue(e.message.indexOf(NO_BOOKMARKS_PERMISSION) == 0); |
| 57 } | 57 } |
| 58 | 58 |
| 59 doReq('http://b.c.com/', pass(function(result) { | 59 doReq('http://b.c.com/', pass(function(result) { |
| 60 assertFalse(result); | 60 assertFalse(result); |
| 61 })); | 61 })); |
| 62 })); | 62 })); |
| 63 }, | 63 }, |
| 64 | 64 |
| 65 function noPromptForActivePermissions() { | 65 function noPromptForActivePermissions() { |
| 66 // We shouldn't prompt if the extension already has the permissions. | 66 // We shouldn't prompt if the extension already has the permissions. |
| 67 chrome.permissions.request( | 67 chrome.permissions.request( |
| 68 {permissions: ["management"]}, | 68 {permissions: ["management"]}, |
| 69 pass(function(granted) { | 69 pass(function(granted) { |
| 70 assertTrue(granted); | 70 assertTrue(granted); |
| 71 })); | 71 })); |
| 72 } | 72 } |
| 73 ]); | 73 ]); |
| 74 }); | 74 }); |
| OLD | NEW |