aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/common/object-association.js
blob: d58f94b62d652ad2879eb83821ba278b56006f7b (plain) (blame)
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
"use strict";

// For now this only has per-Window tests, but we could expand it to also test per-Document

window.testIsPerWindow = propertyName => {
  test(t => {
    const iframe = document.createElement("iframe");
    document.body.appendChild(iframe);
    const frame = iframe.contentWindow;

    const before = frame[propertyName];
    assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`);

    iframe.remove();

    const after = frame[propertyName];
    assert_equals(after, before, `window.${propertyName} should not change after iframe.remove()`);
  }, `Discarding the browsing context must not change window.${propertyName}`);

  async_test(t => {
    const iframe = document.createElement("iframe");
    document.body.appendChild(iframe);
    const frame = iframe.contentWindow;

    const before = frame[propertyName];
    assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`);

    // Note: cannot use step_func_done for this because it might be called twice, per the below comment.
    iframe.onload = t.step_func(() => {
      if (frame.location.href === "about:blank") {
        // Browsers are not reliable on whether about:blank fires the load event; see
        // https://github.com/whatwg/html/issues/490
        return;
      }

      const after = frame[propertyName];
      assert_equals(after, before);
      t.done();
    });

    iframe.src = "/common/blank.html";
  }, `Navigating from the initial about:blank must not replace window.${propertyName}`);

  // Per spec, document.open() should not change any of the Window state.
  async_test(t => {
    const iframe = document.createElement("iframe");

    iframe.onload = t.step_func_done(() => {
      const frame = iframe.contentWindow;
      const before = frame[propertyName];
      assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`);

      frame.document.open();

      const after = frame[propertyName];
      assert_equals(after, before);

      frame.document.close();
    });

    iframe.src = "/common/blank.html";
    document.body.appendChild(iframe);
  }, `document.open() must replace window.${propertyName}`);
};