Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-src-204-pushState-replaceState.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="UTF-8">
<title>pushState/replaceState on iframe with src set to URL that doesn't load a document (HTTP 204)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<body></body>
<script>
/*
When an iframe is created it will contain the initial empty document. If the
src is set to a URL that doesn't load a new document (e.g. it results in a
HTTP 204 response), it will stay on the initial empty document. If
history.pushState() or history.replaceState() is called on it, it should
still stay on the initial empty document.
These tests verifies 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 crossDocumentURL = "/common/blank.html?2";
promise_test(async t => {
const startingHistoryLength = history.length;
// Create an iframe with src set to URL that doesn't load a new document, so
// it will stay on the initial empty document.
const iframe = insertIframeWith204Src(t);
assert_equals(history.length, startingHistoryLength,
"Inserting iframe with src set to URL that doesn't load a new document must not change history.length");
// Do a history.pushState() to about:blank#foo.
let pushURL = "about:blank#foo";
iframe.contentWindow.history.pushState({}, "title", pushURL);
assert_equals(iframe.contentWindow.location.href, pushURL);
assert_equals(history.length, startingHistoryLength,
"history.length must not change after history.pushState() on the initial empty document");
// Navigate away from the initial empty document. This should do replacement.
iframe.src = crossDocumentURL;
await waitForLoad(t, iframe, crossDocumentURL);
assert_equals(history.length, startingHistoryLength,
"history.length must not change after normal navigation from initial empty document");
}, "history.pushState");
promise_test(async t => {
const startingHistoryLength = history.length;
// Create an iframe with src set to URL that doesn't load a new document, so
// it will stay on the initial empty document.
const iframe = insertIframeWith204Src(t);
assert_equals(history.length, startingHistoryLength,
"Inserting iframe with src set to URL that doesn't load a new document must not change history.length");
// Do a history.replaceState() to about:blank#foo.
let replaceURL = "about:blank#foo";
iframe.contentWindow.history.replaceState({}, "title", replaceURL);
assert_equals(iframe.contentWindow.location.href, replaceURL);
assert_equals(history.length, startingHistoryLength,
"history.length must not change after history.replaceState() on the initial empty document");
// Navigate away from the initial empty document. This should do replacement.
iframe.src = crossDocumentURL;
await waitForLoad(t, iframe, crossDocumentURL);
assert_equals(history.length, startingHistoryLength,
"history.length must not change after normal navigation from initial empty document");
}, "history.replaceState");
</script>