| 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 assertEq = chrome.test.assertEq; | 5 var assertEq = chrome.test.assertEq; |
| 6 var assertFalse = chrome.test.assertFalse; | 6 var assertFalse = chrome.test.assertFalse; |
| 7 var assertTrue = chrome.test.assertTrue; | 7 var assertTrue = chrome.test.assertTrue; |
| 8 var fail = chrome.test.callbackFail; | 8 var fail = chrome.test.callbackFail; |
| 9 var pass = chrome.test.callbackPass; | 9 var pass = chrome.test.callbackPass; |
| 10 var listenOnce = chrome.test.listenOnce; | 10 var listenOnce = chrome.test.listenOnce; |
| 11 | 11 |
| 12 var NOT_OPTIONAL_ERROR = | 12 var NOT_OPTIONAL_ERROR = |
| 13 "Optional permissions must be listed in extension manifest."; | 13 "Optional permissions must be listed in extension manifest."; |
| 14 | 14 |
| 15 var NO_TABS_PERMISSION = | 15 var NO_TABS_PERMISSION = |
| 16 "You do not have permission to use 'windows.getAll'."; | 16 "cannot be used in this context."; |
| 17 | 17 |
| 18 var REQUIRED_ERROR = | 18 var REQUIRED_ERROR = |
| 19 "You cannot remove required permissions."; | 19 "You cannot remove required permissions."; |
| 20 | 20 |
| 21 var NOT_WHITE_LISTED_ERROR = | 21 var NOT_WHITE_LISTED_ERROR = |
| 22 "The optional permissions API does not support '*'."; | 22 "The optional permissions API does not support '*'."; |
| 23 | 23 |
| 24 var UNKNOWN_PERMISSIONS_ERROR = | 24 var UNKNOWN_PERMISSIONS_ERROR = |
| 25 "'*' is not a recognized permission."; | 25 "'*' is not a recognized permission."; |
| 26 | 26 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // permissions list (see permissions_apitest.cc). | 128 // permissions list (see permissions_apitest.cc). |
| 129 function requestTabs() { | 129 function requestTabs() { |
| 130 // chrome.windows is a optional permission, so the API definition should | 130 // chrome.windows is a optional permission, so the API definition should |
| 131 // exist but its use disallowed. | 131 // exist but its use disallowed. |
| 132 assertTrue(!!chrome.windows); | 132 assertTrue(!!chrome.windows); |
| 133 try { | 133 try { |
| 134 chrome.windows.getAll({populate: true}, function() { | 134 chrome.windows.getAll({populate: true}, function() { |
| 135 chrome.test.fail("Should not have tabs API permission."); | 135 chrome.test.fail("Should not have tabs API permission."); |
| 136 }); | 136 }); |
| 137 } catch (e) { | 137 } catch (e) { |
| 138 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0); | 138 console.log(e.message); |
| 139 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) > -1); |
| 139 } | 140 } |
| 140 listenOnce(chrome.permissions.onAdded, | 141 listenOnce(chrome.permissions.onAdded, |
| 141 function(permissions) { | 142 function(permissions) { |
| 142 assertTrue(permissions.permissions.length == 1); | 143 assertTrue(permissions.permissions.length == 1); |
| 143 assertTrue(permissions.permissions[0] == 'tabs'); | 144 assertTrue(permissions.permissions[0] == 'tabs'); |
| 144 }); | 145 }); |
| 145 chrome.permissions.request( | 146 chrome.permissions.request( |
| 146 {permissions:['tabs']}, | 147 {permissions:['tabs']}, |
| 147 pass(function(granted) { | 148 pass(function(granted) { |
| 148 assertTrue(granted); | 149 assertTrue(granted); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 {permissions:['tabs']}, | 203 {permissions:['tabs']}, |
| 203 pass(function() { | 204 pass(function() { |
| 204 chrome.permissions.getAll(pass(function(permissions) { | 205 chrome.permissions.getAll(pass(function(permissions) { |
| 205 assertTrue(checkPermSetsEq(initialPermissions, permissions)); | 206 assertTrue(checkPermSetsEq(initialPermissions, permissions)); |
| 206 })); | 207 })); |
| 207 try { | 208 try { |
| 208 chrome.windows.getAll({populate: true}, function() { | 209 chrome.windows.getAll({populate: true}, function() { |
| 209 chrome.test.fail("Should not have tabs API permission."); | 210 chrome.test.fail("Should not have tabs API permission."); |
| 210 }); | 211 }); |
| 211 } catch (e) { | 212 } catch (e) { |
| 212 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0); | 213 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) > -1); |
| 213 } | 214 } |
| 214 })); | 215 })); |
| 215 }, | 216 }, |
| 216 | 217 |
| 217 // The user shouldn't have to approve permissions that have no warnings. | 218 // The user shouldn't have to approve permissions that have no warnings. |
| 218 function noPromptForNoWarnings() { | 219 function noPromptForNoWarnings() { |
| 219 chrome.permissions.request( | 220 chrome.permissions.request( |
| 220 {permissions: ['notifications']}, | 221 {permissions: ['notifications']}, |
| 221 pass(function(granted) { | 222 pass(function(granted) { |
| 222 assertTrue(granted); | 223 assertTrue(granted); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 assertTrue(true); | 303 assertTrue(true); |
| 303 })); | 304 })); |
| 304 }); | 305 }); |
| 305 listenOnce(chrome.permissions.onRemoved, | 306 listenOnce(chrome.permissions.onRemoved, |
| 306 function(permissions) { | 307 function(permissions) { |
| 307 try { | 308 try { |
| 308 chrome.windows.getAll({populate: true}, function() { | 309 chrome.windows.getAll({populate: true}, function() { |
| 309 chrome.test.fail("Should not have tabs API permission."); | 310 chrome.test.fail("Should not have tabs API permission."); |
| 310 }); | 311 }); |
| 311 } catch (e) { | 312 } catch (e) { |
| 312 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0); | 313 assertTrue(e.message.indexOf(NO_TABS_PERMISSION) > -1); |
| 313 } | 314 } |
| 314 }); | 315 }); |
| 315 | 316 |
| 316 chrome.permissions.request( | 317 chrome.permissions.request( |
| 317 {permissions: ['tabs', 'management']}, pass(function(granted) { | 318 {permissions: ['tabs', 'management']}, pass(function(granted) { |
| 318 assertTrue(granted); | 319 assertTrue(granted); |
| 319 chrome.permissions.remove( | 320 chrome.permissions.remove( |
| 320 {permissions: ['tabs']}, pass(function() { | 321 {permissions: ['tabs']}, pass(function() { |
| 321 assertTrue(true); | 322 assertTrue(true); |
| 322 })); | 323 })); |
| 323 })); | 324 })); |
| 324 } | 325 } |
| 325 | 326 |
| 326 ]); | 327 ]); |
| 327 }); | 328 }); |
| OLD | NEW |