File: remove-initial-about-blankness.window.js

package info (click to toggle)
firefox-esr 91.12.0esr-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,375,668 kB
  • sloc: cpp: 5,762,032; javascript: 5,481,714; ansic: 3,121,206; python: 851,492; asm: 331,174; xml: 178,949; java: 155,554; sh: 63,704; makefile: 20,127; perl: 12,825; yacc: 4,583; cs: 3,846; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; php: 436; lisp: 260; awk: 231; ruby: 103; sed: 53; sql: 46; csh: 45
file content (65 lines) | stat: -rw-r--r-- 2,713 bytes parent folder | download | duplicates (19)
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
// This tests the issues discussed in https://github.com/whatwg/html/issues/4299
// and fixed in https://github.com/whatwg/html/pull/6567.

// Note: because browsers do not interoperate on the spec's notion of window reuse (see e.g. https://crbug.com/778318)
// we pick a specific interoperable test case, which is "currently on initial about:blank, but loading something".

async_test(t => {
  const iframe = document.createElement("iframe");

  // We can't just leave it at the actual initial about:blank because of the interop issues mentioned above.
  // So put it in the "currently on initial about:blank, but loading something" state which interoperably does Window
  // reuse.
  iframe.src = "/common/blank.html";

  // Create the Window object. It will be for the initial about:blank since the load of /common/blank.html hasn't
  // completed.
  document.body.append(iframe);

  // Store a string on that Window object so we can later test if it's reused.
  iframe.contentWindow.persistedString = "Hello world!";

  // This will reset the initial about:blank-ness. But, it will also cancel any ongoing loads.
  iframe.contentDocument.open();

  // So, re-start the load of /common/blank.html.
  iframe.src = "/common/blank.html";

  // When the load finally happens, will it reuse the Window object or not?
  // Because document.open() resets the initial about:blank-ness, it will *not* reuse the Window object.
  // The point of the test is to assert that.
  iframe.addEventListener("load", t.step_func_done(() => {
    assert_equals(
      iframe.contentDocument.URL,
      iframe.src,
      "Prerequisite check: we are getting the right load event"
    );

    assert_equals(iframe.contentWindow.persistedString, undefined);
  }), { once: true });
}, "document.open() removes the initial about:blank-ness of the document");

// This test is redundant with others in WPT but it's intended to make it clear that document.open() is the
// distinguishing factor. It does the same exact thing but without document.open() and with the resulting final assert
// flipped.
async_test(t => {
  const iframe = document.createElement("iframe");
  iframe.src = "/common/blank.html";
  document.body.append(iframe);

  iframe.contentWindow.persistedString = "Hello world!";

  // NO document.open() call.

  iframe.src = "/common/blank.html";

  iframe.addEventListener("load", t.step_func_done(() => {
    assert_equals(
      iframe.contentDocument.URL,
      iframe.src,
      "Prerequisite check: we are getting the right load event"
    );

    assert_equals(iframe.contentWindow.persistedString, "Hello world!");
  }), { once: true });
}, "Double-check: without document.open(), Window reuse indeed happens");