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

Unified Diff: chrome/test/data/extensions/api_test/permissions/optional/background.html

Issue 7432006: Add an experimental permissions API for extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/permissions/optional/background.html
diff --git a/chrome/test/data/extensions/api_test/permissions/optional/background.html b/chrome/test/data/extensions/api_test/permissions/optional/background.html
new file mode 100644
index 0000000000000000000000000000000000000000..74a9719b1005e1ad5ed353e7169b93c7caea64e3
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/permissions/optional/background.html
@@ -0,0 +1,169 @@
+<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 empty_permissions = {apis: []};
Mihai Parparita -not on Chrome 2011/07/20 22:03:43 I think we generally use the JS naming scheme in t
jstritar 2011/07/22 19:21:55 Done.
+
+var initial_permissions = {
+ apis: ['management', 'permissions']
+};
+
+var permissions_with_tabs = {
+ apis: ['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.apis, set2.apis);
+}
+
+chrome.test.runTests([
+ function contains() {
+ chrome.permissions.contains({apis: ['management']}, pass(function(result) {
+ assertTrue(result);
+ }));
+ chrome.permissions.contains({apis: ['devtools']}, pass(function(result) {
+ assertFalse(result);
+ }));
+ chrome.permissions.contains({
+ apis: ['permissions', 'management']
+ }, pass(function(result) {
Mihai Parparita -not on Chrome 2011/07/20 22:03:43 Seems like this should be intended more, since it'
jstritar 2011/07/22 19:21:55 Looked kind of strange that way, since the content
+ assertTrue(result);
+ }));
+ chrome.permissions.contains({
+ apis: ['management', 'permissions']
+ }, pass(function(result) {
+ assertTrue(result);
+ }));
+ },
+
+ function getAll() {
+ chrome.permissions.getAll(pass(function(permissions) {
+ assertTrue(checkPermSetsEq(initial_permissions, permissions));
+ }));
+ },
+
+ // Nothing should happen if we request permission we already have
+ function requestNoOp() {
+ chrome.permissions.request({apis:['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.permissions.request({apis:['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() {
+ assertTrue(false);
Mihai Parparita -not on Chrome 2011/07/20 22:03:43 Something like chrome.test.fail("Should not have t
jstritar 2011/07/22 19:21:55 Done.
+ });
+ } catch (e) {
+ assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0);
+ }
+ listenOnce(chrome.permissions.onAdded, function(permissions) {
+ assertTrue(permissions.apis.length == 1);
+ assertTrue(permissions.apis[0] == 'tabs');
+ });
+ chrome.permissions.request({apis:['tabs']}, pass(function(granted) {
+ assertTrue(granted);
+ chrome.windows.getAll({populate: true}, pass(function(windows) {
+ assertTrue(true);
+ }));
+ chrome.permissions.getAll(pass(function(permissions) {
+ assertTrue(checkPermSetsEq(permissions_with_tabs, permissions));
+ }));
+ }));
+ },
+
+ // You can't remove required permissions.
+ function removeRequired() {
+ chrome.permissions.remove({apis:['management']}, fail(REQUIRED_ERROR));
+ },
+
+ // You can remove permissions you don't have (nothing happens).
+ function removeNoOp() {
+ chrome.permissions.remove({apis:['background']}, pass(function(removed) {
+ assertTrue(removed);
+ }));
+ },
+
+ function removeTabs() {
+ chrome.windows.getAll({populate: true}, pass(function(windows) {
+ assertTrue(true);
+ }));
+ listenOnce(chrome.permissions.onRemoved, function(permissions) {
+ assertTrue(permissions.apis.length == 1);
+ assertTrue(permissions.apis[0] == 'tabs');
+ });
+ chrome.permissions.remove({apis:['tabs']}, pass(function() {
+ chrome.permissions.getAll(pass(function(permissions) {
+ assertTrue(checkPermSetsEq(initial_permissions, permissions));
+ }));
+ try {
+ chrome.windows.getAll({populate: true}, function() {
+ assertTrue(false);
Mihai Parparita -not on Chrome 2011/07/20 22:03:43 Ditto about using chrome.test.fail("Should not hav
jstritar 2011/07/22 19:21:55 Done.
+ });
+ } 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.permissions.request({apis: ['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.permissions.request({apis: ['chromeAuthPrivate']}, fail(error_msg));
+ chrome.permissions.remove({apis: ['chromeAuthPrivate']}, fail(error_msg));
+ },
+
+ function unknownPermission() {
+ var error_msg = UNKNOWN_PERMISSIONS_ERROR.replace('*', 'asdf');
+ chrome.permissions.request({apis: ['asdf']}, fail(error_msg));
+ }
+]);
+</script>

Powered by Google App Engine
This is Rietveld 408576698