Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

  • This WPT test may be referenced by the following Test IDs:
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Navigations on window.open() to URL that doesn't load a new document</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<body></body>
<script>
/*
When a new window is opened through window.open() it will contain the initial
empty document. If the URL parameter is not set, it will stay on the initial
empty document.
These tests verify the behavior of navigations that happen on the initial
empty document in that situation. They should all be converted to do a
replacement.
*/
"use strict";
const url1 = "resources/code-injector.html?1&pipe=sub(none)&code=" + encodeURIComponent(postMessageToOpenerOnLoad);
const url2 = "resources/code-injector.html?2&pipe=sub(none)&code=" + encodeURIComponent(postMessageToOpenerOnLoad);
promise_test(async t => {
// Open a new window with no URL, which will stay in the initial empty document until the navigation below.
const openedWindow = windowOpenNoURL(t);
// Navigate away from the initial empty document through setting
// location.href. This should do a replacement.
openedWindow.location.href = url1;
await waitForMessage(t, "loaded");
assert_equals(openedWindow.history.length, 1,
"history.length should not increase after normal navigation away from initial empty document");
// Navigate again using the same method, but this time it shouldn't do a
// replacement since it's no longer on the initial empty document.
openedWindow.location.href = url2;
await waitForMessage(t, "loaded");
assert_equals(openedWindow.history.length, 2,
"history.length should increase after normal navigation away from non-initial empty document");
}, "location.href");
promise_test(async t => {
// Open a new window with no URL, which will stay in the initial empty document until the navigation below.
const openedWindow = windowOpenNoURL(t);
// Navigate away from the initial empty document through location.assign().
// This should do a replacement.
openedWindow.location.assign(url1);
await waitForMessage(t, "loaded");
assert_equals(openedWindow.history.length, 1,
"history.length should not increase after normal navigation away from initial empty document");
// Navigate again using the same method, but this time it shouldn't do a
// replacement since it's no longer on the initial empty document.
openedWindow.location.assign(url2);
await waitForMessage(t, "loaded");
assert_equals(openedWindow.history.length, 2,
"history.length should increase after normal navigation away from non-initial empty document");
}, "location.assign");
/*
promise_test(async t => {
// Open a new window with no URL, which will stay in the initial empty document until the navigation below.
const openedWindow = windowOpenNoURL(t);
// Navigate away from the initial empty document through setting
// window.open(). This should do a replacement.
openedWindow.open(url1, "_self");
await waitForMessage(t, "loaded");
assert_equals(openedWindow.history.length, 1,
"history.length should not increase after normal navigation away from initial empty document");
// Navigate again using the same method, but this time it shouldn't do a
// replacement since it's no longer on the initial empty document.
openedWindow.open(url2, "_self");
await waitForMessage(t, "loaded");
assert_equals(openedWindow.history.length, 2,
"history.length should increase after normal navigation away from non-initial empty document");
}, "window.open");
*/
</script>