tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

remove-initial-about-blankness.window.js (2713B)


      1 // This tests the issues discussed in https://github.com/whatwg/html/issues/4299
      2 // and fixed in https://github.com/whatwg/html/pull/6567.
      3 
      4 // Note: because browsers do not interoperate on the spec's notion of window reuse (see e.g. https://crbug.com/778318)
      5 // we pick a specific interoperable test case, which is "currently on initial about:blank, but loading something".
      6 
      7 async_test(t => {
      8  const iframe = document.createElement("iframe");
      9 
     10  // We can't just leave it at the actual initial about:blank because of the interop issues mentioned above.
     11  // So put it in the "currently on initial about:blank, but loading something" state which interoperably does Window
     12  // reuse.
     13  iframe.src = "/common/blank.html";
     14 
     15  // Create the Window object. It will be for the initial about:blank since the load of /common/blank.html hasn't
     16  // completed.
     17  document.body.append(iframe);
     18 
     19  // Store a string on that Window object so we can later test if it's reused.
     20  iframe.contentWindow.persistedString = "Hello world!";
     21 
     22  // This will reset the initial about:blank-ness. But, it will also cancel any ongoing loads.
     23  iframe.contentDocument.open();
     24 
     25  // So, re-start the load of /common/blank.html.
     26  iframe.src = "/common/blank.html";
     27 
     28  // When the load finally happens, will it reuse the Window object or not?
     29  // Because document.open() resets the initial about:blank-ness, it will *not* reuse the Window object.
     30  // The point of the test is to assert that.
     31  iframe.addEventListener("load", t.step_func_done(() => {
     32    assert_equals(
     33      iframe.contentDocument.URL,
     34      iframe.src,
     35      "Prerequisite check: we are getting the right load event"
     36    );
     37 
     38    assert_equals(iframe.contentWindow.persistedString, undefined);
     39  }), { once: true });
     40 }, "document.open() removes the initial about:blank-ness of the document");
     41 
     42 // This test is redundant with others in WPT but it's intended to make it clear that document.open() is the
     43 // distinguishing factor. It does the same exact thing but without document.open() and with the resulting final assert
     44 // flipped.
     45 async_test(t => {
     46  const iframe = document.createElement("iframe");
     47  iframe.src = "/common/blank.html";
     48  document.body.append(iframe);
     49 
     50  iframe.contentWindow.persistedString = "Hello world!";
     51 
     52  // NO document.open() call.
     53 
     54  iframe.src = "/common/blank.html";
     55 
     56  iframe.addEventListener("load", t.step_func_done(() => {
     57    assert_equals(
     58      iframe.contentDocument.URL,
     59      iframe.src,
     60      "Prerequisite check: we are getting the right load event"
     61    );
     62 
     63    assert_equals(iframe.contentWindow.persistedString, "Hello world!");
     64  }), { once: true });
     65 }, "Double-check: without document.open(), Window reuse indeed happens");