Bug 1041363 - remove tricky timers to make tests more stable. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Fri, 03 Oct 2014 00:34:00 +0200
changeset 208916 de956d0e0c46c4c1eec29be075c7f4d55d2e7d7d
parent 208915 347f87932c7710393de237caf627fb56f6759040
child 208917 b00ca413f85b32ef54a71063ddbf7ba3496f7a34
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerscpearce
bugs1041363
milestone35.0a1
Bug 1041363 - remove tricky timers to make tests more stable. r=cpearce
content/media/test/test_preload_actions.html
--- a/content/media/test/test_preload_actions.html
+++ b/content/media/test/test_preload_actions.html
@@ -535,38 +535,46 @@ var tests = [
       v.play(); // Should cause preload:none to be overridden.
     },
 
     name: "test18",
   },
   {
     // 19. Set preload='auto' on first video source then switching preload='none' and swapping the video source to another.
     // The second video should not start playing as it's preload state has been changed to 'none' from 'auto'
-    loadedmetadata: function(e) {
-      var v = e.target;
-      is(v.preload === "auto", true, "(19) preload is initially auto");
-      setTimeout(function() {
+    setup:
+    function(v) {
+      v.preload = "auto";
+      v.src = test.name;
+      // add a listener for when the video has loaded, so we know preload auto has worked
+      v.onloadedmetadata = function() {
+        is(v.preload, "auto", "(19) preload is initially auto");
         // set preload state to none and switch video sources
         v.preload="none";
         v.src = test.name + "?asdf";
-        setTimeout(function() {
-          is(v.readyState === 0, true, "(19) no buffering has taken place");
-          maybeFinish(v, 19);
-        }, 2000);
-      }, 2000);
 
-    },
+        v.onloadedmetadata = function() {
+          ok(false, "(19) 'loadedmetadata' shouldn't fire when preload is none");
+        }
 
-    setup:
-    function(v) {
-      var that = this;
-      v.preload = "auto";
-      v.src = test.name;
-      // add a listener for when the video has loaded, so we know preload auto has worked
-      v.addEventListener( "loadedmetadata", this.loadedmetadata, false);
+        var ontimeout = function() {
+          v.removeEventListener("suspend", onsuspend, false);
+          ok(false, "(19) 'suspend' should've fired");
+          maybeFinish(v, 19);
+        }
+        var cancel = setTimeout(ontimeout, 10000);
+
+        var onsuspend = function() {
+          v.removeEventListener("suspend", onsuspend, false);
+          clearTimeout(cancel);
+          is(v.readyState, 0, "(19) no buffering has taken place");
+          maybeFinish(v, 19);
+        }
+        v.addEventListener("suspend", onsuspend, false);
+      }
       document.body.appendChild(v);
     },
 
     name: "test19",
   }
 ];
 
 var iterationCount = 0;