Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various active document tests #22031

Merged
merged 3 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions payment-request/rejects_if_not_active-manual.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
iframe,
"/payment-request/resources/page1.html"
);
// Save the DOMException of page1.html before navigating away.
const frameDOMException1 = iframe.contentWindow.DOMException;
// We navigate the iframe again, putting request1's document into an inactive state.
const request2 = await getLoadedPaymentRequest(
iframe,
Expand All @@ -71,6 +73,7 @@
await promise_rejects_dom(
t,
"AbortError",
frameDOMException1,
request1.show(),
"Inactive document, so must throw AbortError"
);
Expand All @@ -80,6 +83,7 @@
await promise_rejects_dom(
t,
"InvalidStateError",
iframe.contentWindow.DOMException,
request2.show(),
"Abort already called, so InvalidStateError"
);
Expand Down Expand Up @@ -112,6 +116,8 @@
innerIframe,
"/payment-request/resources/page2.html"
);
// Save DOMException from innerIframe before navigating away.
const innerIframeDOMException = innerIframe.contentWindow.DOMException;

// Navigate the outer iframe to a new location.
// Wait for the load event to fire.
Expand All @@ -128,6 +134,7 @@
await promise_rejects_dom(
t,
"AbortError",
innerIframeDOMException,
showPromise,
"Active, but not fully active, so must throw AbortError"
);
Expand Down
54 changes: 42 additions & 12 deletions resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,37 @@ policies and contribution forms [3].
});
}

/**
* Make a copy of a Promise in the current realm.
*
* @param {Promise} promise the given promise that may be from a different
* realm
* @returns {Promise}
*
* An arbitrary promise provided by the caller may have originated in
* another frame that have since navigated away, rendering the frame's
* document inactive. Such a promise cannot be used with `await` or
* Promise.resolve(), as microtasks associated with it may be prevented
* from being run. See https://github.com/whatwg/html/issues/5319 for a
* particular case.
*
* In functions we define here, there is an expectation from the caller
* that the promise is from the current realm, that can always be used with
* `await`, etc. We therefore create a new promise in this realm that
* inherit the value and status from the given promise.
*/

function bring_promise_to_current_realm(promise) {
return new Promise(promise.then.bind(promise));
TimothyGu marked this conversation as resolved.
Show resolved Hide resolved
}

function promise_rejects_js(test, constructor, promise, description) {
return promise.then(test.unreached_func("Should have rejected: " + description)).catch(function(e) {
assert_throws_js_impl(constructor, function() { throw e },
description, "promise_rejects_js");
});
return bring_promise_to_current_realm(promise)
.then(test.unreached_func("Should have rejected: " + description))
.catch(function(e) {
assert_throws_js_impl(constructor, function() { throw e },
description, "promise_rejects_js");
});
}

/**
Expand Down Expand Up @@ -678,17 +704,21 @@ policies and contribution forms [3].
assert(maybeDescription === undefined,
"Too many args pased to no-constructor version of promise_rejects_dom");
}
return promise.then(test.unreached_func("Should have rejected: " + description)).catch(function(e) {
assert_throws_dom_impl(type, function() { throw e }, description,
"promise_rejects_dom", constructor);
});
return bring_promise_to_current_realm(promise)
.then(test.unreached_func("Should have rejected: " + description))
.catch(function(e) {
assert_throws_dom_impl(type, function() { throw e }, description,
"promise_rejects_dom", constructor);
});
}

function promise_rejects_exactly(test, exception, promise, description) {
return promise.then(test.unreached_func("Should have rejected: " + description)).catch(function(e) {
assert_throws_exactly_impl(exception, function() { throw e },
description, "promise_rejects_exactly");
});
return bring_promise_to_current_realm(promise)
.then(test.unreached_func("Should have rejected: " + description))
.catch(function(e) {
assert_throws_exactly_impl(exception, function() { throw e },
description, "promise_rejects_exactly");
});
}

/**
Expand Down
6 changes: 6 additions & 0 deletions wake-lock/wakelock-active-document.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ promise_test(async t => {
iframe,
"/wake-lock/resources/page1.html"
);
// Save the DOMException of page1.html before navigating away.
const frameDOMException1 = iframe.contentWindow.DOMException;
// We navigate the iframe again, putting wakeLock1's document into an inactive state.
const wakeLock2 = await getWakeLockObject(
iframe,
Expand All @@ -30,6 +32,7 @@ promise_test(async t => {
await promise_rejects_dom(
t,
"NotAllowedError",
frameDOMException1,
wakeLock1.request('screen'),
"Inactive document, so must throw NotAllowedError"
);
Expand Down Expand Up @@ -58,6 +61,8 @@ promise_test(async t => {
innerIframe,
"/wake-lock/resources/page2.html"
);
// Save DOMException from innerIframe before navigating away.
const innerIframeDOMException = innerIframe.contentWindow.DOMException;

// Navigate the outer iframe to a new location.
// Wait for the load event to fire.
Expand All @@ -73,6 +78,7 @@ promise_test(async t => {
await promise_rejects_dom(
t,
"NotAllowedError",
innerIframeDOMException,
wakeLock.request('screen'),
"Active, but not fully active, so must throw NotAllowedError"
);
Expand Down