|
1 function ok(what, msg) { |
|
2 postMessage({ event: msg, test: 'ok', a: what }); |
|
3 } |
|
4 |
|
5 function is(a, b, msg) { |
|
6 postMessage({ event: msg, test: 'is', a: a, b: b }); |
|
7 } |
|
8 |
|
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 ]; |
|
26 |
|
27 var invalidParameters = [ |
|
28 {get mozSystem() { throw "Bla"; } }, |
|
29 ]; |
|
30 |
|
31 |
|
32 function testParameters(havePrivileges) { |
|
33 |
|
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)); |
|
43 |
|
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 } |
|
55 |
|
56 |
|
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 } |
|
67 |
|
68 validParameters.forEach(testValidParameter); |
|
69 invalidParameters.forEach(testInvalidParameter); |
|
70 } |
|
71 |
|
72 self.onmessage = function onmessage(event) { |
|
73 testParameters(event.data); |
|
74 postMessage({test: "finish"}); |
|
75 }; |