toolkit/components/social/test/browser/worker_xhr.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Used to test XHR in the worker.
     2 onconnect = function(e) {
     3   let port = e.ports[0];
     4   let req;
     5   try {
     6     req = new XMLHttpRequest();
     7   } catch(e) {
     8     port.postMessage({topic: "done", result: "FAILED to create XHR object, " + e.toString() });
     9   }
    10   if (req === undefined) { // until bug 756173 is fixed...
    11     port.postMessage({topic: "done", result: "FAILED to create XHR object"});
    12     return;
    13   }
    14   // The test that uses this worker MUST use the same origin to load the worker.
    15   // We fetch the test app manifest so we can check the data is what we expect.
    16   let url = "https://example.com/browser/toolkit/components/social/test/browser/data.json";
    17   req.open("GET", url, true);
    18   req.onreadystatechange = function() {
    19     if (req.readyState === 4) {
    20       let ok = req.status == 200 && req.responseText.length > 0;
    21       if (ok) {
    22         // check we actually got something sane...
    23         try {
    24           let data = JSON.parse(req.responseText);
    25           ok = "response" in data;
    26         } catch(e) {
    27           ok = e.toString();
    28         }
    29       }
    30       port.postMessage({topic: "done", result: ok ? "ok" : "bad response"});
    31     }
    32   }
    33   req.send(null);
    34 }

mercurial