Bug 668973 - Part2 - make timeout reason obvious for easier debugging. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Tue, 07 Oct 2014 19:57:00 +0200
changeset 209545 5dd50b10a400989645605900aad478ba6a64f827
parent 209544 e5883dd2d69e2b9fdb9c8a6dc1b9354c201edae4
child 209546 dbd9a3b1ba7084ad1bbd0ba6583f541667cc3a72
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerscpearce
bugs668973
milestone35.0a1
Bug 668973 - Part2 - make timeout reason obvious for easier debugging. r=cpearce
content/media/test/test_playback.html
--- a/content/media/test/test_playback.html
+++ b/content/media/test/test_playback.html
@@ -31,52 +31,84 @@ function startTest(test, token) {
     is(test.name, v.name, test.name + ": Name should match #1");
     checkMetadata(test.name, v, test);
   }}(test, v);
 
   var noLoad = function(test, v) { return function() {
     ok(false, test.name + " should not fire 'load' event");
   }}(test, v);
 
+  // Used to cancel timer callback.
+  var timer = null;
+
+  var cancelTimer = function() {
+    if (timer) {
+      clearTimeout(timer);
+    }
+  }
+
+  var finish = function() {
+    cancelTimer();
+    v.finished = true;
+    v.removeEventListener("timeupdate", timeUpdate, false);
+    removeNodeAndSource(v);
+    manager.finished(v.token);
+  }
+
+  // We should get "ended" and "suspend" events to finish the test.
+  var mayFinish = function() {
+    if (v.seenEnded && v.seenSuspend) {
+      finish();
+    }
+  }
+
+  var onTimeout = function() {
+    ok(v.seenEnded, v.name + " timed out, should get 'ended'");
+    ok(v.seenSuspend, v.name + " timed out, should get 'suspend'");
+    finish();
+  }
+
+  // Check if we time out in waiting for some events.
+  var registerTimer = function() {
+    cancelTimer();
+    timer = setTimeout(onTimeout, 30000);
+  }
+
   var checkEnded = function(test, v) { return function() {
+    is(test.name, v.name, test.name + ": Name should match #2");
     checkMetadata(test.name, v, test);
-    is(test.name, v.name, test.name + ": Name should match #2");
     is(v.readyState, v.HAVE_CURRENT_DATA, test.name + " checking readyState");
     ok(v.readyState != v.NETWORK_LOADED, test.name + " shouldn't report NETWORK_LOADED");
     ok(v.ended, test.name + " checking playback has ended");
-    if (v.ended && v.seenSuspend && !v.finished) {
-      v.finished = true;
-      v.removeEventListener("timeupdate", timeUpdate, false);
-      removeNodeAndSource(v);
-      manager.finished(v.token);
-    }
+    ok(!v.finished, test.name + " shouldn't be finished");
+    ok(!v.seenEnded, test.name + " shouldn't be ended");
+
+    v.seenEnded = true;
+    registerTimer();
+    mayFinish();
   }}(test, v);
 
   var checkSuspended = function(test, v) { return function() {
-    is(test.name, v.name, test.name + ": Name should match #3");
     if (v.seenSuspend) {
       return;
     }
+    is(test.name, v.name, test.name + ": Name should match #3");
 
     v.seenSuspend = true;
-    ok(true, test.name + " got suspend");
-    if (v.ended && !v.finished) {
-      v.finished = true;
-      v.removeEventListener("timeupdate", timeUpdate, false);
-      removeNodeAndSource(v);
-      manager.finished(v.token);
-    }
+    registerTimer();
+    mayFinish();
   }}(test, v);
 
   var timeUpdate = function(test, v) { return function() {
     if (v.prevTime > v.currentTime) {
       ok(false, test.name + " time should run forwards: p=" +
                 v.prevTime + " c=" + v.currentTime);
     }
     v.prevTime = v.currentTime;
+    registerTimer();
   }}(test, v);
 
   v.addEventListener("load", noLoad, false);
   v.addEventListener("loadedmetadata", check, false);
   v.addEventListener("timeupdate", timeUpdate, false);
 
   // We should get "ended" and "suspend" events for every resource
   v.addEventListener("ended", checkEnded, false);