tor-browser

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

abort.sub.window.js (4108B)


      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    let happened = false;
      7    const client = new frame.contentWindow.XMLHttpRequest();
      8    client.open("GET", "/common/blank.html");
      9    client.onload = t.step_func_done(e => {
     10      assert_true(happened);
     11    });
     12    client.onerror = t.unreached_func("XMLHttpRequest should have succeeded");
     13    client.onabort = t.unreached_func("XMLHttpRequest should have succeeded");
     14    client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded");
     15    client.send();
     16    frame.contentDocument.open();
     17    happened = true;
     18  });
     19  frame.src = "/common/blank.html";
     20 }, "document.open() does not abort documents that are not navigating (XMLHttpRequest)");
     21 
     22 async_test(t => {
     23  const frame = document.body.appendChild(document.createElement("iframe"));
     24  t.add_cleanup(() => frame.remove());
     25  frame.onload = t.step_func(() => {
     26    frame.onload = null;
     27    let happened = false;
     28    frame.contentWindow.fetch("/common/blank.html").then(
     29      t.step_func_done(() => {
     30        assert_true(happened);
     31      }),
     32      t.unreached_func("Fetch should have succeeded")
     33    );
     34    frame.contentDocument.open();
     35    happened = true;
     36  });
     37  frame.src = "/common/blank.html";
     38 }, "document.open() does not abort documents that are not navigating (fetch())");
     39 
     40 async_test(t => {
     41  const frame = document.body.appendChild(document.createElement("iframe"));
     42  t.add_cleanup(() => frame.remove());
     43  frame.onload = t.step_func(() => {
     44    frame.onload = null;
     45    let happened = false;
     46    const img = frame.contentDocument.createElement("img");
     47    img.src = new URL("resources/slow-png.py", document.URL);
     48    img.onload = t.step_func_done(() => {
     49      assert_true(happened);
     50    });
     51    img.onerror = t.unreached_func("Image loading should not have errored");
     52    // The image fetch starts in a microtask, so let's be sure to test after
     53    // the fetch has started.
     54    t.step_timeout(() => {
     55      frame.contentDocument.open();
     56      happened = true;
     57    });
     58  });
     59  frame.src = "/common/blank.html";
     60 }, "document.open() does not abort documents that are not navigating (image loading)");
     61 
     62 async_test(t => {
     63  const __SERVER__NAME = "{{host}}";
     64  const __PORT = {{ports[ws][0]}};
     65  const frame = document.body.appendChild(document.createElement("iframe"));
     66  t.add_cleanup(() => frame.remove());
     67  frame.onload = t.step_func(() => {
     68    frame.onload = null;
     69    let happened = false;
     70    const ws = new frame.contentWindow.WebSocket(`ws://${__SERVER__NAME}:${__PORT}/echo`);
     71    ws.onopen = t.step_func_done(() => {
     72      assert_true(happened);
     73    });
     74    ws.onclose = t.unreached_func("WebSocket fetch should have succeeded");
     75    ws.onerror = t.unreached_func("WebSocket should have no error");
     76    frame.contentDocument.open();
     77    happened = true;
     78  });
     79  frame.src = "/common/blank.html";
     80 }, "document.open() does not abort documents that are not navigating (establish a WebSocket connection)");
     81 
     82 // An already established WebSocket connection shouldn't be terminated during
     83 // an "abort a document" anyway. Test just for completeness.
     84 async_test(t => {
     85  const __SERVER__NAME = "{{host}}";
     86  const __PORT = {{ports[ws][0]}};
     87  const frame = document.body.appendChild(document.createElement("iframe"));
     88  t.add_cleanup(() => frame.remove());
     89  frame.onload = t.step_func(() => {
     90    frame.onload = null;
     91    let happened = false;
     92    const ws = new frame.contentWindow.WebSocket(`ws://${__SERVER__NAME}:${__PORT}/echo`);
     93    ws.onopen = t.step_func(() => {
     94      t.step_timeout(t.step_func_done(() => {
     95        assert_true(happened);
     96      }), 100);
     97      frame.contentDocument.open();
     98      happened = true;
     99    });
    100    ws.onclose = t.unreached_func("WebSocket should not be closed");
    101    ws.onerror = t.unreached_func("WebSocket should have no error");
    102  });
    103  frame.src = "/common/blank.html";
    104 }, "document.open() does not abort documents that are not navigating (already established WebSocket connection)");