From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/promise/tests/chrome.ini | 7 + .../tests/file_promise_and_timeout_ordering.js | 18 + dom/promise/tests/file_promise_xrays.html | 32 + dom/promise/tests/mochitest.ini | 18 + dom/promise/tests/promise_uncatchable_exception.js | 9 + dom/promise/tests/test_bug883683.html | 41 + dom/promise/tests/test_on_new_promise.html | 45 ++ dom/promise/tests/test_on_promise_settled.html | 54 ++ .../tests/test_on_promise_settled_duplicates.html | 59 ++ dom/promise/tests/test_promise.html | 831 +++++++++++++++++++++ .../tests/test_promise_and_timeout_ordering.html | 15 + .../test_promise_and_timeout_ordering_workers.html | 13 + .../tests/test_promise_uncatchable_exception.html | 35 + dom/promise/tests/test_promise_utils.html | 320 ++++++++ dom/promise/tests/test_promise_xrays.html | 365 +++++++++ dom/promise/tests/test_resolve.html | 67 ++ dom/promise/tests/test_resolver_return_value.html | 40 + dom/promise/tests/test_species_getter.html | 24 + .../tests/test_thenable_vs_promise_ordering.html | 27 + dom/promise/tests/test_webassembly_compile.html | 174 +++++ dom/promise/tests/unit/test_monitor_uncaught.js | 274 +++++++ dom/promise/tests/unit/xpcshell.ini | 5 + 22 files changed, 2473 insertions(+) create mode 100644 dom/promise/tests/chrome.ini create mode 100644 dom/promise/tests/file_promise_and_timeout_ordering.js create mode 100644 dom/promise/tests/file_promise_xrays.html create mode 100644 dom/promise/tests/mochitest.ini create mode 100644 dom/promise/tests/promise_uncatchable_exception.js create mode 100644 dom/promise/tests/test_bug883683.html create mode 100644 dom/promise/tests/test_on_new_promise.html create mode 100644 dom/promise/tests/test_on_promise_settled.html create mode 100644 dom/promise/tests/test_on_promise_settled_duplicates.html create mode 100644 dom/promise/tests/test_promise.html create mode 100644 dom/promise/tests/test_promise_and_timeout_ordering.html create mode 100644 dom/promise/tests/test_promise_and_timeout_ordering_workers.html create mode 100644 dom/promise/tests/test_promise_uncatchable_exception.html create mode 100644 dom/promise/tests/test_promise_utils.html create mode 100644 dom/promise/tests/test_promise_xrays.html create mode 100644 dom/promise/tests/test_resolve.html create mode 100644 dom/promise/tests/test_resolver_return_value.html create mode 100644 dom/promise/tests/test_species_getter.html create mode 100644 dom/promise/tests/test_thenable_vs_promise_ordering.html create mode 100644 dom/promise/tests/test_webassembly_compile.html create mode 100644 dom/promise/tests/unit/test_monitor_uncaught.js create mode 100644 dom/promise/tests/unit/xpcshell.ini (limited to 'dom/promise/tests') diff --git a/dom/promise/tests/chrome.ini b/dom/promise/tests/chrome.ini new file mode 100644 index 000000000..c6dc855c4 --- /dev/null +++ b/dom/promise/tests/chrome.ini @@ -0,0 +1,7 @@ +[DEFAULT] + +[test_on_new_promise.html] +[test_on_promise_settled.html] +[test_on_promise_settled_duplicates.html] +[test_promise_xrays.html] +support-files = file_promise_xrays.html diff --git a/dom/promise/tests/file_promise_and_timeout_ordering.js b/dom/promise/tests/file_promise_and_timeout_ordering.js new file mode 100644 index 000000000..c83b5a6ac --- /dev/null +++ b/dom/promise/tests/file_promise_and_timeout_ordering.js @@ -0,0 +1,18 @@ +var log = []; +var resolvedPromise = Promise.resolve(null); +function schedulePromiseTask(f) { + resolvedPromise.then(f); +} + +setTimeout(function() { + log.push('t1start'); + schedulePromiseTask(function() { + log.push('promise'); + }); + log.push('t1end'); +}, 10); + +setTimeout(function() { + log.push('t2'); + postMessage(log.join(', ')); +}, 10); diff --git a/dom/promise/tests/file_promise_xrays.html b/dom/promise/tests/file_promise_xrays.html new file mode 100644 index 000000000..73f9bf7d7 --- /dev/null +++ b/dom/promise/tests/file_promise_xrays.html @@ -0,0 +1,32 @@ + + + + diff --git a/dom/promise/tests/mochitest.ini b/dom/promise/tests/mochitest.ini new file mode 100644 index 000000000..0e6466d16 --- /dev/null +++ b/dom/promise/tests/mochitest.ini @@ -0,0 +1,18 @@ +[DEFAULT] +support-files = + promise_uncatchable_exception.js + +[test_bug883683.html] +[test_promise.html] +[test_promise_uncatchable_exception.html] +skip-if = debug == false +[test_promise_utils.html] +[test_resolve.html] +[test_resolver_return_value.html] +[test_thenable_vs_promise_ordering.html] +[test_promise_and_timeout_ordering.html] +support-files = file_promise_and_timeout_ordering.js +[test_promise_and_timeout_ordering_workers.html] +support-files = file_promise_and_timeout_ordering.js +[test_species_getter.html] +[test_webassembly_compile.html] diff --git a/dom/promise/tests/promise_uncatchable_exception.js b/dom/promise/tests/promise_uncatchable_exception.js new file mode 100644 index 000000000..d062e21af --- /dev/null +++ b/dom/promise/tests/promise_uncatchable_exception.js @@ -0,0 +1,9 @@ +postMessage("Done", "*"); + +var p = new Promise(function(resolve, reject) { + TestFunctions.throwUncatchableException(); + ok(false, "Shouldn't get here!"); +}).catch(function(exception) { + ok(false, "Shouldn't get here!"); +}); +ok(false, "Shouldn't get here!"); diff --git a/dom/promise/tests/test_bug883683.html b/dom/promise/tests/test_bug883683.html new file mode 100644 index 000000000..ab23ca10d --- /dev/null +++ b/dom/promise/tests/test_bug883683.html @@ -0,0 +1,41 @@ + + + + Promise - bug 883683 + + + + +

