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

Side by Side Diff: LayoutTests/http/tests/eventsource/script-tests/eventsource-status-code-states.js

Issue 347043002: Rework EventSource tests for better Worker test coverage. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move out CORS tests 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
OLDNEW
1 <html> 1 if (self.importScripts)
2 <body> 2 importScripts("/js-test-resources/js-test.js");
3 <p>Test EventSource states for different status codes. Should print a series of PASS messages followed by DONE.</p> 3
4 <div id="result"></div> 4 description("Test EventSource states for different status codes.");
5 <script> 5
6 function log(msg) { 6 self.jsTestIsAsync = true;
7 document.getElementById("result").innerHTML += msg + "<br>";
8 }
9 7
10 function arrayCompare(a1, a2) { 8 function arrayCompare(a1, a2) {
11 if (a1.length != a2.length) 9 if (a1.length != a2.length)
12 return false; 10 return false;
13 for (var i = 0; i < a1.length; i++) 11 for (var i = 0; i < a1.length; i++)
14 if (a1[i] != a2[i]) 12 if (a1[i] != a2[i])
15 return false; 13 return false;
16 return true; 14 return true;
17 } 15 }
18 16
19 var stateNames = ["CONNECTING", "OPEN", "CLOSED"]; 17 var stateNames = ["CONNECTING", "OPEN", "CLOSED"];
20 for (var i in stateNames) 18 for (var i in stateNames)
21 eval("var " + stateNames[i] + " = " + i); 19 eval("var " + stateNames[i] + " = " + i);
22 20
23 var tests = [{"code": 200, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]}, 21 var tests = [{"code": 200, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]},
24 {"code": 204, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]}, 22 {"code": 204, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]},
25 {"code": 205, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]}, 23 {"code": 205, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]},
26 {"code": 202, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]}, // other 2xx 24 {"code": 202, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]}, // other 2xx
27 {"code": 301, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]}, 25 {"code": 301, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]},
28 {"code": 302, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]}, 26 {"code": 302, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]},
29 {"code": 303, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]}, 27 {"code": 303, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]},
30 {"code": 307, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]}, 28 {"code": 307, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING , CLOSED]},
31 {"code": 404, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]}]; / / any other 29 {"code": 404, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]}]; / / any other
32 var count = 0; 30 var count = 0;
33 31
32 var es;
33 var states = [];
34
34 function runTest() { 35 function runTest() {
35 if (count >= tests.length) { 36 if (count >= tests.length) {
36 log("DONE"); 37 debug("DONE");
37 if (window.testRunner) 38 finishJSTest();
38 testRunner.notifyDone();
39 return; 39 return;
40 } 40 }
41 41
42 var states = []; 42 states = [];
43 var es = new EventSource("resources/status-codes.php?status-code=" + tests[c ount].code); 43 es = new EventSource("/eventsource/resources/status-codes.php?status-code=" + tests[count].code);
44 states[0] = es.readyState; 44 states[0] = es.readyState;
45 45
46 es.onopen = function () { 46 es.onopen = function () {
47 states[1] = es.readyState; 47 states[1] = es.readyState;
48 }; 48 };
49 49
50 es.onmessage = function (evt) { 50 es.onmessage = function (evt) {
51 states[2] = es.readyState; 51 states[2] = es.readyState;
52 }; 52 };
53 53
54 es.onerror = function () { 54 es.onerror = function () {
55 states[3] = es.readyState; 55 states[3] = es.readyState;
56 es.close(); 56 es.close();
57 states[4] = es.readyState; 57 states[4] = es.readyState;
58 58
59 var result = arrayCompare(states, tests[count].expectedStates) ? "PASS" : "FAIL"; 59 shouldBeTrue("arrayCompare(states, tests[count].expectedStates)");
60 result += ": status code " + tests[count].code + " resulted in states "; 60 result = "status code " + tests[count].code + " resulted in states ";
61 for (var i in states) 61 for (var i in states)
62 result += (i != 0 ? ", " : "") + stateNames[states[i]]; 62 result += (i != 0 ? ", " : "") + stateNames[states[i]];
63 log(result); 63 testPassed(result);
64 64
65 count++;
65 setTimeout(runTest, 0); 66 setTimeout(runTest, 0);
66 count++;
67 }; 67 };
68 } 68 }
69
70 if (window.testRunner) {
71 testRunner.dumpAsText();
72 testRunner.waitUntilDone();
73 }
74
75 runTest(); 69 runTest();
76 </script>
77 </body>
78 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698