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