1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/workers/test/test_xhr_parameters.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +function ok(what, msg) { 1.5 + postMessage({ event: msg, test: 'ok', a: what }); 1.6 +} 1.7 + 1.8 +function is(a, b, msg) { 1.9 + postMessage({ event: msg, test: 'is', a: a, b: b }); 1.10 +} 1.11 + 1.12 +// This is a copy of content/base/test/test_XHR_parameters.js 1.13 +var validParameters = [ 1.14 + undefined, 1.15 + null, 1.16 + {}, 1.17 + {mozSystem: ""}, 1.18 + {mozSystem: 0}, 1.19 + {mozAnon: 1}, 1.20 + {mozAnon: []}, 1.21 + {get mozAnon() { return true; }}, 1.22 + 0, 1.23 + 7, 1.24 + Math.PI, 1.25 + "string", 1.26 + true, 1.27 + false, 1.28 +]; 1.29 + 1.30 +var invalidParameters = [ 1.31 + {get mozSystem() { throw "Bla"; } }, 1.32 +]; 1.33 + 1.34 + 1.35 +function testParameters(havePrivileges) { 1.36 + 1.37 + function testValidParameter(value) { 1.38 + var xhr; 1.39 + try { 1.40 + xhr = new XMLHttpRequest(value); 1.41 + } catch (ex) { 1.42 + ok(false, "Got unexpected exception: " + ex); 1.43 + return; 1.44 + } 1.45 + ok(!!xhr, "passed " + JSON.stringify(value)); 1.46 + 1.47 + // If the page doesnt have privileges to create a system or anon XHR, 1.48 + // these flags will always be false no matter what is passed. 1.49 + var expectedAnon = false; 1.50 + var expectedSystem = false; 1.51 + if (havePrivileges) { 1.52 + expectedAnon = Boolean(value && value.mozAnon); 1.53 + expectedSystem = Boolean(value && value.mozSystem); 1.54 + } 1.55 + is(xhr.mozAnon, expectedAnon, "testing mozAnon"); 1.56 + is(xhr.mozSystem, expectedSystem, "testing mozSystem"); 1.57 + } 1.58 + 1.59 + 1.60 + function testInvalidParameter(value) { 1.61 + try { 1.62 + new XMLHttpRequest(value); 1.63 + ok(false, "invalid parameter did not cause exception: " + 1.64 + JSON.stringify(value)); 1.65 + } catch (ex) { 1.66 + ok(true, "invalid parameter raised exception as expected: " + 1.67 + JSON.stringify(ex)); 1.68 + } 1.69 + } 1.70 + 1.71 + validParameters.forEach(testValidParameter); 1.72 + invalidParameters.forEach(testInvalidParameter); 1.73 +} 1.74 + 1.75 +self.onmessage = function onmessage(event) { 1.76 + testParameters(event.data); 1.77 + postMessage({test: "finish"}); 1.78 +};