From a40c88e159f932877ab336269d091673d369a0f2 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Mon, 4 Sep 2017 13:20:05 +0800 Subject: [PATCH] Bug 1348634 - wait for the 'suspend' event to ensure resource cloning work as expected. r=cpearce MozReview-Commit-ID: BeGGnUfFDcN --HG-- extra : rebase_source : bd8192f09cd088a430437f34674d579859d0194a --- dom/media/test/test_load_same_resource.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dom/media/test/test_load_same_resource.html b/dom/media/test/test_load_same_resource.html index b20abd4d15a2..bdb2881edd0a 100644 --- a/dom/media/test/test_load_same_resource.html +++ b/dom/media/test/test_load_same_resource.html @@ -27,8 +27,7 @@ function cloneLoaded(event) { 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); @@ -70,15 +69,26 @@ function tryClone(event) { // 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();