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

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

Issue 389053003: Always report access control failure if accessing unsupported URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Include supported schemes in console error message Created 6 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
(Empty)
1 if (self.importScripts)
2 importScripts("/js-test-resources/js-test.js");
3
4 self.jsTestIsAsync = true;
5
6 description("Test cross-origin XHRs to CORS-unsupported protocol schemes in the URL.");
7
8 var xhr;
9 var errorEvent;
10 function issueRequest(url, contentType)
11 {
12 xhr = new XMLHttpRequest();
13 xhr.open('POST', url);
14 xhr.onerror = function (a) {
15 errorEvent = a;
16 shouldBeEqualToString("errorEvent.type", "error");
17 setTimeout(runTest, 0);
18 };
19 // Assumed a Content-Type that turns it into a non-simple CORS request.
20 if (contentType)
21 xhr.setRequestHeader('Content-Type', contentType);
22
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 }
41 }
42
43 var withContentType = true;
44 var tests = [ 'http://localhost:1291a/',
45 'ftp://127.0.0.1',
46 'localhost:8080/',
47 'tel:1234' ];
48
49 function runTest()
50 {
51 if (!tests.length && withContentType) {
52 finishJSTest();
53 return;
54 }
55 withContentType = !withContentType;
56 if (!withContentType)
57 issueRequest(tests[0]);
58 else
59 issueRequest(tests.shift(), 'application/json');
60 }
61 runTest();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698