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

Unified Diff: LayoutTests/http/tests/eventsource/script-tests/eventsource-reconnect.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-reconnect.js
diff --git a/LayoutTests/http/tests/eventsource/script-tests/eventsource-reconnect.js b/LayoutTests/http/tests/eventsource/script-tests/eventsource-reconnect.js
new file mode 100644
index 0000000000000000000000000000000000000000..7c4f54bd5411b6f190f1008f83e84c323d382284
--- /dev/null
+++ b/LayoutTests/http/tests/eventsource/script-tests/eventsource-reconnect.js
@@ -0,0 +1,51 @@
+if (self.importScripts)
+ importScripts("/js-test-resources/js-test.js");
+
+description("Test EventSource reconnect after end of event stream.");
+
+self.jsTestIsAsync = true;
+
+var retryTimeout;
+
+function checkReadyState(es, desiredState) {
+ shouldBe("es.readyState", "es." + desiredState);
+}
+
+var errCount = 0;
+var es = new EventSource("/eventsource/resources/reconnect.php");
+
+checkReadyState(es, "CONNECTING");
+
+es.onopen = function (evt) {
+ checkReadyState(es, "OPEN");
+};
+
+var evt;
+es.onmessage = function (arg) {
+ evt = arg;
+ if (errCount)
+ shouldBeEqualToString("evt.data", "77");
+ shouldBeEqualToString("evt.lastEventId", "77");
+};
+
+es.onerror = function () {
+ errCount++;
+ if (errCount < 2) {
+ checkReadyState(es, "CONNECTING");
+ retryTimeout = setTimeout(end, 1000);
+ return;
+ }
+ clearTimeout(retryTimeout);
+ retryTimeout = null;
+ end();
+};
+
+function end() {
+ es.close();
+ if (retryTimeout)
+ testFailed("did not reconnect in time");
+ else
+ checkReadyState(es, "CLOSED");
+
+ finishJSTest();
+}

Powered by Google App Engine
This is Rietveld 408576698