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

Side by Side Diff: LayoutTests/http/tests/eventsource/eventsource-content-type-charset.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 <!DOCTYPE html> 1 <!DOCTYPE HTML>
2 <html> 2 <script src="/js-test-resources/js-test.js"></script>
3 <body> 3 <script src="script-tests/eventsource-content-type-charset.js"></script>
4 <p>Test for bug <a href="https://bugs.webkit.org/show_bug.cgi?id=45372">45372</a >: https://bugs.webkit.org/show_bug.cgi?id=45372</p>
5 <p>Test EventSource with an event-stream with a Content-Type with a charset is s till recognized. You should see 5 PASSED below.</p>
6 <div id="result"></div>
7 <script>
8 function log(msg) {
9 document.getElementById("result").innerHTML += msg + "<br>";
10 }
11
12 if (window.testRunner) {
13 testRunner.dumpAsText();
14 testRunner.waitUntilDone();
15 }
16
17 function shouldGetMessage(es)
18 {
19 if (es.sawOpen && es.sawMessage && !es.sawError)
20 log("PASSED: " + es.contentType);
21 else
22 log("FAILED: " + es.contentType);
23 }
24
25 function shouldFail(es)
26 {
27 if (es.sawError && !es.sawOpen && !es.sawMessages)
28 log("PASSED: " + es.contentType);
29 else
30 log("FAILED: " + es.contentType);
31 }
32
33 var i = 0;
34 var contentTypes = [ 'text/event-stream; charset=UTF-8',
35 'text/event-stream; charset=windows-1251',
36 'text/event-stream; charset=utf-8',
37 'text/event-stream; charset="UTF-8"',
38 'text/event-stream-foobar;'
39 ];
40
41 var expectedResultCallback = [ shouldGetMessage,
42 shouldFail,
43 shouldGetMessage,
44 shouldGetMessage,
45 shouldFail
46 ];
47
48 function openListener(evt) {
49 evt.target.sawOpen = true;
50 };
51
52 function messageListener(evt) {
53 evt.target.sawMessage = true;
54 evt.target.successCallback(evt.target);
55 evt.target.close();
56 next();
57 };
58
59 function errorListener(evt) {
60 evt.target.sawError = true;
61 evt.target.successCallback(evt.target);
62 evt.target.close();
63 next();
64 };
65
66 function startRequest()
67 {
68 es = new EventSource("resources/response-content-type-charset.php?contentTyp e=" + escape(contentTypes[i]));
69 es.onopen = openListener;
70 es.onmessage = messageListener;
71 es.onerror = errorListener;
72 es.successCallback = expectedResultCallback[i];
73 es.contentType = contentTypes[i];
74 ++i;
75 }
76
77 function next() {
78 if (i >= contentTypes.length) {
79 end();
80 return;
81 }
82 startRequest();
83 }
84
85 function end() {
86 if (window.testRunner)
87 testRunner.notifyDone();
88 }
89 startRequest();
90 </script>
91 </body>
92 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698