Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/test/data/extensions/api_test/permissions/optional_deny/background.html

Issue 7508029: Add origin permissions to the extension permissions API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <script> 1 <script>
2 2
3 var assertFalse = chrome.test.assertFalse; 3 var assertFalse = chrome.test.assertFalse;
4 var assertTrue = chrome.test.assertTrue; 4 var assertTrue = chrome.test.assertTrue;
5 var pass = chrome.test.callbackPass; 5 var pass = chrome.test.callbackPass;
6 6
7 var NO_TABS_PERMISSION = 7 var NO_TABS_PERMISSION =
8 "You do not have permission to use 'windows.getAll'."; 8 "You do not have permission to use 'windows.getAll'.";
9 9
10 chrome.test.runTests([ 10 chrome.test.getConfig(function(config) {
11 function denyRequest() {
12 chrome.experimental.permissions.request(
13 {permissions: ['tabs']},
14 pass(function(granted) {
15 // They were not granted, and there should be no error.
16 assertFalse(granted);
17 assertTrue(chrome.extension.lastError === undefined);
18 11
19 // Make sure they weren't granted... 12 function doReq(domain, expectSuccess) {
20 chrome.experimental.permissions.contains( 13 var req = new XMLHttpRequest();
21 {permissions: ['tabs']}, 14 var url = domain + ":PORT/files/extensions/test_file.txt";
22 pass(function(result) { 15 url = url.replace(/PORT/, config.testServer.port);
23 assertFalse(result);
24 }));
25 16
26 try { 17 chrome.test.log("Requesting url: " + url);
27 chrome.windows.getAll({populate: true}, function() { 18 req.open("GET", url, true);
28 chrome.test.fail("Should not have tabs API permission."); 19
29 }); 20
30 } catch (e) { 21 if (expectSuccess) {
31 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0); 22 req.onload = function() {
32 } 23 chrome.test.assertEq(200, req.status);
33 })); 24 chrome.test.assertEq("Hello!", req.responseText);
25 chrome.test.runNextTest();
26 }
27 req.onerror = function() {
28 chrome.test.log("status: " + req.status);
29 chrome.test.log("text: " + req.responseText);
30 chrome.test.fail("Unexpected error for domain: " + domain);
31 }
32 } else {
33 req.onload = function() {
34 chrome.test.fail("Unexpected success for domain: " + domain);
35 }
36 req.onerror = function() {
37 chrome.test.assertEq(0, req.status);
38 chrome.test.runNextTest();
39 }
40 }
41
42 req.send(null);
34 } 43 }
35 ]); 44
45 chrome.test.runTests([
46 function denyRequest() {
47 chrome.experimental.permissions.request(
48 {permissions: ['tabs'], origins: ['http://*.c.com/*']},
49 pass(function(granted) {
50 // They were not granted, and there should be no error.
51 assertFalse(granted);
52 assertTrue(chrome.extension.lastError === undefined);
53
54 // Make sure they weren't granted...
55 chrome.experimental.permissions.contains(
56 {permissions: ['tabs'], origins:['http://*.c.com/*']},
57 pass(function(result) { assertFalse(result); }));
58
59 try {
60 chrome.windows.getAll({populate: true}, function() {
61 chrome.test.fail("Should not have tabs API permission.");
62 });
63 } catch (e) {
64 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0);
65 }
66
67 doReq('http://b.c.com/', false);
Matt Perry 2011/08/03 22:08:14 ditto comments from other test
jstritar 2011/08/04 16:35:15 Done.
68 }));
69 }
70 ]);
71 });
36 </script> 72 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698