Update web-platform-tests to revision e426a6933a05bf144eba06a1d4c47ba876a4e2d1

This commit is contained in:
WPT Sync Bot 2019-05-22 10:24:35 +00:00
parent 415b26e4f1
commit 5e5eccabf8
495 changed files with 14920 additions and 784 deletions

View file

@ -0,0 +1,146 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<div id="log"></div><br>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
'use strict';
setup({
allow_uncaught_exception: true
});
async_test(function(t) {
createIframeAndStartTest(t, function(w) {
let e = new Error();
let promise = new w.Promise(function(_, reject) {
setTimeout(function() {
reject(e);
}, 1);
});
let unhandled = function(evt) {
if (evt.promise === promise) {
t.step(function() {
assert_equals(evt.reason, e);
assert_equals(evt.promise, promise);
});
t.done();
}
};
let handled = function(evt) {
if (evt.promise === promise) {
t.step(function() {
assert_unreached('rejectionhandled event is not supposed to be triggered');
});
}
};
w.addEventListener('unhandledrejection', unhandled);
w.addEventListener('rejectionhandled', handled);
ensureCleanup(t, w, unhandled, handled);
});
}, "unhandledrejection: promise is created in iframe and being rejected elsewhere");
async_test(function(t) {
createIframeAndStartTest(t, function(w) {
let e = new Error();
let promise = w.Promise.reject(e);
let unhandled = function(evt) {
if (evt.promise === promise) {
t.step(function() {
assert_unreached('unhandledrejection event is not supposed to be triggered');
});
}
};
let handled = function(evt) {
if (evt.promise === promise) {
t.step(function() {
assert_unreached('rejectionhandled event is not supposed to be triggered');
});
}
};
w.addEventListener('unhandledrejection', unhandled);
w.addEventListener('rejectionhandled', handled);
ensureCleanup(t, w, unhandled, handled);
promise.catch(function() {});
setTimeout(function() {
t.done();
}, 10);
});
}, 'no unhandledrejection/rejectionhandled: promise is created in iframe and being rejected elsewhere');
async_test(function(t) {
createIframeAndStartTest(t, function(w) {
let e = new Error();
let promise = w.Promise.reject(e);
var unhandledPromises = [];
var unhandledReasons = [];
var handledPromises = [];
var handledReasons = [];
let unhandled = function(evt) {
if (evt.promise === promise) {
t.step(function() {
unhandledPromises.push(evt.promise);
unhandledReasons.push(evt.reason);
setTimeout(function() {
var unreached = t.unreached_func('promise should not be fulfilled');
promise.then(unreached, function(reason) {
assert_equals(reason, e);
setTimeout(function() {
assert_array_equals(handledPromises, [promise]);
assert_array_equals(handledReasons, [e]);
t.done();
}, 10);
});
}, 10);
});
}
};
let handled = function(evt) {
if (evt.promise === promise) {
t.step(function() {
assert_array_equals(unhandledPromises, [promise]);
assert_array_equals(unhandledReasons, [e]);
handledPromises.push(evt.promise);
handledReasons.push(evt.reason);
});
}
};
w.addEventListener('unhandledrejection', unhandled);
w.addEventListener('rejectionhandled', handled);
ensureCleanup(t, w, unhandled, handled);
});
}, 'delayed handling: promise is created in iframe and being rejected elsewhere');
// Helpers
function createIframeAndStartTest(t, runTest) {
var iframe = document.createElement("iframe");
iframe.onload = function() {
t.add_cleanup(() => iframe.remove());
runTest(iframe.contentWindow);
};
iframe.srcdoc = '';
document.documentElement.appendChild(iframe);
}
function ensureCleanup(t, win, unhandled, handled) {
t.add_cleanup(function() {
if (unhandled) {
win.removeEventListener('unhandledrejection', unhandled);
}
if (handled) {
win.removeEventListener('rejectionhandled', handled);
}
});
}
</script>

View file

