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

Side by Side Diff: LayoutTests/http/tests/eventsource/eventsource-reconnect.html

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 <!DOCTYPE HTML>
2 <body> 2 <script src="/js-test-resources/js-test.js"></script>
3 <p>Test EventSource reconnect after end of event stream. Should print a series o f PASS messages followed by DONE.</p> 3 <script src="script-tests/eventsource-reconnect.js"></script>
4 <div id="result"></div>
5 <script>
6 function log(msg) {
7 document.getElementById("result").innerHTML += msg + "<br>";
8 }
9
10 var stateNames = ["CONNECTING", "OPEN", "CLOSED"];
11 for (var i in stateNames)
12 eval("var " + stateNames[i] + " = " + i);
13 var retryTimeout;
14
15 function checkReadyState(es, desiredState) {
16 var currState = es.readyState;
17 if (currState == desiredState)
18 log("PASS: state is " + stateNames[desiredState]);
19 else
20 log("FAIL: bad state (" + stateNames[currState] + ", should be " + state Names[desiredState] + ")");
21 }
22
23 if (window.testRunner) {
24 testRunner.dumpAsText();
25 testRunner.waitUntilDone();
26 }
27
28 var errCount = 0;
29 var es = new EventSource("resources/reconnect.php");
30
31 checkReadyState(es, CONNECTING);
32
33 es.onopen = function (evt) {
34 checkReadyState(es, OPEN);
35 };
36
37 es.onmessage = function (evt) {
38 if (!errCount) {
39 if (evt.lastEventId == "77")
40 log("PASS: got lastEventId \"77\"");
41 else
42 log("FAIL: unexpected lastEventId \"" + evt.lastEventId + "\"");
43 } else {
44 if (evt.data != "77")
45 log("FAIL: Last-Event-ID header was incorrect/missing");
46 else if (evt.lastEventId != "77")
47 log("FAIL: the lastEventId property was incorrect");
48 else
49 log("PASS: Last-Event-ID header and the lastEventId property were co rrect");
50 }
51 };
52
53 es.onerror = function () {
54 errCount++;
55 if (errCount < 2) {
56 checkReadyState(es, CONNECTING);
57 retryTimeout = setTimeout(end, 1000);
58 return;
59 }
60 clearTimeout(retryTimeout);
61 retryTimeout = null;
62 end();
63 };
64
65 function end() {
66 es.close();
67 if (retryTimeout)
68 log("FAIL: did not reconnect in time");
69 else {
70 checkReadyState(es, CLOSED);
71 log("DONE");
72 }
73
74 if (window.testRunner)
75 testRunner.notifyDone();
76 }
77 </script>
78 </body>
79 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698