summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/window-open-204-pushState-replaceState.html
blob: b5382b189f6dbe783a0eb348b119e0d5b874aba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Fragment navigation on initial empty document created through window.open(url-with-204-response)</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 set to the 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 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 = "about:blank#foo";
const url2 = "resources/code-injector.html?2&pipe=sub(none)&code=" +
              encodeURIComponent(postMessageToOpenerOnLoad);

promise_test(async t => {
  // Open a new window with a URL that doesn't load a new document, so it will stay in the initial empty document.
  const openedWindow = windowOpen204(t);

  // Do a history.pushState() to about:blank#foo.
  let pushURL = "about:blank#foo";
  openedWindow.history.pushState({}, "title", pushURL);
  assert_equals(openedWindow.location.href, pushURL);
  assert_equals(history.length, 1,
    "history.length must not change after history.pushState() on the initial empty document");

  // Navigate away from the initial empty document through setting location.href.
  // This should do a replacement.
  openedWindow.location.href = url2;
  await waitForMessage(t, "loaded");
  assert_equals(openedWindow.history.length, 1,
    "history.length should not increase after normal navigation away from initial empty document");
}, "history.pushState");

promise_test(async t => {
  // Open a new window with a URL that doesn't load a new document, so it will stay in the initial empty document.
  const openedWindow = windowOpen204(t);

  // Do a history.pushState() to about:blank#foo.
  let replaceURL = "about:blank#foo";
  openedWindow.history.replaceState({}, "title", replaceURL);
  assert_equals(openedWindow.location.href, replaceURL);
  assert_equals(history.length, 1,
    "history.length must not change after history.replaceState() on the initial empty document");

  // Navigate away from the initial empty document through location.assign().
  // This should do a replacement.
  openedWindow.location.assign(url2);
  await waitForMessage(t, "loaded");
  assert_equals(openedWindow.history.length, 1,
    "history.length should not increase after normal navigation away from initial empty document");
}, "history.replaceState");
</script>