Bug 1348634 - wait for the 'suspend' event to ensure resource cloning work as expected. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Mon, 04 Sep 2017 13:20:05 +0800
changeset 378834 a7e16582c59b49efddc4b197637541fbb5317fc6
parent 378833 b58e786853341e5b280d6c0212bde732f447681d
child 378835 dcfd73044bbabcfd43d767282a111c3d2cd45863
push id50399
push userjwwang@mozilla.com
push dateTue, 05 Sep 2017 02:23:13 +0000
treeherderautoland@a7e16582c59b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1348634
milestone57.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 1348634 - wait for the 'suspend' event to ensure resource cloning work as expected. r=cpearce MozReview-Commit-ID: BeGGnUfFDcN
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
@@ -22,18 +22,17 @@ function checkDuration(actual, expected,
 function cloneLoaded(event) {
   var e = event.target;
   ok(true, `${e.token} loaded OK`);
   checkDuration(e.duration, e._expectedDuration, e.token);
   removeNodeAndSource(e);
   manager.finished(e.token);
 }
 
-function tryClone(event) {
-  var e = event.target;
+function tryClone(e) {
   var clone = e.cloneNode(false);
   clone.token = `${e.token}(cloned)`;
   manager.started(clone.token);
   manager.finished(e.token);
 
   // Log events for debugging.
   var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
                 "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
@@ -65,25 +64,36 @@ function tryClone(event) {
 
 // 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.
 
-function initTest(test, token) {
+async function initTest(test, token) {
   var e = document.createElement("video");
   e.preload = "auto";
   e.src = test.name;
   e._expectedDuration = test.duration;
   ok(true, `Trying to load ${test.name}, duration=${test.duration}`);
-  e.addEventListener("loadeddata", tryClone, {once: true});
   e.token = token;
   manager.started(token);
+
+  // Since 320x240.ogv is less than 32KB, we need to wait for the
+  // 'suspend' event to ensure the partial block is flushed to the cache
+  // otherwise the cloned resource will create a new channel when it
+  // has no data to read at position 0. The new channel will download
+  // a different file than the original resource and fail the duration
+  // test.
+  let p1 = once(e, "loadeddata");
+  let p2 = once(e, "suspend");
+  await p1;
+  await p2;
+  tryClone(e);
 }
 
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPrefEnv(
   {"set": [
     ["logging.MediaDecoder", "Debug"],
     ["logging.nsMediaElement", "Debug"],
     ["logging.MediaCache", "Debug"],