dom/workers/test/test_xhr_parameters.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 function ok(what, msg) {
     2   postMessage({ event: msg, test: 'ok', a: what });
     3 }
     5 function is(a, b, msg) {
     6   postMessage({ event: msg, test: 'is', a: a, b: b });
     7 }
     9 // This is a copy of content/base/test/test_XHR_parameters.js
    10 var validParameters = [
    11   undefined,
    12   null,
    13   {},
    14   {mozSystem: ""},
    15   {mozSystem: 0},
    16   {mozAnon: 1},
    17   {mozAnon: []},
    18   {get mozAnon() { return true; }},
    19   0,
    20   7,
    21   Math.PI,
    22   "string",
    23   true,
    24   false,
    25 ];
    27 var invalidParameters = [
    28   {get mozSystem() { throw "Bla"; } },
    29 ];
    32 function testParameters(havePrivileges) {
    34   function testValidParameter(value) {
    35     var xhr;
    36     try {
    37       xhr = new XMLHttpRequest(value);
    38     } catch (ex) {
    39       ok(false, "Got unexpected exception: " + ex);
    40       return;
    41     }
    42     ok(!!xhr, "passed " + JSON.stringify(value));
    44     // If the page doesnt have privileges to create a system or anon XHR,
    45     // these flags will always be false no matter what is passed.
    46     var expectedAnon = false;
    47     var expectedSystem = false;
    48     if (havePrivileges) {
    49       expectedAnon = Boolean(value && value.mozAnon);
    50       expectedSystem = Boolean(value && value.mozSystem);
    51     }
    52     is(xhr.mozAnon, expectedAnon, "testing mozAnon");
    53     is(xhr.mozSystem, expectedSystem, "testing mozSystem");
    54   }
    57   function testInvalidParameter(value) {
    58     try {
    59       new XMLHttpRequest(value);
    60       ok(false, "invalid parameter did not cause exception: " +
    61          JSON.stringify(value));
    62     } catch (ex) {
    63       ok(true, "invalid parameter raised exception as expected: " +
    64        JSON.stringify(ex));
    65     }
    66   }
    68   validParameters.forEach(testValidParameter);
    69   invalidParameters.forEach(testInvalidParameter);
    70 }
    72 self.onmessage = function onmessage(event) {
    73   testParameters(event.data);
    74   postMessage({test: "finish"});
    75 };

mercurial