summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/srcdoc/consecutive-srcdoc.html
blob: 9aab36b9862742324720200acc3c015e9e52e3e4 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<meta charset="utf-8">
<title>changing srcdoc to a different srcdoc</title>
<link rel="help" href="https://github.com/whatwg/html/issues/6809#issuecomment-905677979">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/helpers.js"></script>

<script>
"use strict";

// Note: bfcache won't mess with any windows with openers, so it doesn't
// interfere with these tests.

promise_test(async t => {
  // Set up a window whose iframe contains [normal page, srcdoc] entries.
  const w = await openWindow("../../resources/has-iframe.html", t);
  const iframe = w.document.querySelector("iframe");

  await waitToAvoidReplace(t);
  iframe.srcdoc = srcdocThatPostsParentOpener("srcdoc1");
  await waitForMessage(iframe.contentWindow);

  assert_equals(w.history.length, 2);

  // Now navigate to a different srcdoc
  iframe.srcdoc = srcdocThatPostsParentOpener("srcdoc2");

  // Test that it's a replace.
  await waitForMessage(iframe.contentWindow);
  assert_equals(w.history.length, 2,
    "history.length must not change since it was a replace");
  assert_equals(
    iframe.contentDocument.querySelector("p").textContent,
    "srcdoc2",
    "Sanity check: the srcdoc document did indeed update"
  );
}, "changing srcdoc does a replace navigation since the URL is still " +
   "about:srcdoc");

promise_test(async t => {
  // Set up a window whose iframe contains [normal page, srcdoc] entries.
  const w = await openWindow("../../resources/has-iframe.html", t);
  const iframe = w.document.querySelector("iframe");

  await waitToAvoidReplace(t);
  iframe.srcdoc = srcdocThatPostsParentOpener("srcdoc1");
  await waitForMessage(iframe.contentWindow);

  assert_equals(w.history.length, 2);

  // Now navigate to about:srcdoc#yo
  iframe.contentWindow.location.href = "about:srcdoc#yo";
  assert_equals(iframe.contentWindow.location.href, "about:srcdoc#yo");
  assert_equals(w.history.length, 3);

  // Now navigate to a different srcdoc
  iframe.srcdoc = srcdocThatPostsParentOpener("srcdoc2");

  // Test that it's a push back to about:srcdoc.
  await waitForMessage(iframe.contentWindow);
  assert_equals(
    w.history.length,
    4,
    "history.length must increase since it was a push"
  );
  assert_equals(iframe.contentWindow.location.href, "about:srcdoc");
  assert_equals(
    iframe.contentDocument.querySelector("p").textContent,
    "srcdoc2",
    "Sanity check: the srcdoc document did indeed update"
  );

  // Test that we can go back to about:srcdoc#yo.
  w.history.back();
  await waitForMessage(iframe.contentWindow);
  assert_equals(iframe.contentWindow.location.href, "about:srcdoc#yo");
  assert_equals(
    iframe.contentDocument.querySelector("p").textContent,
    "srcdoc1",
    "srcdoc content must be restored from history"
  );
}, "changing srcdoc to about:srcdoc#yo then another srcdoc does two push " +
   "navigations and we can navigate back");
</script>