tor-browser

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

late-upload-events.htm (1423B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>Adding upload event listeners after send()</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <script src=support.js?pipe=sub></script>
      7 
      8 <h1>Adding upload event listeners after send()</h1>
      9 
     10 <div id=log></div>
     11 
     12 <script>
     13 function doTest(desc, headers) {
     14    async_test("Late listeners: " + desc).step(function() {
     15        var client = new XMLHttpRequest();
     16        var eventCounter = 0;
     17        client.open("POST", CROSSDOMAIN + "resources/status.py?headers=custom-header");
     18 
     19        for (var name in headers) {
     20            client.setRequestHeader(name, headers[name]);
     21        }
     22 
     23        client.onreadystatechange = this.step_func(function(e) {
     24            // Irrelevant if request is not finished
     25            if (client.readyState < 4) return;
     26            assert_equals(client.status, 200);
     27            assert_equals(eventCounter, 0, 'Events fired, but should not have');
     28            this.done();
     29        });
     30        client.send((new Array(3000)).join('xo'));
     31        client.upload.onprogress = client.upload.onloadend = client.upload.onloadstart = client.upload.onload = this.step_func(function(e) {
     32            eventCounter++;
     33            assert_unreached("Upload events should not fire, but did: " + e.type);
     34        });
     35    });
     36 }
     37 
     38 doTest("No preflight", {});
     39 doTest("Preflight", {"custom-header":"test"});
     40 </script>