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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/xmlhttprequest/resources/cross-origin-unsupported-url.js
diff --git a/LayoutTests/http/tests/xmlhttprequest/resources/cross-origin-unsupported-url.js b/LayoutTests/http/tests/xmlhttprequest/resources/cross-origin-unsupported-url.js
new file mode 100644
index 0000000000000000000000000000000000000000..6f920bcf4ac954263f4c6f04721de2c56f3a0bef
--- /dev/null
+++ b/LayoutTests/http/tests/xmlhttprequest/resources/cross-origin-unsupported-url.js
@@ -0,0 +1,61 @@
+if (self.importScripts)
+ importScripts("/js-test-resources/js-test.js");
+
+self.jsTestIsAsync = true;
+
+description("Test cross-origin XHRs to CORS-unsupported protocol schemes in the URL.");
+
+var xhr;
+var errorEvent;
+function issueRequest(url, contentType)
+{
+ xhr = new XMLHttpRequest();
+ xhr.open('POST', url);
+ xhr.onerror = function (a) {
+ errorEvent = a;
+ shouldBeEqualToString("errorEvent.type", "error");
+ setTimeout(runTest, 0);
+ };
+ // Assumed a Content-Type that turns it into a non-simple CORS request.
+ if (contentType)
+ xhr.setRequestHeader('Content-Type', contentType);
+
+ if (self.importScripts) {
+ // Initiating the load on the main thread is not performed synchronously,
+ // so send() will not have an exception code set by the time it
+ // completes in the Worker case. Hence, no exception will be
+ // thrown by the operation.
+ shouldNotThrow('xhr.send()');
+ } else {
+ // The implementation of send() throws an exception if an
+ // exception code has been set, regardless of the sync flag.
+ // The spec restricts this to sync only, but as error progress
+ // events provide no actionable information, it is more helpful
+ // to the user to not follow spec.
+ //
+ // As the initiation of the request happens synchronously in send(),
+ // and it is determined that it is to an unsupported CORS URL, an
+ // exception is expected to be thrown.
+ shouldThrow('xhr.send()');
+ }
+}
+
+var withContentType = true;
+var tests = [ 'http://localhost:1291a/',
+ 'ftp://127.0.0.1',
+ 'localhost:8080/',
+ 'tel:1234' ];
+
+function runTest()
+{
+ if (!tests.length && withContentType) {
+ finishJSTest();
+ return;
+ }
+ withContentType = !withContentType;
+ if (!withContentType)
+ issueRequest(tests[0]);
+ else
+ issueRequest(tests.shift(), 'application/json');
+}
+runTest();

Powered by Google App Engine
This is Rietveld 408576698