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

Side by Side Diff: LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-tripmine.html

Issue 344533006: [XHR] Rewrite layout test redirect-cross-origin-tripmine.html using Promises (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-tripmine-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 window.testSyncReq = req;
62 req.send("data"); 61 shouldThrow("testSyncReq.send('data')");
63 } catch (ex) { 62 checkResult();
64 }
65
66 setTimeout(function() { checkResult(); next(); }, 10);
67 } 63 }
68 64
69 function test1() { testAsync("POST", 307, test2) } 65 var ASYNC_TEST_CASES = [
70 function test2() { testAsync("GET", 307, test3) } 66 ["POST", 307],
71 function test3() { testAsync("POST", 303, test4) } 67 ["GET", 307],
72 function test4() { testAsync("GET", 303, test5) } 68 ["POST", 303],
73 function test5() { testAsync("POST", 302, test6) } 69 ["GET", 303],
74 function test6() { testAsync("GET", 302, test7) } 70 ["POST", 302],
75 function test7() { testAsync("DELETE", 307, test71) } 71 ["GET", 302],
76 function test71() { testAsync("POST", 301, test72) } 72 ["DELETE", 307],
77 function test72() { testAsync("GET", 301, test73) } 73 ["POST", 301],
78 function test73() { testAsync("DELETE", 301, test8) } 74 ["GET", 301],
79 function test8() { testSync("POST", 307, test9) } 75 ["DELETE", 301],
80 function test9() { testSync("GET", 307, test10) } 76 ];
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 77
90 function done() 78 var SYNC_TEST_CASES = [
79 ["POST", 307],
80 ["GET", 307],
81 ["POST", 303],
82 ["GET", 303],
83 ["POST", 302],
84 ["GET", 302],
85 ["DELETE", 307],
86 ["POST", 301],
87 ["GET", 301],
88 ["DELETE", 301],
89 ];
90
91 function finish()
91 { 92 {
92 resetTripmine(); 93 resetTripmine();
93 log("DONE");
94 94
95 if (window.testRunner) 95 finishJSTest();
96 testRunner.notifyDone();
97 } 96 }
98 97
99 test1(); 98 var prevPromise = Promise.resolve();
99 for (var i = 0; i < ASYNC_TEST_CASES.length; ++i) {
100 var method = ASYNC_TEST_CASES[i][0];
101 var code = ASYNC_TEST_CASES[i][1];
102 prevPromise = prevPromise.then(testAsync.bind(null, method, code));
103 }
104 prevPromise.then(function()
105 {
106 for (var i = 0; i < SYNC_TEST_CASES.length; ++i) {
107 var method = SYNC_TEST_CASES[i][0];
108 var code = SYNC_TEST_CASES[i][1];
109 testSync(method, code);
110 }
111 }).then(function()
112 {
113 finish();
114 }).catch(function(e)
tyoshino (SeeGerritForStatus) 2014/06/18 10:47:21 changed per offline discussion
115 {
116 testFailed(e);
117 finish();
118 });
119
100 </script> 120 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-tripmine-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698