Bug 1197461 - Tests for Permissions.revoke. r=poiru,baku
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Wed, 02 Mar 2016 21:09:56 +0000
changeset 322855 990eeaa39c299b43c06b5b9b04951c8cf8b8b421
parent 322854 59b8d765123ce48d13db01a00a3d3fc628ad67e8
child 322856 860dc7cb6b778bb5638801e41a1f4bd5dbd4c8da
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspoiru, baku
bugs1197461
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1197461 - Tests for Permissions.revoke. r=poiru,baku
dom/permission/tests/test_permissions_api.html
--- a/dom/permission/tests/test_permissions_api.html
+++ b/dom/permission/tests/test_permissions_api.html
@@ -37,27 +37,49 @@ function setPermissions(action) {
   });
   return new Promise((resolve, reject) => {
     SpecialPowers.popPermissions(() => {
       SpecialPowers.pushPermissions(permissions, resolve);
     });
   });
 }
 
+function revokePermissions(action) {
+  return Promise.all(PERMISSIONS.map(x =>
+    navigator.permissions.revoke({ name: x.name }).then(
+      result => is(result.state, "prompt", `correct state for '${x.name}'`),
+      error => ok(false, `revoke should not have rejected for '${x.name}'`))
+  ));
+}
+
+function revokeUnsupportedPermissions() {
+  return Promise.all(UNSUPPORTED_PERMISSIONS.map(name =>
+    navigator.permissions.revoke({ name: name }).then(
+      result => ok(false, `revoke should not have resolved for '${name}'`),
+      error => is(error.name, 'TypeError', `revoke should have thrown TypeError for '${name}'`))
+  ));
+}
+
+function revokeUserVisiblePushPermission() {
+  return navigator.permissions.revoke({ name: 'push', userVisible: true }).then(
+    result => ok(false, `revoke should not have resolved for userVisible push`),
+    error => ok(true, `revoke should have rejected for userVisible push`));
+}
+
 function checkPermissions(state) {
   return Promise.all(PERMISSIONS.map(x => {
     return navigator.permissions.query({ name: x.name }).then(
       result => is(result.state, state, `correct state for '${x.name}'`),
       error => ok(false, `query should not have rejected for '${x.name}'`));
   }));
 }
 
 function checkUnsupportedPermissions() {
   return Promise.all(UNSUPPORTED_PERMISSIONS.map(name => {
-    return navigator.permissions.query({ name }).then(
+    return navigator.permissions.query({ name: name }).then(
       result => ok(false, `query should not have resolved for '${name}'`),
       error => {
         is(error.name, 'TypeError',
            `query should have thrown TypeError for '${name}'`);
       });
   }));
 }
 
@@ -97,29 +119,40 @@ function testStatusOnChange() {
 }
 
 function testInvalidQuery() {
   navigator.permissions.query({ name: 'invalid' }).then(
     result => ok(false, 'invalid query should not have resolved'),
     error => ok(true, 'invalid query should have rejected'));
 }
 
+function testInvalidRevoke() {
+  navigator.permissions.revoke({ name: 'invalid' }).then(
+    result => ok(false, 'invalid revoke should not have resolved'),
+    error => ok(true, 'invalid revoke should have rejected'));
+}
+
 function runTests() {
   checkUnsupportedPermissions()
     .then(checkUserVisiblePushPermission)
     .then(() => setPermissions(UNKNOWN_ACTION))
     .then(() => checkPermissions('prompt'))
     .then(() => setPermissions(PROMPT_ACTION))
     .then(() => checkPermissions('prompt'))
     .then(() => setPermissions(ALLOW_ACTION))
     .then(() => checkPermissions('granted'))
     .then(() => setPermissions(DENY_ACTION))
     .then(() => checkPermissions('denied'))
     .then(testStatusOnChange)
     .then(testInvalidQuery)
+    .then(revokeUnsupportedPermissions)
+    .then(revokeUserVisiblePushPermission)
+    .then(revokePermissions)
+    .then(() => checkPermissions('prompt'))
+    .then(testInvalidRevoke)
     .then(SimpleTest.finish)
     .catch ((e) => {
       ok(false, 'Unexpected error ' + e);
       SimpleTest.finish();
     });
 }
 </script>
 </pre>