+ +
+
+
+ + diff --git a/dom/promise/tests/test_on_new_promise.html b/dom/promise/tests/test_on_new_promise.html new file mode 100644 index 000000000..634dd7dda --- /dev/null +++ b/dom/promise/tests/test_on_new_promise.html @@ -0,0 +1,45 @@ + + + + + + + Test for interaction with SpiderMonkey's Debugger.prototype.onNewPromise + + + + +

+ +
+  
+
+ + + diff --git a/dom/promise/tests/test_on_promise_settled.html b/dom/promise/tests/test_on_promise_settled.html new file mode 100644 index 000000000..4061d3997 --- /dev/null +++ b/dom/promise/tests/test_on_promise_settled.html @@ -0,0 +1,54 @@ + + + + + + + Test for interaction with SpiderMonkey's Debugger.prototype.onNewPromise + + + + +

+ +
+  
+
+ + + diff --git a/dom/promise/tests/test_on_promise_settled_duplicates.html b/dom/promise/tests/test_on_promise_settled_duplicates.html new file mode 100644 index 000000000..5a1eddb1e --- /dev/null +++ b/dom/promise/tests/test_on_promise_settled_duplicates.html @@ -0,0 +1,59 @@ + + + + + + + Test for interaction with SpiderMonkey's Debugger.prototype.onNewPromise + + + + +

+ +
+  
+
+ + + diff --git a/dom/promise/tests/test_promise.html b/dom/promise/tests/test_promise.html new file mode 100644 index 000000000..af185efcd --- /dev/null +++ b/dom/promise/tests/test_promise.html @@ -0,0 +1,831 @@ + + + + Basic Promise Test + + + + +

