tor-browser

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

open-after-stop.window.js (1422B)


      1 // window.stop() below prevents the load event from firing, so wait until it is
      2 // fired to start the test.
      3 setup({explicit_done: true });
      4 
      5 onload = () => {
      6  async_test(function(t) {
      7    const client = new XMLHttpRequest();
      8 
      9    const result = [];
     10    const expected = [
     11      'readystatechange', 0, 1,  // open()
     12    ];
     13 
     14    let state = 0;
     15 
     16    client.onreadystatechange = t.step_func(() => {
     17      result.push('readystatechange', state, client.readyState);
     18    });
     19    client.onabort = t.unreached_func("abort should not be fired after window.stop() and open()");
     20    client.onloadend = t.unreached_func("loadend should not be fired after window.stop() and open()");
     21 
     22    client.open("GET", "resources/well-formed.xml");
     23    assert_equals(client.readyState, 1);
     24 
     25    state = 1;
     26    client.send(null);
     27    state = 2;
     28    window.stop();
     29    // Unlike client.abort(), window.stop() does not change readyState
     30    // immediately, rather through a task...
     31    assert_equals(client.readyState, 1);
     32    state = 3;
     33    // ... which is then canceled when we open a new request anyway.
     34    client.open("GET", "resources/well-formed.xml");
     35    assert_equals(client.readyState, 1);
     36    assert_array_equals(result, expected);
     37 
     38    // Give the abort and loadend events a chance to fire (erroneously) before
     39    // calling this a success.
     40    t.step_timeout(t.step_func_done(), 1000);
     41  }, "open() after window.stop()");
     42  done();
     43 };