Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Side by Side Diff: LayoutTests/http/tests/xmlhttprequest/resources/cross-origin-unsupported-url.js

Issue 1060113004: [XMLHttpRequest] Stop throwing for network error in async mode (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebease Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 if (self.importScripts) { 23 shouldNotThrow('xhr.send()');
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 }
41 } 24 }
42 25
43 var withContentType = true; 26 var withContentType = true;
44 var tests = [ 'http://localhost:1291a/', 27 var tests = [ 'http://localhost:1291a/',
45 'ftp://127.0.0.1', 28 'ftp://127.0.0.1',
46 'localhost:8080/', 29 'localhost:8080/',
47 'tel:1234' ]; 30 'tel:1234' ];
48 31
49 function runTest() 32 function runTest()
50 { 33 {
51 if (!tests.length && withContentType) { 34 if (!tests.length && withContentType) {
52 finishJSTest(); 35 finishJSTest();
53 return; 36 return;
54 } 37 }
55 withContentType = !withContentType; 38 withContentType = !withContentType;
56 if (!withContentType) 39 if (!withContentType)
57 issueRequest(tests[0]); 40 issueRequest(tests[0]);
58 else 41 else
59 issueRequest(tests.shift(), 'application/json'); 42 issueRequest(tests.shift(), 'application/json');
60 } 43 }
61 runTest(); 44 runTest();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698