+ +
+
+
+ + + diff --git a/dom/promise/tests/test_promise_and_timeout_ordering.html b/dom/promise/tests/test_promise_and_timeout_ordering.html new file mode 100644 index 000000000..1dfa13bbb --- /dev/null +++ b/dom/promise/tests/test_promise_and_timeout_ordering.html @@ -0,0 +1,15 @@ + + +Test for promise and timeout ordering + + +
+ + diff --git a/dom/promise/tests/test_promise_and_timeout_ordering_workers.html b/dom/promise/tests/test_promise_and_timeout_ordering_workers.html new file mode 100644 index 000000000..122a794db --- /dev/null +++ b/dom/promise/tests/test_promise_and_timeout_ordering_workers.html @@ -0,0 +1,13 @@ + + +Test for promise and timeout ordering in workers + + +
+ diff --git a/dom/promise/tests/test_promise_uncatchable_exception.html b/dom/promise/tests/test_promise_uncatchable_exception.html new file mode 100644 index 000000000..8f7167d56 --- /dev/null +++ b/dom/promise/tests/test_promise_uncatchable_exception.html @@ -0,0 +1,35 @@ + + + + Promise - uncatchable exceptions + + + + +

+ +
+
+
+ + diff --git a/dom/promise/tests/test_promise_utils.html b/dom/promise/tests/test_promise_utils.html new file mode 100644 index 000000000..316ea02a5 --- /dev/null +++ b/dom/promise/tests/test_promise_utils.html @@ -0,0 +1,320 @@ + + + + Test for Promise.all, Promise.race + + + + +

+ +
+
+
+ + + diff --git a/dom/promise/tests/test_promise_xrays.html b/dom/promise/tests/test_promise_xrays.html new file mode 100644 index 000000000..55398167e --- /dev/null +++ b/dom/promise/tests/test_promise_xrays.html @@ -0,0 +1,365 @@ + + + + + + Test for Bug 1170760 + + + + + +Mozilla Bug 1170760 +

+ + +
+
+
+ + diff --git a/dom/promise/tests/test_resolve.html b/dom/promise/tests/test_resolve.html new file mode 100644 index 000000000..780eae6c6 --- /dev/null +++ b/dom/promise/tests/test_resolve.html @@ -0,0 +1,67 @@ + + + + Promise.resolve(anything) Test + + + + +

+ +
+
+
+ + + diff --git a/dom/promise/tests/test_resolver_return_value.html b/dom/promise/tests/test_resolver_return_value.html new file mode 100644 index 000000000..1fb9652ac --- /dev/null +++ b/dom/promise/tests/test_resolver_return_value.html @@ -0,0 +1,40 @@ + + + + + + Test for Bug 1120235 + + + + + +Mozilla Bug 1120235 +

