diff options
-rw-r--r-- | chrome/test/data/extensions/api_test/permissions/optional/background.html | 376 |
1 files changed, 188 insertions, 188 deletions
diff --git a/chrome/test/data/extensions/api_test/permissions/optional/background.html b/chrome/test/data/extensions/api_test/permissions/optional/background.html index ba9a1c8..c53a327 100644 --- a/chrome/test/data/extensions/api_test/permissions/optional/background.html +++ b/chrome/test/data/extensions/api_test/permissions/optional/background.html @@ -1,188 +1,188 @@ -<script>
-
-var assertFalse = chrome.test.assertFalse;
-var assertTrue = chrome.test.assertTrue;
-var fail = chrome.test.callbackFail;
-var pass = chrome.test.callbackPass;
-var listenOnce = chrome.test.listenOnce;
-
-var NOT_OPTIONAL_ERROR =
- "Optional permissions must be listed in extension manifest.";
-
-var NO_TABS_PERMISSION =
- "You do not have permission to use 'windows.getAll'.";
-
-var REQUIRED_ERROR =
- "You cannot remove required permissions.";
-
-var NOT_WHITE_LISTED_ERROR =
- "The optional permissions API does not support '*'.";
-
-var UNKNOWN_PERMISSIONS_ERROR =
- "'*' is not a recognized permission.";
-
-var emptyPermissions = {permissions: []};
-
-var initialPermissions = {
- permissions: ['experimental', 'management', 'permissions']
-};
-
-var permissionsWithTabs = {
- permissions: ['experimental', 'management', 'permissions', 'tabs']
-}
-
-function checkEqualSets(set1, set2) {
- if (set1.length != set2.length)
- return false;
-
- for (var x = 0; x < set1.length; x++) {
- if (!set2.some(function(v) { return v == set1[x]; }))
- return false;
- }
-
- return true;
-}
-
-function checkPermSetsEq(set1, set2) {
- return checkEqualSets(set1.permissions, set2.permissions);
-}
-
-chrome.test.runTests([
- function contains() {
- chrome.experimental.permissions.contains(
- {permissions: ['management']},
- pass(function(result) {
- assertTrue(result);
- }));
- chrome.experimental.permissions.contains(
- {permissions: ['devtools']},
- pass(function(result) {
- assertFalse(result);
- }));
- chrome.experimental.permissions.contains(
- {permissions: ['permissions', 'management']},
- pass(function(result) {
- assertTrue(result);
- }));
- chrome.experimental.permissions.contains(
- {permissions: ['management', 'permissions']},
- pass(function(result) {
- assertTrue(result);
- }));
- },
-
- function getAll() {
- chrome.experimental.permissions.getAll(pass(function(permissions) {
- assertTrue(checkPermSetsEq(initialPermissions, permissions));
- }));
- },
-
- // Nothing should happen if we request permission we already have
- function requestNoOp() {
- chrome.experimental.permissions.request(
- {permissions:['management']},
- pass(function(granted) {
- assertTrue(granted);
- }));
- },
-
- // We should get an error when requesting permissions that haven't been
- // defined in "optional_permissions".
- function requestNonOptional() {
- chrome.experimental.permissions.request(
- {permissions:['debugger']}, fail(NOT_OPTIONAL_ERROR));
- },
-
- // We should be able to request the tabs API since it's in the granted
- // permissions list (see permissions_apitest.cc).
- function requestTabs() {
- try {
- chrome.windows.getAll({populate: true}, function() {
- chrome.test.fail("Should not have tabs API permission.");
- });
- } catch (e) {
- assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0);
- }
- listenOnce(chrome.experimental.permissions.onAdded, function(permissions) {
- assertTrue(permissions.permissions.length == 1);
- assertTrue(permissions.permissions[0] == 'tabs');
- });
- chrome.experimental.permissions.request(
- {permissions:['tabs']},
- pass(function(granted) {
- assertTrue(granted);
- chrome.windows.getAll({populate: true}, pass(function(windows) {
- assertTrue(true);
- }));
- chrome.experimental.permissions.getAll(pass(function(permissions) {
- assertTrue(checkPermSetsEq(permissionsWithTabs, permissions));
- }));
- }));
- },
-
- // You can't remove required permissions.
- function removeRequired() {
- chrome.experimental.permissions.remove(
- {permissions:['management']}, fail(REQUIRED_ERROR));
- },
-
- // You can remove permissions you don't have (nothing happens).
- function removeNoOp() {
- chrome.experimental.permissions.remove(
- {permissions:['background']},
- pass(function(removed) {
- assertTrue(removed);
- }));
- },
-
- function removeTabs() {
- chrome.windows.getAll({populate: true}, pass(function(windows) {
- assertTrue(true);
- }));
- listenOnce(chrome.experimental.permissions.onRemoved,
- function(permissions) {
- assertTrue(permissions.permissions.length == 1);
- assertTrue(permissions.permissions[0] == 'tabs');
- });
- chrome.experimental.permissions.remove(
- {permissions:['tabs']},
- pass(function() {
- chrome.experimental.permissions.getAll(pass(function(permissions) {
- assertTrue(checkPermSetsEq(initialPermissions, permissions));
- }));
- try {
- chrome.windows.getAll({populate: true}, function() {
- chrome.test.fail("Should not have tabs API permission.");
- });
- } catch (e) {
- assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0);
- }
- }));
- },
-
- // The user shouldn't have to approve permissions that have no warnings.
- // TODO(jstritar): move to its own test and set a low timeout
- function noPromptForNoWarnings() {
- chrome.experimental.permissions.request(
- {permissions: ['notifications']},
- pass(function(granted) {
- assertTrue(granted);
- }));
- },
-
- // Make sure you can only access the white listed permissions.
- function whitelist() {
- var error_msg = NOT_WHITE_LISTED_ERROR.replace('*', 'chromeAuthPrivate');
- chrome.experimental.permissions.request(
- {permissions: ['chromeAuthPrivate']}, fail(error_msg));
- chrome.experimental.permissions.remove(
- {permissions: ['chromeAuthPrivate']}, fail(error_msg));
- },
-
- function unknownPermission() {
- var error_msg = UNKNOWN_PERMISSIONS_ERROR.replace('*', 'asdf');
- chrome.experimental.permissions.request(
- {permissions: ['asdf']}, fail(error_msg));
- }
-]);
-</script>
+<script> + +var assertFalse = chrome.test.assertFalse; +var assertTrue = chrome.test.assertTrue; +var fail = chrome.test.callbackFail; +var pass = chrome.test.callbackPass; +var listenOnce = chrome.test.listenOnce; + +var NOT_OPTIONAL_ERROR = + "Optional permissions must be listed in extension manifest."; + +var NO_TABS_PERMISSION = + "You do not have permission to use 'windows.getAll'."; + +var REQUIRED_ERROR = + "You cannot remove required permissions."; + +var NOT_WHITE_LISTED_ERROR = + "The optional permissions API does not support '*'."; + +var UNKNOWN_PERMISSIONS_ERROR = + "'*' is not a recognized permission."; + +var emptyPermissions = {permissions: []}; + +var initialPermissions = { + permissions: ['experimental', 'management', 'permissions'] +}; + +var permissionsWithTabs = { + permissions: ['experimental', 'management', 'permissions', 'tabs'] +} + +function checkEqualSets(set1, set2) { + if (set1.length != set2.length) + return false; + + for (var x = 0; x < set1.length; x++) { + if (!set2.some(function(v) { return v == set1[x]; })) + return false; + } + + return true; +} + +function checkPermSetsEq(set1, set2) { + return checkEqualSets(set1.permissions, set2.permissions); +} + +chrome.test.runTests([ + function contains() { + chrome.experimental.permissions.contains( + {permissions: ['management']}, + pass(function(result) { + assertTrue(result); + })); + chrome.experimental.permissions.contains( + {permissions: ['devtools']}, + pass(function(result) { + assertFalse(result); + })); + chrome.experimental.permissions.contains( + {permissions: ['permissions', 'management']}, + pass(function(result) { + assertTrue(result); + })); + chrome.experimental.permissions.contains( + {permissions: ['management', 'permissions']}, + pass(function(result) { + assertTrue(result); + })); + }, + + function getAll() { + chrome.experimental.permissions.getAll(pass(function(permissions) { + assertTrue(checkPermSetsEq(initialPermissions, permissions)); + })); + }, + + // Nothing should happen if we request permission we already have + function requestNoOp() { + chrome.experimental.permissions.request( + {permissions:['management']}, + pass(function(granted) { + assertTrue(granted); + })); + }, + + // We should get an error when requesting permissions that haven't been + // defined in "optional_permissions". + function requestNonOptional() { + chrome.experimental.permissions.request( + {permissions:['debugger']}, fail(NOT_OPTIONAL_ERROR)); + }, + + // We should be able to request the tabs API since it's in the granted + // permissions list (see permissions_apitest.cc). + function requestTabs() { + try { + chrome.windows.getAll({populate: true}, function() { + chrome.test.fail("Should not have tabs API permission."); + }); + } catch (e) { + assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0); + } + listenOnce(chrome.experimental.permissions.onAdded, function(permissions) { + assertTrue(permissions.permissions.length == 1); + assertTrue(permissions.permissions[0] == 'tabs'); + }); + chrome.experimental.permissions.request( + {permissions:['tabs']}, + pass(function(granted) { + assertTrue(granted); + chrome.windows.getAll({populate: true}, pass(function(windows) { + assertTrue(true); + })); + chrome.experimental.permissions.getAll(pass(function(permissions) { + assertTrue(checkPermSetsEq(permissionsWithTabs, permissions)); + })); + })); + }, + + // You can't remove required permissions. + function removeRequired() { + chrome.experimental.permissions.remove( + {permissions:['management']}, fail(REQUIRED_ERROR)); + }, + + // You can remove permissions you don't have (nothing happens). + function removeNoOp() { + chrome.experimental.permissions.remove( + {permissions:['background']}, + pass(function(removed) { + assertTrue(removed); + })); + }, + + function removeTabs() { + chrome.windows.getAll({populate: true}, pass(function(windows) { + assertTrue(true); + })); + listenOnce(chrome.experimental.permissions.onRemoved, + function(permissions) { + assertTrue(permissions.permissions.length == 1); + assertTrue(permissions.permissions[0] == 'tabs'); + }); + chrome.experimental.permissions.remove( + {permissions:['tabs']}, + pass(function() { + chrome.experimental.permissions.getAll(pass(function(permissions) { + assertTrue(checkPermSetsEq(initialPermissions, permissions)); + })); + try { + chrome.windows.getAll({populate: true}, function() { + chrome.test.fail("Should not have tabs API permission."); + }); + } catch (e) { + assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0); + } + })); + }, + + // The user shouldn't have to approve permissions that have no warnings. + // TODO(jstritar): move to its own test and set a low timeout + function noPromptForNoWarnings() { + chrome.experimental.permissions.request( + {permissions: ['notifications']}, + pass(function(granted) { + assertTrue(granted); + })); + }, + + // Make sure you can only access the white listed permissions. + function whitelist() { + var error_msg = NOT_WHITE_LISTED_ERROR.replace('*', 'chromeAuthPrivate'); + chrome.experimental.permissions.request( + {permissions: ['chromeAuthPrivate']}, fail(error_msg)); + chrome.experimental.permissions.remove( + {permissions: ['chromeAuthPrivate']}, fail(error_msg)); + }, + + function unknownPermission() { + var error_msg = UNKNOWN_PERMISSIONS_ERROR.replace('*', 'asdf'); + chrome.experimental.permissions.request( + {permissions: ['asdf']}, fail(error_msg)); + } +]); +</script> |