• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2
3// For now this only has per-Window tests, but we could expand it to also test per-Document
4
5/**
6 * Run tests for window[propertyName] after discarding the browsing context, navigating, etc.
7 * @param {string} propertyName
8 */
9window.testIsPerWindow = propertyName => {
10  test(t => {
11    const iframe = document.createElement("iframe");
12    document.body.appendChild(iframe);
13    const frame = iframe.contentWindow;
14
15    const before = frame[propertyName];
16    assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`);
17
18    iframe.remove();
19
20    const after = frame[propertyName];
21    assert_equals(after, before, `window.${propertyName} should not change after iframe.remove()`);
22  }, `Discarding the browsing context must not change window.${propertyName}`);
23
24  async_test(t => {
25    const iframe = document.createElement("iframe");
26    document.body.appendChild(iframe);
27    const frame = iframe.contentWindow;
28
29    const before = frame[propertyName];
30    assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`);
31
32    // Note: cannot use step_func_done for this because it might be called twice, per the below comment.
33    iframe.onload = t.step_func(() => {
34      if (frame.location.href === "about:blank") {
35        // Browsers are not reliable on whether about:blank fires the load event; see
36        // https://github.com/whatwg/html/issues/490
37        return;
38      }
39
40      const after = frame[propertyName];
41      assert_equals(after, before);
42      t.done();
43    });
44
45    iframe.src = "/common/blank.html";
46  }, `Navigating from the initial about:blank must not replace window.${propertyName}`);
47
48  // Per spec, document.open() should not change any of the Window state.
49  async_test(t => {
50    const iframe = document.createElement("iframe");
51
52    iframe.onload = t.step_func_done(() => {
53      const frame = iframe.contentWindow;
54      const before = frame[propertyName];
55      assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`);
56
57      frame.document.open();
58
59      const after = frame[propertyName];
60      assert_equals(after, before);
61
62      frame.document.close();
63    });
64
65    iframe.src = "/common/blank.html";
66    document.body.appendChild(iframe);
67  }, `document.open() must replace window.${propertyName}`);
68};
69