Bug 1206121 - Test for XHR in the worker and status code when redirect a CORS url, r=khuey

This commit is contained in:
Andrea Marchesini 2016-03-08 08:19:45 +01:00
Родитель 511c3a74c2
Коммит 9c656d5bba
4 изменённых файлов: 58 добавлений и 0 удалений

Просмотреть файл

@ -97,6 +97,7 @@ support-files =
xhr_worker.js
xhr_headers_worker.js
xhr_headers_server.sjs
xhr_cors_redirect.js
url_exceptions_worker.js
urlSearchParams_worker.js
subdir/relativeLoad_sub_worker.js
@ -127,6 +128,7 @@ support-files =
worker_fileReader.js
fileapi_chromeScript.js
importScripts_3rdParty_worker.js
xhr_cors_redirect.sjs
[test_404.html]
[test_atob.html]
@ -246,6 +248,7 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 982828
skip-if = buildapp == 'b2g'
[test_xhr_responseURL.html]
[test_xhr_system.html]
[test_xhr_cors_redirect.html]
skip-if = buildapp == 'b2g'
[test_xhr_timeout.html]
skip-if = (os == "win") || (os == "mac") || toolkit == 'android' #bug 798220

Просмотреть файл

@ -0,0 +1,35 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for Bug 1206121</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
"use strict";
var worker = new Worker("xhr_cors_redirect.js");
worker.onmessage = function(e) {
is(e.data, 200, "We want to read 200 here.");
runTests();
};
var tests = [ 'http://example.com/tests/dom/workers/test/xhr_cors_redirect.sjs',
'http://example.com/tests/dom/workers/test/xhr_cors_redirect.sjs?redirect',
'xhr_cors_redirect.sjs?redirect' ];
function runTests() {
if (!tests.length) {
SimpleTest.finish();
return;
}
worker.postMessage(tests.shift());
}
SimpleTest.waitForExplicitFinish();
</script>
</head>
<body onload="runTests()">
</body>
</html>

Просмотреть файл

@ -0,0 +1,10 @@
onmessage = function(e) {
var xhr = new XMLHttpRequest();
xhr.open('GET', e.data, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
postMessage(xhr.status);
}
};
xhr.send();
};

Просмотреть файл

@ -0,0 +1,10 @@
function handleRequest(request, response) {
response.setHeader("Access-Control-Allow-Origin", "*");
if (request.queryString == 'redirect') {
response.setStatusLine("1.1", 302, "Found");
response.setHeader("Location", "xhr_cors_redirect.sjs");
} else {
response.write("'hello world'");
}
}