Bug 1221104 - Revoke 'midi' permission queries with TypeError. r=baku
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Fri, 18 Dec 2015 15:02:50 +0200
changeset 277007 8feecfc42ddde37ac5273b98c9f9ce114b86c897
parent 277006 279077cb41922135036667f26fd80ab8a6d65525
child 277008 bd9a30ae129298318684ec889b2833e6ccd86dc7
push id16724
push usercbook@mozilla.com
push dateMon, 21 Dec 2015 11:00:52 +0000
treeherderfx-team@3f3f0361567c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1221104
milestone46.0a1
Bug 1221104 - Revoke 'midi' permission queries with TypeError. r=baku According to the spec, we should reject unsupported permissions with a TypeError. This removes the 'midi' entry entirely so that we get the expected behaviour.
dom/permission/PermissionUtils.cpp
dom/permission/Permissions.cpp
dom/permission/tests/test_permissions_api.html
dom/webidl/Permissions.webidl
--- a/dom/permission/PermissionUtils.cpp
+++ b/dom/permission/PermissionUtils.cpp
@@ -8,18 +8,17 @@
 
 namespace mozilla {
 namespace dom {
 
 const char* kPermissionTypes[] = {
   "geo",
   "desktop-notification",
   // Alias `push` to `desktop-notification`.
-  "desktop-notification",
-  "midi"
+  "desktop-notification"
 };
 
 // `-1` for the last null entry.
 const size_t kPermissionNameCount =
   MOZ_ARRAY_LENGTH(PermissionNameValues::strings) - 1;
 
 static_assert(MOZ_ARRAY_LENGTH(kPermissionTypes) == kPermissionNameCount,
               "kPermissionTypes and PermissionName count should match");
--- a/dom/permission/Permissions.cpp
+++ b/dom/permission/Permissions.cpp
@@ -79,18 +79,18 @@ CreatePermissionStatus(JSContext* aCx,
   switch (permission.mName) {
     case PermissionName::Geolocation:
     case PermissionName::Notifications:
       return PermissionStatus::Create(aWindow, permission.mName, aRv);
 
     case PermissionName::Push:
       return CreatePushPermissionStatus(aCx, aPermission, aWindow, aRv);
 
-    case PermissionName::Midi:
     default:
+      MOZ_ASSERT_UNREACHABLE("Unhandled type");
       aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
       return nullptr;
   }
 }
 
 } // namespace
 
 already_AddRefed<Promise>
--- a/dom/permission/tests/test_permissions_api.html
+++ b/dom/permission/tests/test_permissions_api.html
@@ -22,17 +22,18 @@ SimpleTest.waitForExplicitFinish();
 
 const PERMISSIONS = [
   { name: 'geolocation', perm: 'geo' },
   { name: 'notifications', perm: 'desktop-notification' },
   { name: 'push', perm: 'desktop-notification' },
 ];
 
 const UNSUPPORTED_PERMISSIONS = [
-  'midi',
+  'foobarbaz',  // Not in spec, for testing only.
+  'midi'
 ];
 
 function setup() {
   return new Promise((resolve, reject) => {
     SpecialPowers.pushPrefEnv({'set': [
       ['dom.permissions.enabled', true],
     ]}, resolve);
   });
@@ -56,17 +57,20 @@ function checkPermissions(state) {
       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(
       result => ok(false, `query should not have resolved for '${name}'`),
-      error => ok(true, `query should have rejected for '${name}'`));
+      error => {
+        is(error.name, 'TypeError',
+           `query should have thrown TypeError for '${name}'`);
+      });
   }));
 }
 
 function checkUserVisiblePushPermission() {
   return navigator.permissions.query({ name: 'push', userVisible: true }).then(
     result => ok(false, `query should not have resolved for userVisible push`),
     error => ok(true, `query should have rejected for userVisible push`));
 }
--- a/dom/webidl/Permissions.webidl
+++ b/dom/webidl/Permissions.webidl
@@ -5,18 +5,18 @@
  *
  * The origin of this IDL file is
  * https://w3c.github.io/permissions/#permissions-interface
  */
 
 enum PermissionName {
   "geolocation",
   "notifications",
-  "push",
-  "midi"
+  "push"
+  // Unsupported: "midi"
 };
 
 dictionary PermissionDescriptor {
   required PermissionName name;
 };
 
 dictionary PushPermissionDescriptor : PermissionDescriptor {
   boolean userVisible = false;