Skip to content

Commit

Permalink
Test whether javascript: navigation aborts fetches in earlier navigation
Browse files Browse the repository at this point in the history
See whatwg/html#2590. Tentative tests for now.
  • Loading branch information
zcorpan committed Feb 19, 2018
1 parent abcd6e9 commit be7c5e5
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
@@ -0,0 +1,28 @@
<!doctype html>
<title>Aborting fetch for javascript:string navigation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#navigate">
<link rel="help" href="https://github.com/whatwg/html/issues/2590">
<div id="log"></div>
<iframe src="support/iframe-and-links.html"></iframe>
<script>
async_test(test => {
onload = () => {
const child = document.querySelector('iframe').contentWindow;
child.document.querySelector("#slowLink").click();
// The step below is in a timeout. The framed page can't communicate back mid-parse because that
// would involve running script, which makes that navigation "mature", and we need to do this
// before it matures.
test.step_timeout(() => {

This comment has been minimized.

Copy link
@bzbarsky

bzbarsky Feb 21, 2018

Contributor

What guarantees that this timeout will fire before the navigation matures? The 1s timer on the trickle is in a different process (the server). Depending on OS scheduling, it can in fact end up replying before this time fires.

child.document.querySelector("#javascriptStringLink").click();
child.document.querySelector("iframe").onload = test.step_func_done(() => {
assert_false(child.childLoaded, 'child.childLoaded');
});
}, 100);
};
window.javascriptStringDocLoaded = test.step_func(() => {
assert_unreached("javascript: URL doc replaced the document, should be targeted to child iframe.");
});
});
</script>
@@ -0,0 +1,25 @@
<!doctype html>
<title>Not aborting fetch for javascript:undefined navigation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#navigate">
<link rel="help" href="https://github.com/whatwg/html/issues/2590">
<div id="log"></div>
<iframe src="support/iframe-and-links.html"></iframe>
<script>
async_test(test => {
onload = () => {
const child = document.querySelector('iframe').contentWindow;
child.document.querySelector("#slowLink").click();
// The step below is in a timeout. The framed page can't communicate back mid-parse because that
// would involve running script, which makes that navigation "mature", and we need to do this
// before it matures.
test.step_timeout(() => {
child.document.querySelector("#javascriptUndefinedLink").click();
child.document.querySelector("iframe").onload = test.step_func_done(() => {
assert_true(child.childLoaded, 'child.childLoaded');
});
}, 100);
};
});
</script>
@@ -0,0 +1,18 @@
<!doctype html>

<iframe name="iframe"></iframe>

<!-- slow link's response is delayed by 1 second -->
<!-- https://wptserve.readthedocs.io/en/latest/pipes.html#trickle -->
<a target="iframe" href="set-child-loaded.html?pipe=trickle(d1)" id="slowLink">slow link</a>
<a target="iframe" href="javascript:'javascript:string <script> parent.javascriptStringDocLoaded(); </script>'" id="javascriptStringLink">javascript:string link</a>
<a target="iframe" href="javascript:undefined" id="javascriptUndefinedLink">javascript:undefined link</a>

<script>
// set-child-loaded.html (the slow link) sets this to true.
window.childLoaded = false;

// Do nothing when the javascript:string doc has loaded, if it's correctly targeted to the above iframe.
// However, if it replaces this document, it needs to fail the test (handled in the parent).
function javascriptStringDocLoaded() {}
</script>
@@ -0,0 +1,5 @@
<!doctype html>
set-child-loaded.html
<script>
parent.childLoaded = true;
</script>

0 comments on commit be7c5e5

Please sign in to comment.