diff options
Diffstat (limited to 'testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals')
12 files changed, 164 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location-assign.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location-assign.html new file mode 100644 index 0000000000..cb2984d409 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location-assign.html @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/context-helper.js"></script> +<script> +window.scriptToRun = 'relevantWindow.location.assign("target.html");'; + +async_test(t => { + window.addEventListener("message", t.step_func_done(function(e) { + // Base URL used for parsing a relative URL to `target.html` + // should be the base URL of the entry settings object in + // https://html.spec.whatwg.org/C/#dom-location-assign + assert_equals( + e.data.location, + new URL('target.html', entryUrl).href, + 'Base URL should use the entry settings object'); + + // `document.referrer` should reflect the source browsing context, + // which is the incumbent in + // https://html.spec.whatwg.org/C/#location-object-navigate + assert_equals( + e.data.referrer, incumbentUrl, + 'Referrer should use the incumbent settings object'); + })); +}, 'Fetch client and URL resolution for location.assign()'); +</script> +<iframe id="entry" src="entry/entry.html"></iframe> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location-href.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location-href.html new file mode 100644 index 0000000000..02ff214ed5 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location-href.html @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/context-helper.js"></script> +<script> +window.scriptToRun = 'relevantWindow.location.href = "target.html";'; + +async_test(t => { + window.addEventListener("message", t.step_func_done(function(e) { + // Base URL used for parsing a relative URL to `target.html` + // should be the base URL of the entry settings object in + // https://html.spec.whatwg.org/C/#dom-location-href + assert_equals( + e.data.location, + new URL('target.html', entryUrl).href, + 'Base URL should use the entry settings object'); + + // `document.referrer` should reflect the source browsing context, + // which is the incumbent in + // https://html.spec.whatwg.org/C/#location-object-navigate + assert_equals( + e.data.referrer, incumbentUrl, + 'Referrer should use the incumbent settings object'); + })); +}, 'Fetch client and URL resolution for location.href setter'); +</script> +<iframe id="entry" src="entry/entry.html"></iframe> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location.html new file mode 100644 index 0000000000..fae17dd2ac --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location.html @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/context-helper.js"></script> +<script> +window.scriptToRun = 'relevantWindow.location = "target.html";'; + +async_test(t => { + window.addEventListener("message", t.step_func_done(function(e) { + // Base URL used for parsing a relative URL to `target.html` + // should be the base URL of the entry settings object in + // https://html.spec.whatwg.org/C/#dom-location-assign + assert_equals( + e.data.location, + new URL('target.html', entryUrl).href, + 'Base URL should use the entry settings object'); + + // `document.referrer` should reflect the source browsing context, + // which is the incumbent in + // https://html.spec.whatwg.org/C/#location-object-navigate + assert_equals( + e.data.referrer, incumbentUrl, + 'Referrer should use the incumbent settings object'); + })); +}, 'Fetch client and URL resolution for location setter'); +</script> +<iframe id="entry" src="entry/entry.html"></iframe> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-window-open.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-window-open.html new file mode 100644 index 0000000000..0a391ef28e --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-window-open.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/context-helper.js"></script> +<script> +window.scriptToRun = + 'relevantWindow.open("target.html", "target");'; + +async_test(t => { + window.addEventListener("message", t.step_func_done(function(e) { + // Base URL used for parsing a relative URL to `target.html` + // should be the base URL of the entry settings object in + // https://html.spec.whatwg.org/C/#window-open-steps + assert_equals( + e.data.location, + new URL('target.html', entryUrl).href, + 'Base URL should use the entry settings object'); + + // `document.referrer` should reflect the source browsing context, + // which is the entry in + // https://html.spec.whatwg.org/C/#window-open-steps + assert_equals( + e.data.referrer, entryUrl, + 'Referrer should use the entry settings object'); + })); +}, 'Fetch client and URL resolution for window.open()'); +</script> +<iframe id="entry" src="entry/entry.html"></iframe> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/entry/entry.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/entry/entry.html new file mode 100644 index 0000000000..82fecfdd38 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/entry/entry.html @@ -0,0 +1,4 @@ +<body onload="top.go()"> +<iframe id="incumbent" src="../incumbent/empty.html"></iframe> +<iframe id="relevant" src="../relevant/empty.html"></iframe> +</body> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/entry/target.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/entry/target.html new file mode 100644 index 0000000000..5ceaeaf07e --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/entry/target.html @@ -0,0 +1,2 @@ +<!DOCTYPE html> +<script src="../resources/target.js"></script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/incumbent/empty.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/incumbent/empty.html new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/incumbent/empty.html diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/incumbent/target.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/incumbent/target.html new file mode 100644 index 0000000000..5ceaeaf07e --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/incumbent/target.html @@ -0,0 +1,2 @@ +<!DOCTYPE html> +<script src="../resources/target.js"></script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/relevant/empty.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/relevant/empty.html new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/relevant/empty.html diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/relevant/target.html b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/relevant/target.html new file mode 100644 index 0000000000..5ceaeaf07e --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/relevant/target.html @@ -0,0 +1,2 @@ +<!DOCTYPE html> +<script src="../resources/target.js"></script> diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/resources/context-helper.js b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/resources/context-helper.js new file mode 100644 index 0000000000..dda338b4cc --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/resources/context-helper.js @@ -0,0 +1,34 @@ +// Usage: in the top-level Window, include: +// +// <script src="resources/context-helper.js"></script> +// <script> +// window.scriptToRun = '...'; +// </script> +// <iframe id="entry" src="entry/entry.html"></iframe> +// +// Then `scriptToRun` is evaluated, with: +// - The entry Realm is that of entry/entry.html +// - The incumbent Realm is that of incumbent/empty.html +// - The relevant Realm of `relevantWindow`, `relevantWindow.location` etc. is +// that of relevant/empty.html + +window.scriptToRun = ''; + +const entryUrl = new URL('entry/entry.html', location).href; +const incumbentUrl = new URL('incumbent/empty.html', location).href; +const relevantUrl = new URL('relevant/empty.html', location).href; + +function go() { + const entry = document.querySelector('#entry'); + const incumbent = entry.contentDocument.querySelector('#incumbent'); + const incumbentScript = incumbent.contentDocument.createElement('script'); + incumbentScript.textContent = ` + function go() { + const relevantWindow = + parent.document.querySelector('#relevant').contentWindow; + ${window.scriptToRun} + } + `; + incumbent.contentDocument.head.appendChild(incumbentScript); + incumbent.contentWindow.go(); +} diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/resources/target.js b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/resources/target.js new file mode 100644 index 0000000000..e3a507b0d8 --- /dev/null +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/resources/target.js @@ -0,0 +1,11 @@ +window.onload = function() { + let testWindow; + if (opener) { + testWindow = opener.top; + } else { + testWindow = top; + } + testWindow.postMessage( + {location: location.href, referrer: document.referrer}, + "*"); +} |