-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for javascript: URL task queuing
See whatwg/html#3730. Follows the spec in whatwg/html#6315.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
html/browsers/browsing-the-web/navigating-across-documents/javascript-url-task-queuing.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |