Bug 1549351 - Add tests for UA rejected promise; r=smaug
authorEdgar Chen <echen@mozilla.com>
Mon, 20 May 2019 09:28:23 +0000
changeset 474482 bba4ef388cc0906abaa9bab96c0e9c3bfec5490a
parent 474481 0e88a0a379f37595e17d7b516c90d8d2962798d0
child 474483 6e5b24c61e3aa7b01cebef924128bdf3b8019d7c
push id36040
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:43:21 +0000
treeherdermozilla-central@319a369ccde4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1549351
milestone68.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 1549351 - Add tests for UA rejected promise; r=smaug Differential Revision: https://phabricator.services.mozilla.com/D31733
testing/web-platform/tests/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/support/promise-rejection-events.js
--- a/testing/web-platform/tests/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/support/promise-rejection-events.js
+++ b/testing/web-platform/tests/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/support/promise-rejection-events.js
@@ -157,16 +157,34 @@ async_test(function(t) {
   var e = new Error();
   var p;
 
   onUnhandledSucceed(t, e, function() { return p; });
 
   p = Promise.all([Promise.reject(e)]);
 }, 'unhandledrejection: from Promise.reject, indirected through Promise.all');
 
+async_test(function(t) {
+  var p;
+
+  var unhandled = function(ev) {
+    if (ev.promise === p) {
+      t.step(function() {
+        assert_equals(ev.reason.name, 'InvalidStateError');
+        assert_equals(ev.promise, p);
+      });
+      t.done();
+    }
+  };
+  addEventListener('unhandledrejection', unhandled);
+  ensureCleanup(t, unhandled);
+
+  p = createImageBitmap(new Blob());
+}, 'unhandledrejection: from createImageBitmap which is UA triggered');
+
 //
 // Negative unhandledrejection/rejectionhandled tests with immediate attachment
 //
 
 async_test(function(t) {
   var e = new Error();
   var p;
 
@@ -265,16 +283,26 @@ async_test(function(t) {
     p = Promise.resolve().then(function() {
       return Promise.reject(e);
     })
     .catch(function() {});
   });
 }, 'no unhandledrejection/rejectionhandled: all inside a queued task, a rejection handler attached synchronously to ' +
    'a promise created from returning a Promise.reject-created promise in a fulfillment handler');
 
+async_test(function(t) {
+  var p;
+
+  onUnhandledFail(t, function() { return p; });
+
+  var unreached = t.unreached_func('promise should not be fulfilled');
+  p = createImageBitmap(new Blob()).then(unreached, function() {});
+}, 'no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a promise created from ' +
+   'createImageBitmap');
+
 //
 // Negative unhandledrejection/rejectionhandled tests with microtask-delayed attachment
 //
 
 async_test(function(t) {
   var e = new Error();
   var p;
 
@@ -654,16 +682,53 @@ async_test(function(t) {
     var unreached = t.unreached_func('promise should not be fulfilled');
     p.then(unreached, function(reason) {
       assert_equals(reason, e);
       setTimeout(function() { t.done(); }, 10);
     });
   }, 10);
 }, 'delayed handling: delaying handling by setTimeout(,10) will cause both events to fire');
 
+async_test(function(t) {
+  var unhandledPromises = [];
+  var unhandledReasons = [];
+  var p;
+
+  var unhandled = function(ev) {
+    if (ev.promise === p) {
+      t.step(function() {
+        unhandledPromises.push(ev.promise);
+        unhandledReasons.push(ev.reason.name);
+      });
+    }
+  };
+  var handled = function(ev) {
+    if (ev.promise === p) {
+      t.step(function() {
+        assert_array_equals(unhandledPromises, [p]);
+        assert_array_equals(unhandledReasons, ['InvalidStateError']);
+        assert_equals(ev.promise, p);
+        assert_equals(ev.reason.name, 'InvalidStateError');
+      });
+    }
+  };
+  addEventListener('unhandledrejection', unhandled);
+  addEventListener('rejectionhandled', handled);
+  ensureCleanup(t, unhandled, handled);
+
+  p = createImageBitmap(new Blob());
+  setTimeout(function() {
+    var unreached = t.unreached_func('promise should not be fulfilled');
+    p.then(unreached, function(reason) {
+      assert_equals(reason.name, 'InvalidStateError');
+      setTimeout(function() { t.done(); }, 10);
+    });
+  }, 10);
+}, 'delayed handling: delaying handling rejected promise created from createImageBitmap will cause both events to fire');
+
 //
 // Miscellaneous tests about integration with the rest of the platform
 //
 
 async_test(function(t) {
   var e = new Error();
   var l = function(ev) {
     var order = [];