+ +
+
+ + diff --git a/dom/promise/tests/test_species_getter.html b/dom/promise/tests/test_species_getter.html new file mode 100644 index 000000000..04e590a13 --- /dev/null +++ b/dom/promise/tests/test_species_getter.html @@ -0,0 +1,24 @@ + + +Test for ... + + +
+ diff --git a/dom/promise/tests/test_thenable_vs_promise_ordering.html b/dom/promise/tests/test_thenable_vs_promise_ordering.html new file mode 100644 index 000000000..161e95d75 --- /dev/null +++ b/dom/promise/tests/test_thenable_vs_promise_ordering.html @@ -0,0 +1,27 @@ + + +Test for promise resolution ordering with thenables and promises + + +
+ diff --git a/dom/promise/tests/test_webassembly_compile.html b/dom/promise/tests/test_webassembly_compile.html new file mode 100644 index 000000000..0243df49c --- /dev/null +++ b/dom/promise/tests/test_webassembly_compile.html @@ -0,0 +1,174 @@ + + + + WebAssembly.compile Test + + + + + + + + diff --git a/dom/promise/tests/unit/test_monitor_uncaught.js b/dom/promise/tests/unit/test_monitor_uncaught.js new file mode 100644 index 000000000..7dd80d212 --- /dev/null +++ b/dom/promise/tests/unit/test_monitor_uncaught.js @@ -0,0 +1,274 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var { utils: Cu } = Components; + +Cu.import("resource://gre/modules/Timer.jsm", this); +Cu.import("resource://testing-common/PromiseTestUtils.jsm", this); + +// Prevent test failures due to the unhandled rejections in this test file. +PromiseTestUtils.disableUncaughtRejectionObserverForSelfTest(); + +add_task(function* test_globals() { + Assert.equal(Promise.defer || undefined, undefined, "We are testing DOM Promise."); + Assert.notEqual(PromiseDebugging, undefined, "PromiseDebugging is available."); +}); + +add_task(function* test_promiseID() { + let p1 = new Promise(resolve => {}); + let p2 = new Promise(resolve => {}); + let p3 = p2.then(null, null); + let promise = [p1, p2, p3]; + + let identifiers = promise.map(PromiseDebugging.getPromiseID); + do_print("Identifiers: " + JSON.stringify(identifiers)); + let idSet = new Set(identifiers); + Assert.equal(idSet.size, identifiers.length, + "PromiseDebugging.getPromiseID returns a distinct id per promise"); + + let identifiers2 = promise.map(PromiseDebugging.getPromiseID); + Assert.equal(JSON.stringify(identifiers), + JSON.stringify(identifiers2), + "Successive calls to PromiseDebugging.getPromiseID return the same id for the same promise"); +}); + +add_task(function* test_observe_uncaught() { + // The names of Promise instances + let names = new Map(); + + // The results for UncaughtPromiseObserver callbacks. + let CallbackResults = function(name) { + this.name = name; + this.expected = new Set(); + this.observed = new Set(); + this.blocker = new Promise(resolve => this.resolve = resolve); + }; + CallbackResults.prototype = { + observe: function(promise) { + do_print(this.name + " observing Promise " + names.get(promise)); + Assert.equal(PromiseDebugging.getState(promise).state, "rejected", + this.name + " observed a rejected Promise"); + if (!this.expected.has(promise)) { + Assert.ok(false, + this.name + " observed a Promise that it expected to observe, " + + names.get(promise) + + " (" + PromiseDebugging.getPromiseID(promise) + + ", " + PromiseDebugging.getAllocationStack(promise) + ")"); + + } + Assert.ok(this.expected.delete(promise), + this.name + " observed a Promise that it expected to observe, " + + names.get(promise) + " (" + PromiseDebugging.getPromiseID(promise) + ")"); + Assert.ok(!this.observed.has(promise), + this.name + " observed a Promise that it has not observed yet"); + this.observed.add(promise); + if (this.expected.size == 0) { + this.resolve(); + } else { + do_print(this.name + " is still waiting for " + this.expected.size + " observations:"); + do_print(JSON.stringify(Array.from(this.expected.values(), (x) => names.get(x)))); + } + }, + }; + + let onLeftUncaught = new CallbackResults("onLeftUncaught"); + let onConsumed = new CallbackResults("onConsumed"); + + let observer = { + onLeftUncaught: function(promise, data) { + onLeftUncaught.observe(promise); + }, + onConsumed: function(promise) { + onConsumed.observe(promise); + }, + }; + + let resolveLater = function(delay = 20) { + return new Promise((resolve, reject) => setTimeout(resolve, delay)); + }; + let rejectLater = function(delay = 20) { + return new Promise((resolve, reject) => setTimeout(reject, delay)); + }; + let makeSamples = function*() { + yield { + promise: Promise.resolve(0), + name: "Promise.resolve", + }; + yield { + promise: Promise.resolve(resolve => resolve(0)), + name: "Resolution callback", + }; + yield { + promise: Promise.resolve(0).then(null, null), + name: "`then(null, null)`" + }; + yield { + promise: Promise.reject(0).then(null, () => {}), + name: "Reject and catch immediately", + }; + yield { + promise: resolveLater(), + name: "Resolve later", + }; + yield { + promise: Promise.reject("Simple rejection"), + leftUncaught: true, + consumed: false, + name: "Promise.reject", + }; + + // Reject a promise now, consume it later. + let p = Promise.reject("Reject now, consume later"); + setTimeout(() => p.then(null, () => { + do_print("Consumed promise"); + }), 200); + yield { + promise: p, + leftUncaught: true, + consumed: true, + name: "Reject now, consume later", + }; + + yield { + promise: Promise.all([ + Promise.resolve("Promise.all"), + rejectLater() + ]), + leftUncaught: true, + name: "Rejecting through Promise.all" + }; + yield { + promise: Promise.race([ + resolveLater(500), + Promise.reject(), + ]), + leftUncaught: true, // The rejection wins the race. + name: "Rejecting through Promise.race", + }; + yield { + promise: Promise.race([ + Promise.resolve(), + rejectLater(500) + ]), + leftUncaught: false, // The resolution wins the race. + name: "Resolving through Promise.race", + }; + + let boom = new Error("`throw` in the constructor"); + yield { + promise: new Promise(() => { throw boom; }), + leftUncaught: true, + name: "Throwing in the constructor", + }; + + let rejection = Promise.reject("`reject` during resolution"); + yield { + promise: rejection, + leftUncaught: false, + consumed: false, // `rejection` is consumed immediately (see below) + name: "Promise.reject, again", + }; + + yield { + promise: new Promise(resolve => resolve(rejection)), + leftUncaught: true, + consumed: false, + name: "Resolving with a rejected promise", + }; + + yield { + promise: Promise.resolve(0).then(() => rejection), + leftUncaught: true, + consumed: false, + name: "Returning a rejected promise from success handler", + }; + + yield { + promise: Promise.resolve(0).then(() => { throw new Error(); }), + leftUncaught: true, + consumed: false, + name: "Throwing during the call to the success callback", + }; + }; + let samples = []; + for (let s of makeSamples()) { + samples.push(s); + do_print("Promise '" + s.name + "' has id " + PromiseDebugging.getPromiseID(s.promise)); + } + + PromiseDebugging.addUncaughtRejectionObserver(observer); + + for (let s of samples) { + names.set(s.promise, s.name); + if (s.leftUncaught || false) { + onLeftUncaught.expected.add(s.promise); + } + if (s.consumed || false) { + onConsumed.expected.add(s.promise); + } + } + + do_print("Test setup, waiting for callbacks."); + yield onLeftUncaught.blocker; + + do_print("All calls to onLeftUncaught are complete."); + if (onConsumed.expected.size != 0) { + do_print("onConsumed is still waiting for the following Promise:"); + do_print(JSON.stringify(Array.from(onConsumed.expected.values(), (x) => names.get(x)))); + yield onConsumed.blocker; + } + + do_print("All calls to onConsumed are complete."); + let removed = PromiseDebugging.removeUncaughtRejectionObserver(observer); + Assert.ok(removed, "removeUncaughtRejectionObserver succeeded"); + removed = PromiseDebugging.removeUncaughtRejectionObserver(observer); + Assert.ok(!removed, "second call to removeUncaughtRejectionObserver didn't remove anything"); +}); + + +add_task(function* test_uninstall_observer() { + let Observer = function() { + this.blocker = new Promise(resolve => this.resolve = resolve); + this.active = true; + }; + Observer.prototype = { + set active(x) { + this._active = x; + if (x) { + PromiseDebugging.addUncaughtRejectionObserver(this); + } else { + PromiseDebugging.removeUncaughtRejectionObserver(this); + } + }, + onLeftUncaught: function() { + Assert.ok(this._active, "This observer is active."); + this.resolve(); + }, + onConsumed: function() { + Assert.ok(false, "We should not consume any Promise."); + }, + }; + + do_print("Adding an observer."); + let deactivate = new Observer(); + Promise.reject("I am an uncaught rejection."); + yield deactivate.blocker; + Assert.ok(true, "The observer has observed an uncaught Promise."); + deactivate.active = false; + do_print("Removing the observer, it should not observe any further uncaught Promise."); + + do_print("Rejecting a Promise and waiting a little to give a chance to observers."); + let wait = new Observer(); + Promise.reject("I am another uncaught rejection."); + yield wait.blocker; + yield new Promise(resolve => setTimeout(resolve, 100)); + // Normally, `deactivate` should not be notified of the uncaught rejection. + wait.active = false; +}); + +function run_test() { + run_next_test(); +} diff --git a/dom/promise/tests/unit/xpcshell.ini b/dom/promise/tests/unit/xpcshell.ini new file mode 100644 index 000000000..73df2380b --- /dev/null +++ b/dom/promise/tests/unit/xpcshell.ini @@ -0,0 +1,5 @@ +[DEFAULT] +head = +tail = + +[test_monitor_uncaught.js] -- cgit v1.2.3