Bug 1591102 - Let some SpecialPowers.pushPermissions callers use promises r=jdm
authorRob Wu <rob@robwu.nl>
Sun, 27 Oct 2019 15:28:41 +0000
changeset 499399 cc7ea5119035faeb9fd28a53abdefa1e52c21ec9
parent 499398 1d5f3e7514333591327df1c9bb4feb403dc2705f
child 499400 c46d79d9d4ae8e4786d6883c2b50a9930dee9a0d
push id98931
push userrob@robwu.nl
push dateSun, 27 Oct 2019 15:30:10 +0000
treeherderautoland@cc7ea5119035 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1591102
milestone72.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 1591102 - Let some SpecialPowers.pushPermissions callers use promises r=jdm Some callers of SpecialPowers.pushPermissions wrapped the call in a promise. That is not needed; directly use the returned promise instead. Differential Revision: https://phabricator.services.mozilla.com/D50487
browser/base/content/test/alerts/head.js
devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html
dom/media/test/AutoplayTestUtils.js
dom/plugins/test/mochitest/test_bug1165981.html
dom/push/test/test_utils.js
--- a/browser/base/content/test/alerts/head.js
+++ b/browser/base/content/test/alerts/head.js
@@ -1,21 +1,16 @@
 async function addNotificationPermission(originString) {
-  return new Promise(resolve => {
-    SpecialPowers.pushPermissions(
-      [
-        {
-          type: "desktop-notification",
-          allow: true,
-          context: originString,
-        },
-      ],
-      resolve
-    );
-  });
+  return SpecialPowers.pushPermissions([
+    {
+      type: "desktop-notification",
+      allow: true,
+      context: originString,
+    },
+  ]);
 }
 
 /**
  * Similar to `BrowserTestUtils.closeWindow`, but
  * doesn't call `window.close()`.
  */
 function promiseWindowClosed(window) {
   return new Promise(function(resolve) {
--- a/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html
@@ -8,20 +8,18 @@
 <script type="text/javascript">
 
 "use strict";
 
 let registration;
 let subscription;
 
 const registerServiceWorker = async function() {
-  await new Promise(resolve => {
-    const perm = { type: "desktop-notification", allow: true, context: document };
-    SpecialPowers.pushPermissions([perm], resolve);
-  });
+  const perm = { type: "desktop-notification", allow: true, context: document };
+  await SpecialPowers.pushPermissions([perm]);
 
   try {
     registration = await navigator.serviceWorker.register("push-sw.js");
     dump("Push service worker registered\n");
   } catch (e) {
     dump("Push service worker not registered: " + e + "\n");
   }
 };
--- a/dom/media/test/AutoplayTestUtils.js
+++ b/dom/media/test/AutoplayTestUtils.js
@@ -26,21 +26,16 @@ function log(msg) {
   var log_pane = document.body;
   log_pane.appendChild(document.createTextNode(msg));
   log_pane.appendChild(document.createElement("br"));
 }
 
 const autoplayPermission = "autoplay-media";
 
 async function pushAutoplayAllowedPermission() {
-  return new Promise((resolve, reject) => {
-    SpecialPowers.pushPermissions(
-      [
-        {
-          type: autoplayPermission,
-          allow: true,
-          context: document,
-        },
-      ],
-      resolve
-    );
-  });
+  return SpecialPowers.pushPermissions([
+    {
+      type: autoplayPermission,
+      allow: true,
+      context: document,
+    },
+  ]);
 }
--- a/dom/plugins/test/mochitest/test_bug1165981.html
+++ b/dom/plugins/test/mochitest/test_bug1165981.html
@@ -38,19 +38,17 @@
           obj.width = 200;
           obj.height = 200;
           document.body.appendChild(obj);
       }
 
       async function run() {
         ok(await SpecialPowers.setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Shockwave Flash"), "Should find allowed test flash plugin");
         ok(!await SpecialPowers.setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Third Test Plug-in"), "Should not find disallowed plugin");
-        await new Promise(resolve => {
-          SpecialPowers.pushPermissions([{type: "plugin:flash", allow: true, context: document}], resolve);
-        });
+        await SpecialPowers.pushPermissions([{type: "plugin:flash", allow: true, context: document}]);
 
         createNode("plugin-flash", "application/x-shockwave-flash-test");
         createNode("disallowedPlugin", "application/x-third-test");
         var pluginElement = document.getElementById("plugin-flash");
         is(pluginElement.identifierToStringTest("foo"), "foo", "Should be able to call a function provided by the plugin");
 
         pluginElement = document.getElementById("disallowedPlugin");
         is(typeof pluginElement.identifierToStringTest, "undefined", "Should NOT be able to call a function on a disallowed plugin");
--- a/dom/push/test/test_utils.js
+++ b/dom/push/test/test_utils.js
@@ -167,22 +167,19 @@ class MockWebSocket {
 SimpleTest.registerCleanupFunction(async function() {
   await new Promise(resolve => SpecialPowers.flushPermissions(resolve));
   await SpecialPowers.flushPrefEnv();
   await restorePushService();
   await teardownMockPushSocket();
 });
 
 function setPushPermission(allow) {
-  return new Promise(resolve => {
-    SpecialPowers.pushPermissions(
-      [{ type: "desktop-notification", allow, context: document }],
-      resolve
-    );
-  });
+  return SpecialPowers.pushPermissions([
+    { type: "desktop-notification", allow, context: document },
+  ]);
 }
 
 function setupPrefs() {
   return SpecialPowers.pushPrefEnv({
     set: [
       ["dom.push.enabled", true],
       ["dom.push.connection.enabled", true],
       ["dom.push.maxRecentMessageIDsPerSubscription", 0],