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 // async = false |
| 14 xhr.open('POST', url, false); |
| 15 xhr.onerror = () => testFailed("onerror callback should not be called."); |
| 16 // Assumed a Content-Type that turns it into a non-simple CORS request. |
| 17 if (contentType) |
| 18 xhr.setRequestHeader('Content-Type', contentType); |
| 19 try { |
| 20 xhr.send(); |
| 21 } catch(e) { |
| 22 errorEvent = e; |
| 23 shouldBeEqualToString("errorEvent.name", "NetworkError"); |
| 24 } |
| 25 |
| 26 xhr = new XMLHttpRequest(); |
| 27 // async = true |
| 28 xhr.open('POST', url, true); |
14 xhr.onerror = function (a) { | 29 xhr.onerror = function (a) { |
15 errorEvent = a; | 30 errorEvent = a; |
16 shouldBeEqualToString("errorEvent.type", "error"); | 31 shouldBeEqualToString("errorEvent.type", "error"); |
17 setTimeout(runTest, 0); | 32 setTimeout(runTest, 0); |
18 }; | 33 }; |
19 // Assumed a Content-Type that turns it into a non-simple CORS request. | 34 // Assumed a Content-Type that turns it into a non-simple CORS request. |
20 if (contentType) | 35 if (contentType) |
21 xhr.setRequestHeader('Content-Type', contentType); | 36 xhr.setRequestHeader('Content-Type', contentType); |
22 | 37 |
23 shouldNotThrow('xhr.send()'); | 38 shouldNotThrow('xhr.send()'); |
(...skipping 11 matching lines...) Expand all Loading... |
35 finishJSTest(); | 50 finishJSTest(); |
36 return; | 51 return; |
37 } | 52 } |
38 withContentType = !withContentType; | 53 withContentType = !withContentType; |
39 if (!withContentType) | 54 if (!withContentType) |
40 issueRequest(tests[0]); | 55 issueRequest(tests[0]); |
41 else | 56 else |
42 issueRequest(tests.shift(), 'application/json'); | 57 issueRequest(tests.shift(), 'application/json'); |
43 } | 58 } |
44 runTest(); | 59 runTest(); |
OLD | NEW |