Skip to content

Commit

Permalink
Add tests for javascript: URL task queuing
Browse files Browse the repository at this point in the history
See whatwg/html#3730. Follows the spec in whatwg/html#6315.
  • Loading branch information
domenic committed Oct 10, 2022
1 parent 5e9bb79 commit b2c4983
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>javascript: URL task queuing</title>
<link rel="help" href="https://github.com/whatwg/html/issues/3730">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
"use strict";

testIsAsync(() => {
const iframe = document.createElement("iframe");
document.body.append(iframe);
iframe.contentWindow.location.href = "javascript:window.top.javascriptURLRan = true; window.top.resolveTestPromise();";
}, `Navigating an iframe via location.href to a javascript: URL must queue a task`);

testIsAsync(() => {
const iframe = document.createElement("iframe");
iframe.src = "javascript:window.top.javascriptURLRan = true; window.top.resolveTestPromise();";
document.body.append(iframe);
}, `Navigating an iframe via src="" to a javascript: URL before insertion must queue a task`);

testIsAsync(() => {
const iframe = document.createElement("iframe");
document.body.append(iframe);
iframe.src = "javascript:window.top.javascriptURLRan = true; window.top.resolveTestPromise();";
}, `Navigating an iframe via src="" to a javascript: URL after insertion must queue a task`);

testIsAsync(() => {
const w = window.open();
w.location.href = "javascript:window.opener.javascriptURLRan = true; window.opener.resolveTestPromise();";
}, `Navigating an opened window via location.href to a javascript: URL must queue a task`);

testIsAsync(() => {
window.open("javascript:window.opener.javascriptURLRan = true; window.opener.resolveTestPromise();");
}, `Navigating an opened window as part of creation to a javascript: URL must queue a task`);

function testIsAsync(setupFunc, description) {
promise_test(async t => {
t.add_cleanup(() => {
delete window.resolveTestPromise;
delete window.javascriptURLRan;
});

const ranInsidePromise = new Promise(resolve => {
window.resolveTestPromise = resolve;
});

setupFunc();

assert_equals(window.javascriptURLRan, undefined, "Must not run sync");

// Ensure that we do actually run the code, though.
await ranInsidePromise;
}, description);
}
</script>

0 comments on commit b2c4983

Please sign in to comment.