Commit 00f958af authored by tyoshino@chromium.org's avatar tyoshino@chromium.org

[XHR] Rewrite layout test redirect-cross-origin-tripmine.html using Promises

Unnecessary delay is removed

Use js-test.js instead of manual logging, asserts

BUG=27569

Review URL: https://codereview.chromium.org/344533006

git-svn-id: svn://svn.chromium.org/blink/trunk@176484 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 99ae05c5
......@@ -10,45 +10,60 @@ CONSOLE ERROR: XMLHttpRequest cannot load http://localhost:8000/resources/tripmi
CONSOLE ERROR: XMLHttpRequest cannot load http://localhost:8000/resources/tripmine.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8000' is therefore not allowed access.
Test that a cross-origin redirect does not result in a non-simple request being sent to the target.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Asynchronous XMLHttpRequest 307 POST redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 307 GET redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 303 POST redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 303 GET redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 302 POST redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 302 GET redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 307 DELETE redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 301 POST redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 301 GET redirect:
PASS
PASS tripmineStatus is ""
Asynchronous XMLHttpRequest 301 DELETE redirect:
PASS
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 307 POST redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=307&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 307 GET redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=307&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 303 POST redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=303&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 303 GET redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=303&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 302 POST redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=302&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 302 GET redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=302&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 307 DELETE redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=307&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 301 POST redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=301&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 301 GET redirect:
PASS
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=301&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
Synchronous XMLHttpRequest 301 DELETE redirect:
PASS
DONE
PASS testSyncReq.send('data') threw exception NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://127.0.0.1:8000/resources/redirect.php?code=301&url=http://localhost:8000/resources/tripmine.php'..
PASS tripmineStatus is ""
PASS successfullyParsed is true
TEST COMPLETE
<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>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment