OLD | NEW |
(Empty) | |
| 1 if (self.importScripts) |
| 2 importScripts("/js-test-resources/js-test.js"); |
| 3 |
| 4 description("Test EventSource text/event-stream parsing."); |
| 5 |
| 6 self.jsTestIsAsync = true; |
| 7 |
| 8 var count = -1; |
| 9 var es, evt; |
| 10 |
| 11 shouldNotThrow("es = new EventSource(\"resources/event-stream.php\");"); |
| 12 es.onopen = function (evt) { |
| 13 testPassed("got open event" + (!evt.data ? "" : " from server")); |
| 14 }; |
| 15 |
| 16 es.onmessage = function (arg) { |
| 17 evt = arg; |
| 18 switch(count++) { |
| 19 case -1: |
| 20 shouldBeEqualToString("evt.data", "\n\n"); |
| 21 break; |
| 22 case 0: |
| 23 shouldBeEqualToString("evt.data", "simple"); |
| 24 break; |
| 25 case 1: |
| 26 shouldBeEqualToString("evt.data", "spanning\nmultiple\n\nlines\n"); |
| 27 break; |
| 28 case 2: |
| 29 shouldBeEqualToString("evt.data", "id is 1"); |
| 30 shouldBeEqualToString("evt.lastEventId", "1"); |
| 31 break |
| 32 case 3: |
| 33 shouldBeEqualToString("evt.data", "id is still 1"); |
| 34 shouldBeEqualToString("evt.lastEventId", "1"); |
| 35 break; |
| 36 case 4: |
| 37 shouldBeEqualToString("evt.data", "no id"); |
| 38 shouldBeEqualToString("evt.lastEventId", ""); |
| 39 break; |
| 40 case 5: |
| 41 shouldBeEqualToString("evt.data", "a message event with the name \"messa
ge\""); |
| 42 break; |
| 43 case 6: |
| 44 shouldBeEqualToString("evt.data", "a line ending with crlf\na line with
a : (colon)\na line ending with cr"); |
| 45 break; |
| 46 default: |
| 47 testFailed("got unexpected event"); |
| 48 es.close(); |
| 49 } |
| 50 }; |
| 51 |
| 52 es.onerror = function () { |
| 53 es.close(); |
| 54 |
| 55 shouldBe("count", "7"); |
| 56 debug("DONE"); |
| 57 finishJSTest(); |
| 58 }; |
OLD | NEW |