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/script-tests/eventsource-content-type-charset.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
(Empty)
1 if (self.importScripts)
2 importScripts("/js-test-resources/js-test.js");
3
4 description("Test EventSource with an event-stream with a Content-Type with a ch arset is still recognized.");
5 // Test for bug https://bugs.webkit.org/show_bug.cgi?id=45372
6
7 self.jsTestIsAsync = true;
8
9 var es;
10
11 function shouldGetMessage() {
12 debug("Content type: " + es.contentType);
13 shouldBeFalse("!!es.sawError");
14 shouldBeTrue("es.sawMessage");
15 shouldBeTrue("es.sawOpen");
16 }
17
18 function shouldFail() {
19 debug("Content type: " + es.contentType);
20 shouldBeTrue("es.sawError");
21 shouldBeFalse("!!es.sawMessage");
22 shouldBeFalse("!!es.sawOpen");
23 }
24
25 var i = 0;
26 var contentTypes = [ 'text/event-stream; charset=UTF-8',
27 'text/event-stream; charset=windows-1251',
28 'text/event-stream; charset=utf-8',
29 'text/event-stream; charset="UTF-8"',
30 'text/event-stream-foobar;'
31 ];
32
33 var expectedResultCallback = [ shouldGetMessage,
34 shouldFail,
35 shouldGetMessage,
36 shouldGetMessage,
37 shouldFail
38 ];
39
40 function openListener(evt)
41 {
42 evt.target.sawOpen = true;
43 }
44
45 function messageListener(evt)
46 {
47 evt.target.sawMessage = true;
48 evt.target.successCallback(evt.target);
49 evt.target.close();
50 next();
51 }
52
53 function errorListener(evt)
54 {
55 evt.target.sawError = true;
56 evt.target.successCallback(evt.target);
57 evt.target.close();
58 next();
59 }
60
61 function startRequest()
62 {
63 shouldNotThrow("es = new EventSource(\"/eventsource/resources/response-conte nt-type-charset.php?contentType=" + escape(contentTypes[i]) + "\")");
64 es.onopen = openListener;
65 es.onmessage = messageListener;
66 es.onerror = errorListener;
67 es.successCallback = expectedResultCallback[i];
68 es.contentType = contentTypes[i];
69 ++i;
70 }
71
72 function next()
73 {
74 if (i >= contentTypes.length) {
75 finishJSTest();
76 return;
77 }
78 startRequest();
79 }
80 startRequest();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698