OLD | NEW |
1 if (self.importScripts) | 1 if (self.importScripts) |
2 importScripts("/js-test-resources/js-test.js"); | 2 importScripts("/js-test-resources/js-test.js"); |
3 | 3 |
4 self.jsTestIsAsync = true; | 4 self.jsTestIsAsync = true; |
5 | 5 |
6 description("Test cross-origin XHRs to CORS-unsupported protocol schemes in the
URL."); | 6 description("Test cross-origin XHRs to CORS-unsupported protocol schemes in the
URL."); |
7 | 7 |
8 var xhr; | 8 var xhr; |
9 var errorEvent; | 9 var errorEvent; |
10 function issueRequest(url, contentType) | 10 function issueRequest(url, contentType) |
11 { | 11 { |
12 xhr = new XMLHttpRequest(); | 12 xhr = new XMLHttpRequest(); |
13 xhr.open('POST', url); | 13 xhr.open('POST', url); |
14 xhr.onerror = function (a) { | 14 xhr.onerror = function (a) { |
15 errorEvent = a; | 15 errorEvent = a; |
16 shouldBeEqualToString("errorEvent.type", "error"); | 16 shouldBeEqualToString("errorEvent.type", "error"); |
17 setTimeout(runTest, 0); | 17 setTimeout(runTest, 0); |
18 }; | 18 }; |
19 // Assumed a Content-Type that turns it into a non-simple CORS request. | 19 // Assumed a Content-Type that turns it into a non-simple CORS request. |
20 if (contentType) | 20 if (contentType) |
21 xhr.setRequestHeader('Content-Type', contentType); | 21 xhr.setRequestHeader('Content-Type', contentType); |
22 | 22 |
23 shouldNotThrow('xhr.send()'); | 23 if (self.importScripts) { |
| 24 // Initiating the load on the main thread is not performed synchronously
, |
| 25 // so send() will not have an exception code set by the time it |
| 26 // completes in the Worker case. Hence, no exception will be |
| 27 // thrown by the operation. |
| 28 shouldNotThrow('xhr.send()'); |
| 29 } else { |
| 30 // The implementation of send() throws an exception if an |
| 31 // exception code has been set, regardless of the sync flag. |
| 32 // The spec restricts this to sync only, but as error progress |
| 33 // events provide no actionable information, it is more helpful |
| 34 // to the user to not follow spec. |
| 35 // |
| 36 // As the initiation of the request happens synchronously in send(), |
| 37 // and it is determined that it is to an unsupported CORS URL, an |
| 38 // exception is expected to be thrown. |
| 39 shouldThrow('xhr.send()'); |
| 40 } |
24 } | 41 } |
25 | 42 |
26 var withContentType = true; | 43 var withContentType = true; |
27 var tests = [ 'http://localhost:1291a/', | 44 var tests = [ 'http://localhost:1291a/', |
28 'ftp://127.0.0.1', | 45 'ftp://127.0.0.1', |
29 'localhost:8080/', | 46 'localhost:8080/', |
30 'tel:1234' ]; | 47 'tel:1234' ]; |
31 | 48 |
32 function runTest() | 49 function runTest() |
33 { | 50 { |
34 if (!tests.length && withContentType) { | 51 if (!tests.length && withContentType) { |
35 finishJSTest(); | 52 finishJSTest(); |
36 return; | 53 return; |
37 } | 54 } |
38 withContentType = !withContentType; | 55 withContentType = !withContentType; |
39 if (!withContentType) | 56 if (!withContentType) |
40 issueRequest(tests[0]); | 57 issueRequest(tests[0]); |
41 else | 58 else |
42 issueRequest(tests.shift(), 'application/json'); | 59 issueRequest(tests.shift(), 'application/json'); |
43 } | 60 } |
44 runTest(); | 61 runTest(); |
OLD | NEW |