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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/eventsource/script-tests/eventsource-content-type-charset.js
diff --git a/LayoutTests/http/tests/eventsource/script-tests/eventsource-content-type-charset.js b/LayoutTests/http/tests/eventsource/script-tests/eventsource-content-type-charset.js
new file mode 100644
index 0000000000000000000000000000000000000000..8fb52feb51834e71a116a160823423772dfcac0d
--- /dev/null
+++ b/LayoutTests/http/tests/eventsource/script-tests/eventsource-content-type-charset.js
@@ -0,0 +1,80 @@
+if (self.importScripts)
+ importScripts("/js-test-resources/js-test.js");
+
+description("Test EventSource with an event-stream with a Content-Type with a charset is still recognized.");
+// Test for bug https://bugs.webkit.org/show_bug.cgi?id=45372
+
+self.jsTestIsAsync = true;
+
+var es;
+
+function shouldGetMessage() {
+ debug("Content type: " + es.contentType);
+ shouldBeFalse("!!es.sawError");
+ shouldBeTrue("es.sawMessage");
+ shouldBeTrue("es.sawOpen");
+}
+
+function shouldFail() {
+ debug("Content type: " + es.contentType);
+ shouldBeTrue("es.sawError");
+ shouldBeFalse("!!es.sawMessage");
+ shouldBeFalse("!!es.sawOpen");
+}
+
+var i = 0;
+var contentTypes = [ 'text/event-stream; charset=UTF-8',
+ 'text/event-stream; charset=windows-1251',
+ 'text/event-stream; charset=utf-8',
+ 'text/event-stream; charset="UTF-8"',
+ 'text/event-stream-foobar;'
+ ];
+
+var expectedResultCallback = [ shouldGetMessage,
+ shouldFail,
+ shouldGetMessage,
+ shouldGetMessage,
+ shouldFail
+ ];
+
+function openListener(evt)
+{
+ evt.target.sawOpen = true;
+}
+
+function messageListener(evt)
+{
+ evt.target.sawMessage = true;
+ evt.target.successCallback(evt.target);
+ evt.target.close();
+ next();
+}
+
+function errorListener(evt)
+{
+ evt.target.sawError = true;
+ evt.target.successCallback(evt.target);
+ evt.target.close();
+ next();
+}
+
+function startRequest()
+{
+ shouldNotThrow("es = new EventSource(\"/eventsource/resources/response-content-type-charset.php?contentType=" + escape(contentTypes[i]) + "\")");
+ es.onopen = openListener;
+ es.onmessage = messageListener;
+ es.onerror = errorListener;
+ es.successCallback = expectedResultCallback[i];
+ es.contentType = contentTypes[i];
+ ++i;
+}
+
+function next()
+{
+ if (i >= contentTypes.length) {
+ finishJSTest();
+ return;
+ }
+ startRequest();
+}
+startRequest();

Powered by Google App Engine
This is Rietveld 408576698