Bug 1041363 - remove tricky timers to make tests more stable. r=cpearce
--- 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;