@ -38,7 +38,7 @@ async_test(function(t) {
onUnhandledSucceed(t, e, function() { return p; });
p = new Promise(function(_, reject) {
postMessageTask(function() {
queueTask(function() {
reject(e);
});
});
@ -162,6 +162,24 @@ async_test(function(t) {
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
//
@ -261,7 +279,7 @@ async_test(function(t) {
onUnhandledFail(t, function() { return p; });
postMessageTask(function() {
queueTask(function() {
p = Promise.resolve().then(function() {
return Promise.reject(e);
})
@ -270,6 +288,16 @@ async_test(function(t) {
}, '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
//
@ -353,7 +381,7 @@ async_test(function(t) {
onUnhandledFail(t, function() { return p; });
postMessageTask(function() {
queueTask(function() {
p = Promise.reject(e);
mutationObserverMicrotask(function() {
Promise.resolve().then(function() {
@ -366,7 +394,7 @@ async_test(function(t) {
});
});
}, 'microtask nesting: attaching a handler inside a combination of mutationObserverMicrotask + promise microtasks, ' +
'all inside a postMessageTask');
'all inside a queueTask');
async_test(function(t) {
var e = new Error();
@ -413,7 +441,7 @@ async_test(function(t) {
onUnhandledFail(t, function() { return p; });
postMessageTask(function() {
queueTask(function() {
p = Promise.reject(e);
Promise.resolve().then(function() {
mutationObserverMicrotask(function() {
@ -426,7 +454,7 @@ async_test(function(t) {
});
});
}, 'microtask nesting: attaching a handler inside a combination of promise microtasks + mutationObserverMicrotask, ' +
'all inside a postMessageTask');
'all inside a queueTask');
async_test(function(t) {
var e = new Error();
@ -450,7 +478,7 @@ async_test(function(t) {
'all inside a setTimeout');
// For workers, postMessageTask() involves posting tasks to other threads, so
// For workers, queueTask() involves posting tasks to other threads, so
// the following tests don't work there.
if ('document' in self) {
@ -469,7 +497,7 @@ if ('document' in self) {
_reject = reject;
});
_reject(e);
postMessageTask(function() {
queueTask(function() {
var unreached = t.unreached_func('promise should not be fulfilled');
p.then(unreached, function() {});
});
@ -482,12 +510,12 @@ if ('document' in self) {
onUnhandledFail(t, function() { return p; });
p = Promise.reject(e);
postMessageTask(function() {
queueTask(function() {
Promise.resolve().then(function() {
p.catch(function() {});
});
});
}, 'delayed handling: postMessageTask after promise creation/rejection, plus promise microtasks, is not too late to ' +
}, 'delayed handling: queueTask after promise creation/rejection, plus promise microtasks, is not too late to ' +
'attach a rejection handler');
async_test(function(t) {
@ -496,7 +524,7 @@ if ('document' in self) {
onUnhandledFail(t, function() { return p; });
postMessageTask(function() {
queueTask(function() {
Promise.resolve().then(function() {
Promise.resolve().then(function() {
Promise.resolve().then(function() {
@ -508,7 +536,7 @@ if ('document' in self) {
});
});
p = Promise.reject(e);
}, 'delayed handling: postMessageTask before promise creation/rejection, plus many promise microtasks, is not too ' +
}, 'delayed handling: queueTask before promise creation/rejection, plus many promise microtasks, is not too ' +
'late to attach a rejection handler');
async_test(function(t) {
@ -518,7 +546,7 @@ if ('document' in self) {
onUnhandledFail(t, function() { return p; });
p = Promise.reject(e);
postMessageTask(function() {
queueTask(function() {
Promise.resolve().then(function() {
Promise.resolve().then(function() {
Promise.resolve().then(function() {
@ -529,7 +557,7 @@ if ('document' in self) {
});
});
});
}, 'delayed handling: postMessageTask after promise creation/rejection, plus many promise microtasks, is not too ' +
}, 'delayed handling: queueTask after promise creation/rejection, plus many promise microtasks, is not too ' +
'late to attach a rejection handler');
}
@ -548,8 +576,8 @@ async_test(function(t) {
_reject = reject;
});
_reject(e);
postMessageTask(function() {
postMessageTask(function() {
queueTask(function() {
queueTask(function() {
var unreached = t.unreached_func('promise should not be fulfilled');
p.then(unreached, function() {});
});
@ -563,14 +591,14 @@ async_test(function(t) {
onUnhandledSucceed(t, e, function() { return p; });
p = Promise.reject(e);
postMessageTask(function() {
postMessageTask(function() {
queueTask(function() {
queueTask(function() {
Promise.resolve().then(function() {
p.catch(function() {});
});
});
});
}, 'delayed handling: a nested-postMessageTask after promise creation/rejection, plus promise microtasks, is too ' +
}, 'delayed handling: a nested-queueTask after promise creation/rejection, plus promise microtasks, is too ' +
'late to attach a rejection handler');
async_test(function(t) {
@ -579,8 +607,8 @@ async_test(function(t) {
onUnhandledSucceed(t, e, function() { return p; });
postMessageTask(function() {
postMessageTask(function() {
queueTask(function() {
queueTask(function() {
Promise.resolve().then(function() {
Promise.resolve().then(function() {
Promise.resolve().then(function() {
@ -593,7 +621,7 @@ async_test(function(t) {
});
});
p = Promise.reject(e);
}, 'delayed handling: a nested-postMessageTask before promise creation/rejection, plus many promise microtasks, is ' +
}, 'delayed handling: a nested-queueTask before promise creation/rejection, plus many promise microtasks, is ' +
'too late to attach a rejection handler');
async_test(function(t) {
@ -603,8 +631,8 @@ async_test(function(t) {
onUnhandledSucceed(t, e, function() { return p; });
p = Promise.reject(e);
postMessageTask(function() {
postMessageTask(function() {
queueTask(function() {
queueTask(function() {
Promise.resolve().then(function() {
Promise.resolve().then(function() {
Promise.resolve().then(function() {
@ -616,7 +644,7 @@ async_test(function(t) {
});
});
});
}, 'delayed handling: a nested-postMessageTask after promise creation/rejection, plus many promise microtasks, is ' +
}, 'delayed handling: a nested-queueTask after promise creation/rejection, plus many promise microtasks, is ' +
'too late to attach a rejection handler');
async_test(function(t) {
@ -659,6 +687,43 @@ async_test(function(t) {
}, 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
//
@ -681,9 +746,9 @@ async_test(function(t) {
addEventListener('unhandledrejection', l);
ensureCleanup(t, l);
Promise.reject(e);
}, 'mutationObserverMicrotask vs. postMessageTask ordering is not disturbed inside unhandledrejection events');
}, 'mutationObserverMicrotask vs. queueTask ordering is not disturbed inside unhandledrejection events');
// For workers, postMessageTask() involves posting tasks to other threads, so
// For workers, queueTask() involves posting tasks to other threads, so
// the following tests don't work there.
if ('document' in self) {
@ -699,10 +764,10 @@ if ('document' in self) {
var p1 = Promise.reject();
var p2;
postMessageTask(function() {
queueTask(function() {
p2 = Promise.reject();
postMessageTask(function() {
sequenceOfEvents.push('postMessageTask');
queueTask(function() {
sequenceOfEvents.push('queueTask');
checkSequence();
});
});
@ -717,12 +782,12 @@ if ('document' in self) {
function checkSequence() {
if (sequenceOfEvents.length === 3) {
t.step(function() {
assert_array_equals(sequenceOfEvents, [p1, 'postMessageTask', p2]);
assert_array_equals(sequenceOfEvents, [p1, 'queueTask', p2]);
});
t.done();
}
}
}, 'postMessageTask ordering vs. the task queued for unhandled rejection notification (1)');
}, 'queueTask ordering vs. the task queued for unhandled rejection notification (1)');
async_test(function(t) {
var sequenceOfEvents = [];
@ -731,10 +796,10 @@ if ('document' in self) {
ensureCleanup(t, l);
var p2;
postMessageTask(function() {
queueTask(function() {
p2 = Promise.reject();
postMessageTask(function() {
sequenceOfEvents.push('postMessageTask');
queueTask(function() {
sequenceOfEvents.push('queueTask');
checkSequence();
});
});
@ -749,12 +814,12 @@ if ('document' in self) {
function checkSequence() {
if (sequenceOfEvents.length === 2) {
t.step(function() {
assert_array_equals(sequenceOfEvents, ['postMessageTask', p2]);
assert_array_equals(sequenceOfEvents, ['queueTask', p2]);
});
t.done();
}
}
}, 'postMessageTask ordering vs. the task queued for unhandled rejection notification (2)');
}, 'queueTask ordering vs. the task queued for unhandled rejection notification (2)');
async_test(function(t) {
var sequenceOfEvents = [];
@ -767,7 +832,7 @@ if ('document' in self) {
var p = Promise.reject();
setTimeout(function() {
postMessageTask(function() {
queueTask(function() {
sequenceOfEvents.push('task before catch');
checkSequence();
});
@ -777,7 +842,7 @@ if ('document' in self) {
checkSequence();
});
postMessageTask(function() {
queueTask(function() {
sequenceOfEvents.push('task after catch');
checkSequence();
});
@ -816,21 +881,18 @@ if ('document' in self) {
// HELPERS
//
var globalPostMessageCounter = 0;
function postMessageTask(f) {
// This function queues a task in "DOM manipulation task source" in window
// context, but not in workers.
function queueTask(f) {
if ('document' in self) {
var message = 'abusingpostmessageforfunandprofit' + globalPostMessageCounter;
globalPostMessageCounter++;
var l = function(ev) {
if (ev.data === message) {
removeEventListener('message', l);
f();
}
var d = document.createElement("details");
d.ontoggle = function() {
f();
};
addEventListener('message', l);
postMessage(message, '*');
d.setAttribute("open", "");
} else {
// We need to fix this to use something that can queue tasks in
// "DOM manipulation task source" to ensure the order is correct
var channel = new MessageChannel();
channel.port1.onmessage = function() { channel.port1.close(); f(); };
channel.port2.postMessage('abusingpostmessageforfunandprofit');