Bug 1348634 - Wait for the 'suspend' event to ensure resource cloning work as expected. r=cpearce, a=test-only
authorJW Wang <jwwang@mozilla.com>
Mon, 04 Sep 2017 13:20:05 +0800
changeset 421555 1a0a1ec5c58f6c6aee9b4692810f314fe26b9cfb
parent 421554 6dd7c570d4807f6b279e859c90dc033f68b1e2fd
child 421556 8bdd1bbd948f52e7b5f3ab2c1168fece0ee14377
push id7717
push userryanvm@gmail.com
push dateTue, 05 Sep 2017 22:40:57 +0000
treeherdermozilla-beta@e0216397b51a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, test-only
Bug 1348634 - Wait for the 'suspend' event to ensure resource cloning work as expected. r=cpearce, a=test-only MozReview-Commit-ID: BeGGnUfFDcN
--- 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);
-function tryClone(event) {
-  var e = event.target;
+function tryClone(e) {
   var clone = e.cloneNode(false);
   clone.token = `${e.token}(cloned)`;
   // 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;
+  // 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);
   {"set": [
     ["logging.MediaDecoder", "Debug"],
     ["logging.nsMediaElement", "Debug"],
     ["logging.MediaCache", "Debug"],