summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/the-window-object/window-reuse-in-nested-browsing-contexts.tentative.html
blob: 03c7a68dfd3f113ad3ef3e1902bc76e188938232 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
const setupIframe = (t, attrs) => {
  const iframe = document.createElement('iframe');
  for (const [key, value] of Object.entries(attrs))
    iframe[key] = value;
  const watcher = new EventWatcher(t, iframe, ['load']);
  document.body.appendChild(iframe);
  return {iframe, watcher};
};

promise_test(async t => {
  const {iframe, watcher} = setupIframe(t, {});

  // Per https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes,
  // the task to perform the "iframe load event steps" should still be queued.
  // If a browser already fired a load event, the test will fail here since
  // EventWatcher will have received an unexpected load event.

  iframe.contentWindow.persistedString = 'Hello world!';
  iframe.src = 'support/same-origin-iframe.html';
  await watcher.wait_for(['load']);

  assert_true(iframe.contentWindow.didLoadFrame);
  // The <iframe>'s session history has only one Document, and that Document is
  // the initial about:blank Document. The Window object should be reused per
  // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes.
  assert_equals(iframe.contentWindow.persistedString, 'Hello world!');
}, 'synchronously navigate iframe with no initial src.');

promise_test(async t => {
  const {iframe, watcher} = setupIframe(t, {});

  // Per https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes,
  // the task to perform the "iframe load event steps" should still be queued.
  await watcher.wait_for(['load']);

  iframe.contentWindow.persistedString = 'Hello world!';
  iframe.src = 'support/same-origin-iframe.html';
  await watcher.wait_for(['load']);

  assert_true(iframe.contentWindow.didLoadFrame);
  // The <iframe>'s session history has only one Document, and that Document is
  // the initial about:blank Document. The Window object should be reused per
  // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes.
  assert_equals(iframe.contentWindow.persistedString, 'Hello world!');
}, 'after the first iframe load event, navigate iframe with no initial src.');

// Per https://whatwg.org/c/iframe-embed-object.html#otherwise-steps-for-iframe-or-frame-elements,
// setting the <iframe> src to an empty string before inserting the <iframe>
// into the document should begin an attempt to navigate to a resource with
// url == "about:blank".
promise_test(async t => {
  const {iframe, watcher} = setupIframe(t, {src: ''});

  // Per https://whatwg.org/c/browsing-the-web.html#navigate, the "about:blank"
  // resource should be obtained "in parallel". If a browser performs this step
  // synchronously, the test will fail here since EventWatcher will have
  // received an unexpected load event.

  iframe.contentWindow.persistedString = 'Hello world!';
  // An attempt to navigate to "about:blank" already exists but should not have
  // matured yet since the resource should be obtained "in parallel". The new
  // navigation attempt will cancel the preexisting attempt.
  iframe.src = 'support/same-origin-iframe.html';
  await watcher.wait_for(['load']);

  assert_true(iframe.contentWindow.didLoadFrame);
  // The navigation attempt to "about:blank" was cancelled, so the <iframe>'s
  // session history has only one Document, and that Document is the
  // initial about:blank Document. The Window object should be reused per
  // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes.
  assert_equals(iframe.contentWindow.persistedString, 'Hello world!');
}, 'synchronously navigate iframe with initial src == "".');

promise_test(async t => {
  const {iframe, watcher} = setupIframe(t, {src: ''});

  // Per https://whatwg.org/c/browsing-the-web.html#navigate, the "about:blank"
  // resource should be obtained "in parallel".
  await watcher.wait_for(['load']);

  iframe.contentWindow.persistedString = 'Hello world!';
  iframe.src = 'support/same-origin-iframe.html';
  await watcher.wait_for(['load']);

  assert_true(iframe.contentWindow.didLoadFrame);
  // A non-initial navigation to about:blank was committed, so the <iframe>
  // element is no longer displaying the initial about:blank Document. Per
  // https://whatwg.org/c/browsing-the-web.html#initialise-the-document-object,
  // the Window object must not be reused.
  assert_equals(iframe.contentWindow.persistedString, undefined);
}, 'after the first iframe load event, navigate iframe with initial src == "".');

promise_test(async t => {
  const {iframe, watcher} = setupIframe(t, {src: 'about:blank'});

  // Per https://whatwg.org/c/browsing-the-web.html#navigate, the "about:blank"
  // resource should be obtained "in parallel". If a browser performs this step
  // synchronously, the test will fail here since EventWatcher will have
  // received an unexpected load event.

  iframe.contentWindow.persistedString = 'Hello world!';
  // An attempt to navigate to "about:blank" already exists but should not have
  // matured yet since the resource should be obtained "in parallel". The new
  // navigation attempt will cancel the preexisting attempt.
  iframe.src = 'support/same-origin-iframe.html';
  await watcher.wait_for(['load']);

  assert_true(iframe.contentWindow.didLoadFrame);
  // The navigation attempt to "about:blank" was cancelled, so the <iframe>'s
  // session history has only one Document, and that Document is the
  // initial about:blank Document. The Window object should be reused per
  // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes.
  assert_equals(iframe.contentWindow.persistedString, 'Hello world!');
}, 'synchronously navigate iframe with initial src == "about:blank".');

promise_test(async t => {
  const {iframe, watcher} = setupIframe(t, {src: 'about:blank'});

  // Per https://whatwg.org/c/browsing-the-web.html#navigate, the "about:blank"
  // resource should be obtained "in parallel".
  await watcher.wait_for(['load']);

  iframe.contentWindow.persistedString = 'Hello world!';
  iframe.src = 'support/same-origin-iframe.html';
  await watcher.wait_for(['load']);

  assert_true(iframe.contentWindow.didLoadFrame);
  // A non-initial navigation to about:blank was committed, so the <iframe>
  // element is no longer displaying the initial about:blank Document. Per
  // https://whatwg.org/c/browsing-the-web.html#initialise-the-document-object,
  // the Window object must not be reused.
  assert_equals(iframe.contentWindow.persistedString, undefined);
}, 'after the first iframe load event, navigate iframe with initial src == "about:blank".');

// Per https://whatwg.org/c/iframe-embed-object.html#otherwise-steps-for-iframe-or-frame-elements,
// setting <iframe> src before inserting the <iframe> into the document should
// begin an attempt to navigate to the value of the src attribute.
promise_test(async t => {
  const {iframe, watcher} = setupIframe(t, {src: 'support/same-origin-iframe.html'});

  iframe.contentWindow.persistedString = 'Hello world!';
  // Completion of the attempt to navigate happens "in parallel".
  await watcher.wait_for(['load']);

  assert_true(iframe.contentWindow.didLoadFrame);
  // The <iframe>'s session history has only one Document, and that Document is
  // the initial about:blank Document. The Window object should be reused per
  // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes.
  assert_equals(iframe.contentWindow.persistedString, 'Hello world!');
}, 'iframe with initial src == same-origin resource.');
</script>