| Index: LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-tripmine.html
|
| diff --git a/LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-tripmine.html b/LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-tripmine.html
|
| index 6dc6df4d1d66caf4810128ae331e30efe3df7e25..ae8850687c2a2b4ade8be41fdf80e8ea4b80ef52 100644
|
| --- a/LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-tripmine.html
|
| +++ b/LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-tripmine.html
|
| @@ -1,15 +1,11 @@
|
| -<p>Test that a cross-origin redirect does not result in a non-simple request being sent to the target.</p>
|
| -<pre id="console"></pre>
|
| +<!DOCTYPE HTML>
|
| +<html>
|
| +<body>
|
| +<script src="/js-test-resources/js-test.js"></script>
|
| <script>
|
| -if (window.testRunner) {
|
| - testRunner.dumpAsText();
|
| - testRunner.waitUntilDone();
|
| -}
|
| +description("Test that a cross-origin redirect does not result in a non-simple request being sent to the target.");
|
|
|
| -function log(message)
|
| -{
|
| - document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
|
| -}
|
| +window.jsTestIsAsync = true;
|
|
|
| function resetTripmine()
|
| {
|
| @@ -18,7 +14,7 @@ function resetTripmine()
|
| req.send();
|
| }
|
|
|
| -function tripmineStatus()
|
| +function fetchTripmineStatus()
|
| {
|
| var req = new XMLHttpRequest;
|
| req.open("GET", "/resources/tripmine.php?command=status", false);
|
| @@ -28,16 +24,13 @@ function tripmineStatus()
|
|
|
| function checkResult()
|
| {
|
| - var status = tripmineStatus();
|
| - if (status == "")
|
| - log(" PASS");
|
| - else
|
| - log(" " + status);
|
| + window.tripmineStatus = fetchTripmineStatus();
|
| + shouldBeEmptyString("tripmineStatus");
|
| }
|
|
|
| -function testAsync(method, code, next)
|
| +function testAsync(method, code)
|
| {
|
| - log("Asynchronous XMLHttpRequest " + code + " " + method + " redirect:");
|
| + debug("Asynchronous XMLHttpRequest " + code + " " + method + " redirect:");
|
| resetTripmine();
|
|
|
| var req = new XMLHttpRequest;
|
| @@ -45,56 +38,83 @@ function testAsync(method, code, next)
|
| req.setRequestHeader("X-WebKit-Test", "*");
|
| req.setRequestHeader("Content-Type", "application/xml");
|
| req.send("data");
|
| - req.onload = function() { setTimeout(function() { checkResult(); next(); }, 10) }
|
| - req.onerror = function() { setTimeout(function() { checkResult(); next(); }, 10) }
|
| +
|
| + return new Promise(function(resolve, reject)
|
| + {
|
| + req.onloadend = function() {
|
| + checkResult();
|
| + resolve();
|
| + };
|
| + });
|
| }
|
|
|
| -function testSync(method, code, next)
|
| +function testSync(method, code)
|
| {
|
| - log("Synchronous XMLHttpRequest " + code + " " + method + " redirect:");
|
| + debug("Synchronous XMLHttpRequest " + code + " " + method + " redirect:");
|
| resetTripmine();
|
|
|
| var req = new XMLHttpRequest;
|
| req.open(method, "/resources/redirect.php?code=" + code + "&url=http://localhost:8000/resources/tripmine.php", false);
|
| req.setRequestHeader("X-WebKit-Test", "*");
|
| req.setRequestHeader("Content-Type", "application/xml");
|
| - try {
|
| - req.send("data");
|
| - } catch (ex) {
|
| - }
|
| -
|
| - setTimeout(function() { checkResult(); next(); }, 10);
|
| + window.testSyncReq = req;
|
| + shouldThrow("testSyncReq.send('data')");
|
| + checkResult();
|
| }
|
|
|
| -function test1() { testAsync("POST", 307, test2) }
|
| -function test2() { testAsync("GET", 307, test3) }
|
| -function test3() { testAsync("POST", 303, test4) }
|
| -function test4() { testAsync("GET", 303, test5) }
|
| -function test5() { testAsync("POST", 302, test6) }
|
| -function test6() { testAsync("GET", 302, test7) }
|
| -function test7() { testAsync("DELETE", 307, test71) }
|
| -function test71() { testAsync("POST", 301, test72) }
|
| -function test72() { testAsync("GET", 301, test73) }
|
| -function test73() { testAsync("DELETE", 301, test8) }
|
| -function test8() { testSync("POST", 307, test9) }
|
| -function test9() { testSync("GET", 307, test10) }
|
| -function test10() { testSync("POST", 303, test11) }
|
| -function test11() { testSync("GET", 303, test12) }
|
| -function test12() { testSync("POST", 302, test13) }
|
| -function test13() { testSync("GET", 302, test14) }
|
| -function test14() { testSync("DELETE", 307, test15) }
|
| -function test15() { testSync("POST", 301, test16) }
|
| -function test16() { testSync("GET", 301, test17) }
|
| -function test17() { testSync("DELETE", 301, done) }
|
| +var ASYNC_TEST_CASES = [
|
| + ["POST", 307],
|
| + ["GET", 307],
|
| + ["POST", 303],
|
| + ["GET", 303],
|
| + ["POST", 302],
|
| + ["GET", 302],
|
| + ["DELETE", 307],
|
| + ["POST", 301],
|
| + ["GET", 301],
|
| + ["DELETE", 301],
|
| +];
|
| +
|
| +var SYNC_TEST_CASES = [
|
| + ["POST", 307],
|
| + ["GET", 307],
|
| + ["POST", 303],
|
| + ["GET", 303],
|
| + ["POST", 302],
|
| + ["GET", 302],
|
| + ["DELETE", 307],
|
| + ["POST", 301],
|
| + ["GET", 301],
|
| + ["DELETE", 301],
|
| +];
|
|
|
| -function done()
|
| +function finish()
|
| {
|
| resetTripmine();
|
| - log("DONE");
|
|
|
| - if (window.testRunner)
|
| - testRunner.notifyDone();
|
| + finishJSTest();
|
| }
|
|
|
| -test1();
|
| +var prevPromise = Promise.resolve();
|
| +for (var i = 0; i < ASYNC_TEST_CASES.length; ++i) {
|
| + var method = ASYNC_TEST_CASES[i][0];
|
| + var code = ASYNC_TEST_CASES[i][1];
|
| + prevPromise = prevPromise.then(testAsync.bind(null, method, code));
|
| +}
|
| +prevPromise.then(function()
|
| +{
|
| + for (var i = 0; i < SYNC_TEST_CASES.length; ++i) {
|
| + var method = SYNC_TEST_CASES[i][0];
|
| + var code = SYNC_TEST_CASES[i][1];
|
| + testSync(method, code);
|
| + }
|
| +}).then(function()
|
| +{
|
| + finish();
|
| +}, function(e)
|
| +{
|
| + testFailed(e);
|
| + finish();
|
| +});
|
| +
|
| </script>
|
|
|