Bug 1289742. P3 - use the 'once' handler. r=kaku
authorJW Wang <jwwang@mozilla.com>
Mon, 06 Mar 2017 15:03:39 +0800
changeset 494337 34ad60160536daa711cd574721a03538cd699d76
parent 494336 f5c0df74ee7357ac251a9403f3da7e0465915d45
child 494338 f4ce1268e40b2485e2204c3b99dda432fca78a61
push id48023
push userjwwang@mozilla.com
push dateTue, 07 Mar 2017 02:32:15 +0000
reviewerskaku
bugs1289742
milestone54.0a1
Bug 1289742. P3 - use the 'once' handler. r=kaku MozReview-Commit-ID: LOxpTEUvKID
dom/media/test/test_load_same_resource.html
--- a/dom/media/test/test_load_same_resource.html
+++ b/dom/media/test/test_load_same_resource.html
@@ -18,17 +18,16 @@ function cloneLoaded(event) {
   ok(true, "Clone loaded OK");
   var e = event.target;
 
   if (e._expectedDuration) {
     ok(Math.abs(e.duration - e._expectedDuration) < 0.1,
        "Clone " + e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration);
   }
 
-  e.removeEventListener("loadeddata", cloneLoaded);
   removeNodeAndSource(e);
   manager.finished(e.token);
 }
 
 function tryClone(event) {
   var e = event.target;
   var clone = e.cloneNode(false);
   clone.token = e.token;
@@ -47,30 +46,27 @@ function tryClone(event) {
 
 
   if (e._expectedDuration) {
     ok(Math.abs(e.duration - e._expectedDuration) < 0.1,
        e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration);
     clone._expectedDuration = e._expectedDuration;
   }
 
-  clone.addEventListener("loadeddata", cloneLoaded);
-  clone.onloadstart = function(evt) {
+  clone.addEventListener("loadeddata", cloneLoaded, {once: true});
+  clone.addEventListener("loadstart", function(evt) {
     info("cloned " + evt.target.token + " start loading.");
-    evt.target.onloadstart = null;
     // Since there is only one H264 decoder instance, we have to delete the
     // decoder of the original element for the cloned element to load. However,
     // we can't delete the decoder too early otherwise cloning decoder will
     // fail to kick in. We wait for 'loadstart' event of the cloned element to
     // know when the decoder is already cloned and we can delete the decoder of
     // the original element.
     removeNodeAndSource(e);
-  }
-
-  e.removeEventListener("loadeddata", tryClone);
+  }, {once: true});
 }
 
 // This test checks that loading the same URI twice in different elements at the same time
 // uses the same resource without doing another network fetch. One of the gCloneTests
 // uses dynamic_resource.sjs to return one resource on the first fetch and a different resource
 // on the second fetch. These resources have different lengths, so if the cloned element
 // does a network fetch it will get a resource with the wrong length and we get a test
 // failure.
@@ -79,17 +75,17 @@ function initTest(test, token) {
   var elemType = /^audio/.test(test.type) ? "audio" : "video";
   var e = document.createElement(elemType);
   e.preload = "auto";
   e.src = test.name;
   if (test.duration) {
     e._expectedDuration = test.duration;
   }
   ok(true, "Trying to load " + test.name);
-  e.addEventListener("loadeddata", tryClone);
+  e.addEventListener("loadeddata", tryClone, {once: true});
   e.load();
   e.token = token;
   manager.started(token);
 }
 
 manager.runTests(gCloneTests, initTest);
 
 </script>