Bug 1642595 - Add more wpt tests for EventSource lastEventId. r=smaug,annevk
authorFarooq AR <farooqbckk@gmail.com>
Thu, 04 Jun 2020 07:35:35 +0000
changeset 597951 d0c45557821bf26012eef0f77cbcf5833c88ce55
parent 597950 d6b75801e9043c8d79ca760f707a419cbf3d0e4d
child 597952 e9ba31526222335ae6549998b6958f33a8fdb798
push id13310
push userffxbld-merge
push dateMon, 29 Jun 2020 14:50:06 +0000
treeherdermozilla-beta@15a59a0afa5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, annevk
bugs1642595
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1642595 - Add more wpt tests for EventSource lastEventId. r=smaug,annevk Differential Revision: https://phabricator.services.mozilla.com/D77785
testing/web-platform/tests/eventsource/format-field-id-3.window.js
testing/web-platform/tests/eventsource/resources/last-event-id2.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/eventsource/format-field-id-3.window.js
@@ -0,0 +1,56 @@
+const ID_PERSISTS = 1,
+ID_RESETS_1 = 2,
+ID_RESETS_2 = 3;
+
+async_test(testPersist, "EventSource: lastEventId persists");
+async_test(testReset(ID_RESETS_1), "EventSource: lastEventId resets");
+async_test(testReset(ID_RESETS_2), "EventSource: lastEventId resets (id without colon)");
+
+function testPersist(t) {
+    const source = new EventSource("resources/last-event-id2.py?type=" + ID_PERSISTS);
+    let counter = 0;
+    t.add_cleanup(() => source.close());
+    source.onmessage = t.step_func(e => {
+      counter++;
+      if (counter === 1) {
+          assert_equals(e.lastEventId, "1");
+          assert_equals(e.data, "1");
+      } else if (counter === 2) {
+          assert_equals(e.lastEventId, "1");
+          assert_equals(e.data, "2");
+      } else if (counter === 3) {
+          assert_equals(e.lastEventId, "2");
+          assert_equals(e.data, "3");
+      } else if (counter === 4) {
+          assert_equals(e.lastEventId, "2");
+          assert_equals(e.data, "4");
+          t.done();
+      } else {
+          assert_unreached();
+      }
+  });
+}
+
+function testReset(type) {
+  return function (t) {
+    const source = new EventSource("resources/last-event-id2.py?type=" + type);
+    let counter = 0;
+    t.add_cleanup(() => source.close());
+    source.onmessage = t.step_func(e => {
+      counter++;
+      if (counter === 1) {
+        assert_equals(e.lastEventId, "1");
+        assert_equals(e.data, "1");
+      } else if (counter === 2) {
+        assert_equals(e.lastEventId, "");
+        assert_equals(e.data, "2");
+      } else if (counter === 3) {
+        assert_equals(e.lastEventId, "");
+        assert_equals(e.data, "3");
+        t.done();
+      } else {
+          assert_unreached();
+      }
+    });
+  }
+}
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/eventsource/resources/last-event-id2.py
@@ -0,0 +1,23 @@
+ID_PERSISTS = 1
+ID_RESETS_1 = 2
+ID_RESETS_2 = 3
+
+def main(request, response):
+  response.headers.set(b"Content-Type", b"text/event-stream")
+  try:
+    test_type = int(request.GET.first(b"type", ID_PERSISTS))
+  except:
+    test_type = ID_PERSISTS
+
+  if test_type == ID_PERSISTS:
+    return b"id: 1\ndata: 1\n\ndata: 2\n\nid: 2\ndata:3\n\ndata:4\n\n"
+
+  elif test_type == ID_RESETS_1:
+    return b"id: 1\ndata: 1\n\nid:\ndata:2\n\ndata:3\n\n"
+
+  # empty id field without colon character (:) should also reset
+  elif test_type == ID_RESETS_2:
+    return b"id: 1\ndata: 1\n\nid\ndata:2\n\ndata:3\n\n"
+
+  else:
+    return b"data: invalid_test\n\n"