Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <p>Test that a cross-origin redirect does not result in a non-simple request bei ng sent to the target.</p> | 1 <!DOCTYPE HTML> |
| 2 <pre id="console"></pre> | 2 <html> |
| 3 <body> | |
| 4 <script src="/js-test-resources/js-test.js"></script> | |
| 3 <script> | 5 <script> |
| 4 if (window.testRunner) { | 6 description("Test that a cross-origin redirect does not result in a non-simple r equest being sent to the target."); |
| 5 testRunner.dumpAsText(); | |
| 6 testRunner.waitUntilDone(); | |
| 7 } | |
| 8 | 7 |
| 9 function log(message) | 8 window.jsTestIsAsync = true; |
| 10 { | |
| 11 document.getElementById('console').appendChild(document.createTextNode(messa ge + '\n')); | |
| 12 } | |
| 13 | 9 |
| 14 function resetTripmine() | 10 function resetTripmine() |
| 15 { | 11 { |
| 16 var req = new XMLHttpRequest; | 12 var req = new XMLHttpRequest; |
| 17 req.open("GET", "/resources/reset-temp-file.php?filename=tripmine-status", f alse); | 13 req.open("GET", "/resources/reset-temp-file.php?filename=tripmine-status", f alse); |
| 18 req.send(); | 14 req.send(); |
| 19 } | 15 } |
| 20 | 16 |
| 21 function tripmineStatus() | 17 function fetchTripmineStatus() |
| 22 { | 18 { |
| 23 var req = new XMLHttpRequest; | 19 var req = new XMLHttpRequest; |
| 24 req.open("GET", "/resources/tripmine.php?command=status", false); | 20 req.open("GET", "/resources/tripmine.php?command=status", false); |
| 25 req.send(); | 21 req.send(); |
| 26 return req.responseText; | 22 return req.responseText; |
| 27 } | 23 } |
| 28 | 24 |
| 29 function checkResult() | 25 function checkResult() |
| 30 { | 26 { |
| 31 var status = tripmineStatus(); | 27 window.tripmineStatus = fetchTripmineStatus(); |
| 32 if (status == "") | 28 shouldBeEmptyString("tripmineStatus"); |
| 33 log(" PASS"); | |
| 34 else | |
| 35 log(" " + status); | |
| 36 } | 29 } |
| 37 | 30 |
| 38 function testAsync(method, code, next) | 31 function testAsync(method, code) |
| 39 { | 32 { |
| 40 log("Asynchronous XMLHttpRequest " + code + " " + method + " redirect:"); | 33 debug("Asynchronous XMLHttpRequest " + code + " " + method + " redirect:"); |
| 41 resetTripmine(); | 34 resetTripmine(); |
| 42 | 35 |
| 43 var req = new XMLHttpRequest; | 36 var req = new XMLHttpRequest; |
| 44 req.open(method, "/resources/redirect.php?code=" + code + "&url=http://local host:8000/resources/tripmine.php", true); | 37 req.open(method, "/resources/redirect.php?code=" + code + "&url=http://local host:8000/resources/tripmine.php", true); |
| 45 req.setRequestHeader("X-WebKit-Test", "*"); | 38 req.setRequestHeader("X-WebKit-Test", "*"); |
| 46 req.setRequestHeader("Content-Type", "application/xml"); | 39 req.setRequestHeader("Content-Type", "application/xml"); |
| 47 req.send("data"); | 40 req.send("data"); |
| 48 req.onload = function() { setTimeout(function() { checkResult(); next(); }, 10) } | 41 |
| 49 req.onerror = function() { setTimeout(function() { checkResult(); next(); }, 10) } | 42 return new Promise(function(resolve, reject) |
| 43 { | |
| 44 req.onloadend = function() { | |
| 45 checkResult(); | |
| 46 resolve(); | |
| 47 }; | |
| 48 }); | |
| 50 } | 49 } |
| 51 | 50 |
| 52 function testSync(method, code, next) | 51 function testSync(method, code) |
| 53 { | 52 { |
| 54 log("Synchronous XMLHttpRequest " + code + " " + method + " redirect:"); | 53 debug("Synchronous XMLHttpRequest " + code + " " + method + " redirect:"); |
| 55 resetTripmine(); | 54 resetTripmine(); |
| 56 | 55 |
| 57 var req = new XMLHttpRequest; | 56 var req = new XMLHttpRequest; |
| 58 req.open(method, "/resources/redirect.php?code=" + code + "&url=http://local host:8000/resources/tripmine.php", false); | 57 req.open(method, "/resources/redirect.php?code=" + code + "&url=http://local host:8000/resources/tripmine.php", false); |
| 59 req.setRequestHeader("X-WebKit-Test", "*"); | 58 req.setRequestHeader("X-WebKit-Test", "*"); |
| 60 req.setRequestHeader("Content-Type", "application/xml"); | 59 req.setRequestHeader("Content-Type", "application/xml"); |
| 61 try { | 60 try { |
| 62 req.send("data"); | 61 req.send("data"); |
| 62 testFailed("req.send() should throw"); | |
|
yhirano
2014/06/18 08:02:48
shouldThrow?
tyoshino (SeeGerritForStatus)
2014/06/18 09:26:10
Done.
| |
| 63 } catch (ex) { | 63 } catch (ex) { |
| 64 checkResult(); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 ASYNC_TEST_CASES = [ | |
|
yhirano
2014/06/18 08:02:48
var is missing.
tyoshino (SeeGerritForStatus)
2014/06/18 09:26:10
Done.
| |
| 69 ["POST", 307], | |
| 70 ["GET", 307], | |
| 71 ["POST", 303], | |
| 72 ["GET", 303], | |
| 73 ["POST", 302], | |
| 74 ["GET", 302], | |
| 75 ["DELETE", 307], | |
| 76 ["POST", 301], | |
| 77 ["GET", 301], | |
| 78 ["DELETE", 301], | |
| 79 ]; | |
| 80 | |
| 81 SYNC_TEST_CASES = [ | |
|
yhirano
2014/06/18 08:02:48
ditto
tyoshino (SeeGerritForStatus)
2014/06/18 09:26:10
Done.
| |
| 82 ["POST", 307], | |
| 83 ["GET", 307], | |
| 84 ["POST", 303], | |
| 85 ["GET", 303], | |
| 86 ["POST", 302], | |
| 87 ["GET", 302], | |
| 88 ["DELETE", 307], | |
| 89 ["POST", 301], | |
| 90 ["GET", 301], | |
| 91 ["DELETE", 301], | |
| 92 ]; | |
| 93 | |
| 94 function finish() | |
| 95 { | |
| 96 resetTripmine(); | |
| 97 | |
| 98 finishJSTest(); | |
| 99 } | |
| 100 | |
| 101 var prevPromise = Promise.resolve(); | |
| 102 for (var i = 0; i < ASYNC_TEST_CASES.length; ++i) { | |
| 103 var method = ASYNC_TEST_CASES[i][0]; | |
| 104 var code = ASYNC_TEST_CASES[i][1]; | |
| 105 prevPromise = prevPromise.then(testAsync.bind(null, method, code)); | |
| 106 } | |
| 107 prevPromise.then(function() | |
| 108 { | |
| 109 for (var i = 0; i < SYNC_TEST_CASES.length; ++i) { | |
| 110 var method = SYNC_TEST_CASES[i][0]; | |
| 111 var code = SYNC_TEST_CASES[i][1]; | |
| 112 testSync(method, code); | |
| 64 } | 113 } |
| 65 | 114 |
| 66 setTimeout(function() { checkResult(); next(); }, 10); | 115 finish(); |
| 67 } | 116 }, function(e) |
|
yhirano
2014/06/18 08:02:48
I think this rescue function should be added at an
tyoshino (SeeGerritForStatus)
2014/06/18 09:26:10
Done.
| |
| 117 { | |
| 118 testFailed(e); | |
| 119 finish(); | |
| 120 }); | |
| 68 | 121 |
| 69 function test1() { testAsync("POST", 307, test2) } | |
| 70 function test2() { testAsync("GET", 307, test3) } | |
| 71 function test3() { testAsync("POST", 303, test4) } | |
| 72 function test4() { testAsync("GET", 303, test5) } | |
| 73 function test5() { testAsync("POST", 302, test6) } | |
| 74 function test6() { testAsync("GET", 302, test7) } | |
| 75 function test7() { testAsync("DELETE", 307, test71) } | |
| 76 function test71() { testAsync("POST", 301, test72) } | |
| 77 function test72() { testAsync("GET", 301, test73) } | |
| 78 function test73() { testAsync("DELETE", 301, test8) } | |
| 79 function test8() { testSync("POST", 307, test9) } | |
| 80 function test9() { testSync("GET", 307, test10) } | |
| 81 function test10() { testSync("POST", 303, test11) } | |
| 82 function test11() { testSync("GET", 303, test12) } | |
| 83 function test12() { testSync("POST", 302, test13) } | |
| 84 function test13() { testSync("GET", 302, test14) } | |
| 85 function test14() { testSync("DELETE", 307, test15) } | |
| 86 function test15() { testSync("POST", 301, test16) } | |
| 87 function test16() { testSync("GET", 301, test17) } | |
| 88 function test17() { testSync("DELETE", 301, done) } | |
| 89 | |
| 90 function done() | |
| 91 { | |
| 92 resetTripmine(); | |
| 93 log("DONE"); | |
| 94 | |
| 95 if (window.testRunner) | |
| 96 testRunner.notifyDone(); | |
| 97 } | |
| 98 | |
| 99 test1(); | |
| 100 </script> | 122 </script> |
| OLD | NEW |