From 34c77beb984be5c4dc4215cfb812b145086f8397 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Sun, 27 Oct 2019 15:28:41 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- browser/base/content/test/alerts/head.js | 19 +++++++------------ .../resources/service-workers/push-sw.html | 6 ++---- dom/media/test/AutoplayTestUtils.js | 19 +++++++------------ .../test/mochitest/test_bug1165981.html | 4 +--- dom/push/test/test_utils.js | 9 +++------ 5 files changed, 20 insertions(+), 37 deletions(-) diff --git a/browser/base/content/test/alerts/head.js b/browser/base/content/test/alerts/head.js index 94a7324fa089..626a0ae33ab5 100644 --- a/browser/base/content/test/alerts/head.js +++ b/browser/base/content/test/alerts/head.js @@ -1,16 +1,11 @@ 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, + }, + ]); } /** diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html b/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html index e03fc2268221..174d35722b78 100644 --- a/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html +++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html @@ -13,10 +13,8 @@ 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"); diff --git a/dom/media/test/AutoplayTestUtils.js b/dom/media/test/AutoplayTestUtils.js index 5f34f15b61b8..7006aae3749b 100644 --- a/dom/media/test/AutoplayTestUtils.js +++ b/dom/media/test/AutoplayTestUtils.js @@ -31,16 +31,11 @@ function log(msg) { 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, + }, + ]); } diff --git a/dom/plugins/test/mochitest/test_bug1165981.html b/dom/plugins/test/mochitest/test_bug1165981.html index 04331e0ba556..7b35de55905e 100644 --- a/dom/plugins/test/mochitest/test_bug1165981.html +++ b/dom/plugins/test/mochitest/test_bug1165981.html @@ -43,9 +43,7 @@ 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"); diff --git a/dom/push/test/test_utils.js b/dom/push/test/test_utils.js index cd526aab15e2..73d49cc0d642 100644 --- a/dom/push/test/test_utils.js +++ b/dom/push/test/test_utils.js @@ -172,12 +172,9 @@ SimpleTest.registerCleanupFunction(async function() { }); 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() {