tor-browser

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

abort-refresh-multisecond-header.window.js (2841B)


      1 // The following tests deal with the <meta http-equiv=refresh> pragma and the
      2 // `Refresh` header. The spec is still hazy on the precise behavior in those
      3 // cases but we use https://github.com/whatwg/html/issues/4003 as a guideline.
      4 //
      5 // This is separate from abort-refresh-multisecond-meta.window.js to avoid
      6 // browser interventions that limit the number of connections in a tab.
      7 
      8 async_test(t => {
      9  const frame = document.body.appendChild(document.createElement("iframe"));
     10  t.add_cleanup(() => frame.remove());
     11  frame.onload = t.step_func(() => {
     12    frame.onload = null;
     13    let happened = false;
     14 
     15    const client = new frame.contentWindow.XMLHttpRequest();
     16    client.open("GET", "/common/blank.html");
     17    client.onload = t.step_func_done(() => {
     18      assert_true(happened);
     19    });
     20    client.onerror = t.unreached_func("XMLHttpRequest should have succeeded");
     21    client.onabort = t.unreached_func("XMLHttpRequest should have succeeded");
     22    client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded");
     23    client.send();
     24 
     25    frame.contentDocument.open();
     26    happened = true;
     27  });
     28  frame.src = "resources/http-refresh.py?1";
     29 }, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 1-sec timeout (XMLHttpRequest)");
     30 
     31 async_test(t => {
     32  const frame = document.body.appendChild(document.createElement("iframe"));
     33  t.add_cleanup(() => frame.remove());
     34  frame.onload = t.step_func(() => {
     35    frame.onload = null;
     36    let happened = false;
     37    frame.contentWindow.fetch("/common/blank.html").then(
     38      t.step_func_done(() => {
     39        assert_true(happened);
     40      }),
     41      t.unreached_func("Fetch should have succeeded")
     42    );
     43    frame.contentDocument.open();
     44    happened = true;
     45  });
     46  frame.src = "resources/http-refresh.py?1";
     47 }, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 1-sec timeout (fetch())");
     48 
     49 async_test(t => {
     50  const frame = document.body.appendChild(document.createElement("iframe"));
     51  t.add_cleanup(() => frame.remove());
     52  frame.onload = t.step_func(() => {
     53    frame.onload = null;
     54    let happened = false;
     55    const img = frame.contentDocument.createElement("img");
     56    img.src = new URL("resources/slow-png.py", document.URL);
     57    img.onload = t.step_func_done(() => {
     58      assert_true(happened);
     59    });
     60    img.onerror = t.unreached_func("Image loading should not have errored");
     61    // The image fetch starts in a microtask, so let's be sure to test after
     62    // the fetch has started.
     63    t.step_timeout(() => {
     64      frame.contentDocument.open();
     65      happened = true;
     66    });
     67  });
     68  frame.src = "resources/http-refresh.py?4";
     69 }, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 4-sec timeout (image loading)");