Skip to content

Commit

Permalink
Test entry settings object for promise jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Jan 15, 2020
1 parent 3265ac2 commit acd6aad
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Entry settings object for promise jobs</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- https://github.com/whatwg/html/pull/5212 -->
<!-- https://github.com/whatwg/html/issues/1426 -->

<!-- This is the entry page, so window.open() should resolve relative to it, even inside promise jobs. -->

<iframe src="resources/promise-job-entry-incumbent.html"></iframe>

<script>
setup({ explicit_done: true });

const relativeURL = "resources/window-to-open.html";
const expectedURL = (new URL(relativeURL, location.href)).href;

window.onload = () => {
async_test(t => {
const w = frames[0].runWindowOpenVeryIndirectly(relativeURL);
w.onload = t.step_func_done(() => {
t.add_cleanup(() => w.close());
assert_equals(w.location.href, expectedURL);
});
}, "Sanity check: this all works as expected with no promises involved");

async_test(t => {
Promise.resolve().then(t.step_func(() => {
const w = frames[0].runWindowOpenVeryIndirectly(relativeURL);
w.onload = t.step_func_done(() => {
t.add_cleanup(() => w.close());
assert_equals(w.location.href, expectedURL);
});
}));
}, "Fulfillment handler on fulfilled promise");

async_test(t => {
Promise.reject().catch(t.step_func(() => {
const w = frames[0].runWindowOpenVeryIndirectly(relativeURL);
w.onload = t.step_func_done(() => {
t.add_cleanup(() => w.close());
assert_equals(w.location.href, expectedURL);
});
}));
}, "Rejection handler on rejected promise");

async_test(t => {
let resolve;
const p = new Promise(r => { resolve = r; });

p.then(t.step_func(() => {
const w = frames[0].runWindowOpenVeryIndirectly(relativeURL);
w.onload = t.step_func_done(() => {
t.add_cleanup(() => w.close());
assert_equals(w.location.href, expectedURL);
});
}));

t.step_timeout(resolve, 0);
}, "Fulfillment handler on pending-then-fulfilled promise");

async_test(t => {
let reject;
const p = new Promise((_, r) => { reject = r; });

p.catch(t.step_func(() => {
const w = frames[0].runWindowOpenVeryIndirectly(relativeURL);
w.onload = t.step_func_done(() => {
t.add_cleanup(() => w.close());
assert_equals(w.location.href, expectedURL);
});
}));

t.step_timeout(reject, 0);
}, "Rejection handler on pending-then-rejected promise");

async_test(t => {
const thenable = {
then: t.step_func((f) => {
const w = frames[0].runWindowOpenVeryIndirectly(relativeURL);
w.onload = t.step_func_done(() => {
t.add_cleanup(() => w.close());
assert_equals(w.location.href, expectedURL);
});
})
};

Promise.resolve(thenable);
}, "Thenable resolution");

done();
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A couple notes about the files scattered in this `resources/` directory:

* The nested directory structure is necessary here so that relative URL resolution can be tested; we need different sub-paths for each document.

* The semi-duplicate `window-to-open.html`s scattered throughout are present because Firefox, at least, does not fire `Window` `load` events for 404s, so we want to ensure that no matter which global is used, `window`'s `load` event is hit and our tests can proceed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<title>Current page used as a test helper</title>

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<title>If the current settings object is used this page will be opened</title>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<title>Incumbent page used as a test helper</title>

<iframe src="relevant/relevant.html" id="r"></iframe>
<iframe src="current/current.html" id="c"></iframe>

<script>
const relevant = document.querySelector("#r");
const current = document.querySelector("#c");

window.runWindowOpenVeryIndirectly = (...args) => {
return current.contentWindow.open.call(relevant.contentWindow, ...args);
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<title>Relevant page used as a test helper</title>

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<title>If the relevant settings object is used this page will be opened</title>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<title>If the incumbent settings object is used this page will be opened</title>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<title>If the entry settings object is used this page will be opened</title>

0 comments on commit acd6aad

Please sign in to comment.