tor-browser

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

abort-while-navigating.window.js (7714B)


      1 async_test(t => {
      2  const frame = document.body.appendChild(document.createElement("iframe"));
      3  t.add_cleanup(() => frame.remove());
      4  frame.onload = t.step_func(() => {
      5    frame.onload = null;
      6    const client = new frame.contentWindow.XMLHttpRequest();
      7    client.open("GET", "/common/blank.html");
      8    // The abort event handler is called synchronously in Chrome but
      9    // asynchronously in Firefox. See https://crbug.com/879620.
     10    client.onabort = t.step_func_done();
     11    client.send();
     12    frame.contentWindow.location.href = new URL("resources/dummy.html", document.URL);
     13    frame.contentDocument.open();
     14  });
     15  frame.src = "/common/blank.html";
     16 }, "document.open() aborts documents that are navigating through Location (XMLHttpRequest)");
     17 
     18 async_test(t => {
     19  const frame = document.body.appendChild(document.createElement("iframe"));
     20  t.add_cleanup(() => frame.remove());
     21  frame.onload = t.step_func(() => {
     22    frame.onload = null;
     23    let happened = false;
     24    frame.contentWindow.fetch("/common/blank.html").then(
     25      t.unreached_func("Fetch should have been aborted"),
     26      t.step_func_done(() => {
     27        assert_true(happened);
     28      }));
     29    frame.contentWindow.location.href = new URL("resources/dummy.html", document.URL);
     30    frame.contentDocument.open();
     31    happened = true;
     32  });
     33  frame.src = "/common/blank.html";
     34 }, "document.open() aborts documents that are navigating through Location (fetch())");
     35 
     36 // We cannot test for img element's error event for this test, as Firefox does
     37 // not fire the event if the fetch is aborted while Chrome does.
     38 async_test(t => {
     39  const frame = document.body.appendChild(document.createElement("iframe"));
     40  t.add_cleanup(() => frame.remove());
     41  frame.onload = t.step_func(() => {
     42    frame.onload = null;
     43    let happened = false;
     44    const img = frame.contentDocument.createElement("img");
     45    img.src = new URL("resources/slow-png.py", document.URL);
     46    img.onload = t.unreached_func("Image loading should not have succeeded");
     47    // The image fetch starts in a microtask, so let's be sure to test after
     48    // the fetch has started.
     49    t.step_timeout(() => {
     50      frame.contentWindow.location.href = new URL("resources/dummy.html", document.URL);
     51      frame.contentDocument.open();
     52      happened = true;
     53    });
     54    // If 3 seconds have passed and the image has still not loaded, we consider
     55    // it aborted. slow-png.py only sleeps for 2 wallclock seconds.
     56    t.step_timeout(t.step_func_done(() => {
     57      assert_true(happened);
     58    }), 3000);
     59  });
     60  frame.src = "/common/blank.html";
     61 }, "document.open() aborts documents that are navigating through Location (image loading)");
     62 
     63 async_test(t => {
     64  const div = document.body.appendChild(document.createElement("div"));
     65  t.add_cleanup(() => div.remove());
     66  div.innerHTML = "<iframe src='/common/slow.py'></iframe>";
     67  const frame = div.childNodes[0];
     68  const client = new frame.contentWindow.XMLHttpRequest();
     69  client.open("GET", "/common/blank.html");
     70  client.onabort = t.step_func_done();
     71  client.send();
     72  frame.contentDocument.open();
     73 }, "document.open() aborts documents that are navigating through iframe loading (XMLHttpRequest)");
     74 
     75 async_test(t => {
     76  const div = document.body.appendChild(document.createElement("div"));
     77  t.add_cleanup(() => div.remove());
     78  div.innerHTML = "<iframe src='/common/slow.py'></iframe>";
     79  const frame = div.childNodes[0];
     80  frame.contentWindow.fetch("/common/blank.html").then(
     81    t.unreached_func("Fetch should have been aborted"),
     82    t.step_func_done());
     83  frame.contentDocument.open();
     84 }, "document.open() aborts documents that are navigating through iframe loading (fetch())");
     85 
     86 // We cannot test for img element's error event for this test, as Firefox does
     87 // not fire the event if the fetch is aborted while Chrome does.
     88 //
     89 // We use /common/slow.py here as the source of the iframe, to prevent the
     90 // situation where when document.open() is called the initial about:blank
     91 // document has already become inactive.
     92 async_test(t => {
     93  const div = document.body.appendChild(document.createElement("div"));
     94  t.add_cleanup(() => div.remove());
     95  div.innerHTML = "<iframe src='/common/slow.py'></iframe>";
     96  const frame = div.childNodes[0];
     97  let happened = false;
     98  const img = frame.contentDocument.createElement("img");
     99  img.src = new URL("resources/slow-png.py", document.URL);
    100  img.onload = t.unreached_func("Image loading should not have succeeded");
    101  // The image fetch starts in a microtask, so let's be sure to test after
    102  // the fetch has started.
    103  t.step_timeout(() => {
    104    frame.contentDocument.open();
    105    happened = true;
    106  });
    107  // If 3 seconds have passed and the image has still not loaded, we consider
    108  // it aborted. slow-png.py only sleeps for 2 wallclock seconds.
    109  t.step_timeout(t.step_func_done(() => {
    110    assert_true(happened);
    111  }), 3000);
    112 }, "document.open() aborts documents that are navigating through iframe loading (image loading)");
    113 
    114 async_test(t => {
    115  const frame = document.body.appendChild(document.createElement("iframe"));
    116  t.add_cleanup(() => frame.remove());
    117  frame.onload = t.step_func(() => {
    118    frame.onload = null;
    119    const link = frame.contentDocument.body.appendChild(frame.contentDocument.createElement("a"));
    120    link.href = new URL("resources/dummy.html", document.URL);
    121 
    122    const client = new frame.contentWindow.XMLHttpRequest();
    123    client.open("GET", "/common/blank.html");
    124    client.onabort = t.step_func_done();
    125    client.send();
    126 
    127    link.click();
    128    frame.contentDocument.open();
    129  });
    130  frame.src = "/common/blank.html";
    131 }, "document.open() aborts documents that are queued for navigation through .click() (XMLHttpRequest)");
    132 
    133 async_test(t => {
    134  const frame = document.body.appendChild(document.createElement("iframe"));
    135  t.add_cleanup(() => frame.remove());
    136  frame.onload = t.step_func(() => {
    137    frame.onload = null;
    138    const link = frame.contentDocument.body.appendChild(frame.contentDocument.createElement("a"));
    139    link.href = new URL("resources/dummy.html", document.URL);
    140 
    141    frame.contentWindow.fetch("/common/blank.html").then(
    142      t.unreached_func("Fetch should have been aborted"),
    143      t.step_func_done());
    144 
    145    link.click();
    146    frame.contentDocument.open();
    147  });
    148  frame.src = "/common/blank.html";
    149 }, "document.open() aborts documents that are queued for navigation through .click() (fetch())");
    150 
    151 // We cannot test for img element's error event for this test, as Firefox does
    152 // not fire the event if the fetch is aborted while Chrome does.
    153 async_test(t => {
    154  const frame = document.body.appendChild(document.createElement("iframe"));
    155  t.add_cleanup(() => frame.remove());
    156  frame.onload = t.step_func(() => {
    157    frame.onload = null;
    158    const link = frame.contentDocument.body.appendChild(frame.contentDocument.createElement("a"));
    159    link.href = new URL("resources/dummy.html", document.URL);
    160 
    161    let happened = false;
    162    const img = frame.contentDocument.createElement("img");
    163    img.src = new URL("resources/slow-png.py", document.URL);
    164    img.onload = t.unreached_func("Image loading should not have succeeded");
    165    // The image fetch starts in a microtask, so let's be sure to test after
    166    // the fetch has started.
    167    t.step_timeout(() => {
    168      link.click();
    169      frame.contentDocument.open();
    170      happened = true;
    171    });
    172    // If 3 seconds have passed and the image has still not loaded, we consider
    173    // it aborted. slow-png.py only sleeps for 2 wallclock seconds.
    174    t.step_timeout(t.step_func_done(() => {
    175      assert_true(happened);
    176    }), 3000);
    177  });
    178  frame.src = "/common/blank.html";
    179 }, "document.open() aborts documents that are queued for navigation through .click() (image loading)");