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 232760 5dd50b10a400989645605900aad478ba6a64f827
parent 232759 e5883dd2d69e2b9fdb9c8a6dc1b9354c201edae4
child 232761 dbd9a3b1ba7084ad1bbd0ba6583f541667cc3a72
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs668973
milestone35.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 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);