Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/browsers/browsing-the-web/navigating-across-documents/javascript-url-security-check-multi-globals.sub.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>Multi-globals: which one is the initiator for the javascript: URL security check?</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
"use strict";
document.domain = "{{hosts[][]}}";
// These tests would fail if a different pair of origins were compared (see, e.g., the discussion in
promise_test(async t => {
const iframe = await insertIframe(t);
const innerIframe = iframe.contentDocument.querySelector("iframe");
// javascript:'s security check uses incumbentNavigationOrigin vs. the iframe's current origin
// so the check will pass and the result will get written.
innerIframe.src = "javascript:'test'";
await waitForLoad(innerIframe, "Failed to load the javascript: URL");
assert_equals(innerIframe.contentDocument.body.textContent, "test");
}, "Using iframeEl.src");
promise_test(async t => {
const iframe = await insertIframe(t);
const innerIframe = iframe.contentDocument.querySelector("iframe");
// Here, https://html.spec.whatwg.org/#location-object-navigate sets the source browsing context to the
// incumbent settings object's browsing context. So incumbentNavigationOrigin = this page's origin,
//
// So again, the check will pass.
iframe.contentWindow.frames[0].location.href = "javascript:'test'";
await waitForLoad(innerIframe, "Failed to load the javascript: URL");
assert_equals(innerIframe.contentDocument.body.textContent, "test");
}, "Using location.href");
function insertIframe(t) {
return new Promise((resolve, reject) => {
const iframe = document.createElement("iframe");
iframe.onload = () => resolve(iframe);
iframe.onerror = () => reject(new Error("Failed to load the outer iframe"));
t.add_cleanup(() => iframe.remove());
document.body.append(iframe);
});
}
function waitForLoad(iframe, errorMessage = "Failed to load iframe") {
return new Promise((resolve, reject) => {
iframe.onload = () => resolve(iframe);
iframe.onerror = () => reject(new Error(errorMessage));
});
}
</script>