tor-browser

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

abort-after-timeout.any.js (1313B)


      1 // META: title=XMLHttpRequest: abort() after a timeout should not fire "abort" event
      2 
      3    var test = async_test();
      4 
      5    test.step(function() {
      6        // timeout is 100ms
      7        // the download would otherwise take 1000ms
      8        // we check after 300ms to make sure abort does not fire an "abort" event
      9 
     10        var timeoutFired = false;
     11 
     12        var client = new XMLHttpRequest();
     13 
     14        assert_true('timeout' in client, 'xhr.timeout is not supported in this user agent');
     15 
     16        client.timeout = 100;
     17 
     18        test.step_timeout(() => {
     19            assert_true(timeoutFired);
     20 
     21            // abort should not cause the "abort" event to fire
     22            client.abort();
     23 
     24            test.step_timeout(() => { // use a timeout to catch any implementation that might queue an abort event for later - just in case
     25              test.done()
     26            }, 200);
     27 
     28            assert_equals(client.readyState, 0);
     29        }, 300);
     30 
     31        client.ontimeout = function () {
     32            timeoutFired = true;
     33        };
     34 
     35        client.onabort = test.step_func(function () {
     36            // this should not fire!
     37 
     38            assert_unreached("abort() should not cause the abort event to fire");
     39        });
     40 
     41        client.open("GET", "/common/blank.html?pipe=trickle(d1)", true);
     42        client.send(null);
     43    });