From 2dd4dbb9c91430f53a04a20aa04d22e1cb8315ec Mon Sep 17 00:00:00 2001 From: Ben Delevingne Date: Wed, 21 Oct 2020 10:59:32 +0000 Subject: [PATCH] Bug 1672347 - remove defer from devtools/shared/discovery/tests/xpcshell. r=Honza Differential Revision: https://phabricator.services.mozilla.com/D94283 --- .../tests/xpcshell/test_protocol_async.js | 39 +++--- .../xpcshell/test_protocol_longstring.js | 118 +++++++++--------- 2 files changed, 78 insertions(+), 79 deletions(-) diff --git a/devtools/shared/protocol/tests/xpcshell/test_protocol_async.js b/devtools/shared/protocol/tests/xpcshell/test_protocol_async.js index a5258cb75ad7..f0628fd1af0b 100644 --- a/devtools/shared/protocol/tests/xpcshell/test_protocol_async.js +++ b/devtools/shared/protocol/tests/xpcshell/test_protocol_async.js @@ -57,21 +57,20 @@ var RootActor = protocol.ActorClassWithSpec(rootSpec, { promiseReturn: function(toWait) { // Guarantee that this resolves after simpleReturn returns. - const deferred = defer(); - const sequence = this.sequence++; + return new Promise(resolve => { + const sequence = this.sequence++; - // Wait until the number of requests specified by toWait have - // happened, to test queuing. - const check = () => { - if (this.sequence - sequence < toWait) { - executeSoon(check); - return; - } - deferred.resolve(sequence); - }; - executeSoon(check); - - return deferred.promise; + // Wait until the number of requests specified by toWait have + // happened, to test queuing. + const check = () => { + if (this.sequence - sequence < toWait) { + executeSoon(check); + return; + } + resolve(sequence); + }; + executeSoon(check); + }); }, simpleThrow: function() { @@ -80,13 +79,13 @@ var RootActor = protocol.ActorClassWithSpec(rootSpec, { promiseThrow: function() { // Guarantee that this resolves after simpleReturn returns. - const deferred = defer(); - let sequence = this.sequence++; - // This should be enough to force a failure if the code is broken. - do_timeout(150, () => { - deferred.reject(sequence++); + return new Promise((resolve, reject) => { + let sequence = this.sequence++; + // This should be enough to force a failure if the code is broken. + do_timeout(150, () => { + reject(sequence++); + }); }); - return deferred.promise; }, }); diff --git a/devtools/shared/protocol/tests/xpcshell/test_protocol_longstring.js b/devtools/shared/protocol/tests/xpcshell/test_protocol_longstring.js index 20b44b4b1352..6708c59edc8c 100644 --- a/devtools/shared/protocol/tests/xpcshell/test_protocol_longstring.js +++ b/devtools/shared/protocol/tests/xpcshell/test_protocol_longstring.js @@ -206,26 +206,26 @@ function run_test() { expectRootChildren(0); }) .then(() => { - const deferred = defer(); - rootFront.once("string-event", str => { - trace.expectSend({ type: "emitShortString", to: "" }); - trace.expectReceive({ - type: "string-event", - str: "abc", - from: "", - }); + return new Promise(resolve => { + rootFront.once("string-event", str => { + trace.expectSend({ type: "emitShortString", to: "" }); + trace.expectReceive({ + type: "string-event", + str: "abc", + from: "", + }); - Assert.ok(!!str); - strfront = str; - // Shouldn't generate any new references - expectRootChildren(0); - // will generate no packets. - strfront.string().then(value => { - deferred.resolve(value); + Assert.ok(!!str); + strfront = str; + // Shouldn't generate any new references + expectRootChildren(0); + // will generate no packets. + strfront.string().then(value => { + resolve(value); + }); }); + rootFront.emitShortString(); }); - rootFront.emitShortString(); - return deferred.promise; }) .then(value => { Assert.equal(value, SHORT_STR); @@ -235,52 +235,52 @@ function run_test() { return strfront.release(); }) .then(() => { - const deferred = defer(); - rootFront.once("string-event", str => { - trace.expectSend({ type: "emitLongString", to: "" }); - trace.expectReceive({ - type: "string-event", - str: { - type: "longString", - actor: "", - length: 16, - initial: "abcde", - }, - from: "", - }); + return new Promise(resolve => { + rootFront.once("string-event", str => { + trace.expectSend({ type: "emitLongString", to: "" }); + trace.expectReceive({ + type: "string-event", + str: { + type: "longString", + actor: "", + length: 16, + initial: "abcde", + }, + from: "", + }); - Assert.ok(!!str); - // Should generate one new reference - expectRootChildren(1); - strfront = str; - strfront.string().then(value => { - trace.expectSend({ - type: "substring", - start: 5, - end: 10, - to: "", - }); - trace.expectReceive({ substring: "fghij", from: "" }); - trace.expectSend({ - type: "substring", - start: 10, - end: 15, - to: "", - }); - trace.expectReceive({ substring: "klmno", from: "" }); - trace.expectSend({ - type: "substring", - start: 15, - end: 20, - to: "", - }); - trace.expectReceive({ substring: "p", from: "" }); + Assert.ok(!!str); + // Should generate one new reference + expectRootChildren(1); + strfront = str; + strfront.string().then(value => { + trace.expectSend({ + type: "substring", + start: 5, + end: 10, + to: "", + }); + trace.expectReceive({ substring: "fghij", from: "" }); + trace.expectSend({ + type: "substring", + start: 10, + end: 15, + to: "", + }); + trace.expectReceive({ substring: "klmno", from: "" }); + trace.expectSend({ + type: "substring", + start: 15, + end: 20, + to: "", + }); + trace.expectReceive({ substring: "p", from: "" }); - deferred.resolve(value); + resolve(value); + }); }); + rootFront.emitLongString(); }); - rootFront.emitLongString(); - return deferred.promise; }) .then(value => { Assert.equal(value, LONG_STR);