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

Side by Side Diff: LayoutTests/http/tests/eventsource/eventsource-parse-event-stream.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 text/event-stream parsing. Should print a series of PASS mes sages followed by DONE.</p> 3 <script src="script-tests/eventsource-parse-event-stream.js"></script>
4 <div id="result"></div>
5 <script>
6 function log(msg) {
7 document.getElementById("result").innerHTML += msg + "<br>";
8 }
9
10 if (window.testRunner) {
11 testRunner.dumpAsText();
12 testRunner.waitUntilDone();
13 }
14
15 var count = -1;
16 var es = new EventSource("resources/event-stream.php");
17
18 es.onopen = function (evt) {
19 if (!evt.data)
20 log("PASS: got open event");
21 else
22 log("PASS: got open event from server");
23 };
24
25 es.onmessage = function (evt) {
26 switch(count++) {
27 case -1:
28 if (evt.data == "\n\n")
29 log("PASS: received event with two newlines");
30 break;
31 case 0:
32 if (evt.data == "simple")
33 log("PASS: received event with data \"simple\"");
34 break;
35 case 1:
36 if (evt.data == "spanning\nmultiple\n\nlines\n")
37 log("PASS: received event with data spanning multiple lines");
38 break;
39 case 2:
40 if (evt.data == "id is 1" && evt.lastEventId == "1")
41 log("PASS: received event and lastEventId is \"1\"");
42 break
43 case 3:
44 if (evt.data == "id is still 1" && evt.lastEventId == "1")
45 log("PASS: received event and lastEventId is still \"1\"");
46 break;
47 case 4:
48 if (evt.data == "no id" && evt.lastEventId == "")
49 log("PASS: received event and lastEventId has been cleared");
50 break;
51 case 5:
52 if (evt.data == "a message event with the name \"message\"")
53 log("PASS: received event and the event name has been reset");
54 break;
55 case 6:
56 if (evt.data == "a line ending with crlf\na line with a : (colon)\na line ending with cr");
57 log("PASS: received event with data that contains a colon");
58 break;
59 default:
60 log("FAIL: got unexpected event");
61 es.close();
62 }
63 };
64
65 es.onerror = function () {
66 es.close();
67
68 if (count != 7)
69 log("FAIL: got unexpected error event");
70 else
71 log("DONE");
72
73 if (window.testRunner)
74 testRunner.notifyDone();
75 };
76 </script>
77 </body>
78 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698