Bug 1769670 [wpt PR 34087] - [WPT] Add incumbent/entry/relevant realm tests for Location/window.open, a=testonly
authorHiroshige Hayashizaki <hiroshige@chromium.org>
Mon, 23 May 2022 10:02:01 +0000
changeset 618668 c9df738ba2ca2b889ab817fadbce705f327e7618
parent 618667 54d341c7421ede8531d1505e96feb02b40bad92a
child 618669 b4fe76b2198ba7995c4033eb8208feb2b0d4591d
push id163376
push userwptsync@mozilla.com
push dateTue, 24 May 2022 10:19:51 +0000
treeherderautoland@2ef7c238533c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1769670, 34087, 3646085, 1005006
milestone102.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1769670 [wpt PR 34087] - [WPT] Add incumbent/entry/relevant realm tests for Location/window.open, a=testonly Automatic update from web-platform-tests [WPT] Add incumbent/entry/relevant realm tests for Location/window.open Based on Chromium layout tests. Current test failures: The settings object used for `document.referrer` (=navigation request's client) are: - The incumbent settings for `window.open()` on Chrome. - The `Location`'s relevant for `location.assign()` on Safari. Change-Id: I6b50f886985fb21b4e8a1f7138744e1cce205534 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3646085 Reviewed-by: Domenic Denicola <domenic@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#1005006} -- wpt-commits: 6f1407f973fcf34491742489ef9ff29791b0ccad wpt-pr: 34087
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location-assign.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location-href.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-location.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/context-for-window-open.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/entry/entry.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/entry/target.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/incumbent/empty.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/incumbent/target.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/relevant/empty.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/relevant/target.html
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/resources/context-helper.js
testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/multiple-globals/resources/target.js
new file mode 100644
--- /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>
new file mode 100644
--- /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>
new file mode 100644
--- /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>
new file mode 100644
--- /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>
new file mode 100644
--- /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>
new file mode 100644
--- /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>
new file mode 100644
new file mode 100644
--- /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>
new file mode 100644
new file mode 100644
--- /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>
new file mode 100644
--- /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();
+}
new file mode 100644
--- /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},
+        "*");
+}