Bug 760770 - Allow 'progress' and 'suspend' events after 'ended'. r=roc, a=test-only
authorJW Wang <jwwang@mozilla.com>
Tue, 14 Oct 2014 23:28:00 +0200
changeset 225716 915073abfd8b
parent 225715 98fc091c4706
child 225717 c3fa7201e034
push id3988
push userryanvm@gmail.com
push date2014-10-17 01:37 +0000
treeherdermozilla-beta@c3fa7201e034 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, test-only
bugs760770
milestone34.0
Bug 760770 - Allow 'progress' and 'suspend' events after 'ended'. r=roc, a=test-only
content/media/test/test_timeupdate_small_files.html
--- a/content/media/test/test_timeupdate_small_files.html
+++ b/content/media/test/test_timeupdate_small_files.html
@@ -12,78 +12,75 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=495319">Mozilla Bug 495319</a>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 var manager = new MediaTestManager;
 
-function timeupdate(e) {
-  var v = e.target;
-  v._timeupdateCount++;
-  ok(v.gotEnded == 0, v._name + " - shouldn't get timeupdate after ended");
-}
-
 function ended(e) {
   var v = e.target;
-  ++v.gotEnded;
-  ok(v._timeupdateCount > 0, v._name + " - should see at least one timeupdate: " + v.currentTime);
-  v._finished = true;
+  ++v.counter["ended"];
+  is(v.counter["ended"], 1, v._name + " should see ended only once");
+  ok(v.counter["timeupdate"] > 0, v._name + " should see at least one timeupdate: " + v.currentTime);
+
+  // Rest event counters for we don't allow events after ended.
+  eventsToLog.forEach(function(e) {
+    v.counter[e] = 0;
+  });
+
   // Finish the test after 500ms. We shouldn't receive any timeupdate events
   // after the ended event, so this gives time for any pending timeupdate events
   // to fire so we can ensure we don't regress behaviour.
   setTimeout(
     function() {
       // Remove the event listeners before removing the video from the document.
       // We should receive a timeupdate and pause event when we remove the element
       // from the document (as the element is specified to behave as if pause() was
       // invoked when it's removed from a document), and we don't want those
       // confusing the test results.
       v.removeEventListener("ended", ended, false);
-      v.removeEventListener("timeupdate", timeupdate, false);
-      for (var i = 0; i < eventsToLog.length; ++i) {
-        v.removeEventListener(eventsToLog[i], logEvent, false);
-      }
+      eventsToLog.forEach(function(e) {
+        v.removeEventListener(e, logEvent, false);
+      });
       removeNodeAndSource(v);
       manager.finished(v.token);
     },
     500);
 }
 
 var eventsToLog = ["play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
-  "loadeddata", "playing", "progress", "timeupdate", "ended", "suspend", "error", "stalled", "emptied", "abort",
+  "loadeddata", "playing", "timeupdate", "error", "stalled", "emptied", "abort",
   "waiting", "pause"];
+
 function logEvent(event) {
-  if (event.target.gotEnded > (event.type == "ended" ? 1 : 0)) {
-    if (event.target.currentSrc.slice(-9) == "seek.webm" && event.type == "stalled") {
-      todo(false, event.target.currentSrc + " got unexpected stalled after ended (bug 760770)");
-    } else {
-      ok(false, event.target.currentSrc + " got unexpected " + event.type + " after ended");
-    }
-  } else {
-    info(event.target.currentSrc + " got " + event.type);
+  var v = event.target;
+  ++v.counter[event.type];
+  if (v.counter["ended"] > 0) {
+    is(v.counter[event.type], 0, v._name + " got unexpected " + event.type + " after ended");
   }
 }
 
 function startTest(test, token) {
   var type = getMajorMimeType(test.type);
   var v = document.createElement(type);
   v.token = token;
   manager.started(token);
   v.src = test.name;
   v._name = test.name;
-  v._timeupdateCount = 0;
-  v._finished = false;
-  v.gotEnded = 0;
+
+  // Keep how many events received for each event type.
+  v.counter = {};
+  eventsToLog.forEach(function(e) {
+    v.addEventListener(e, logEvent, false);
+    v.counter[e] = 0;
+  });
   v.addEventListener("ended", ended, false);
-  v.addEventListener("timeupdate", timeupdate, false);
-  for (var i = 0; i < eventsToLog.length; ++i) {
-    v.addEventListener(eventsToLog[i], logEvent, false);
-  }
+  v.counter["ended"] = 0;
   document.body.appendChild(v);
   v.play();
 }
 
 manager.runTests(gSmallTests, startTest);
 
 </script>
 </pre>