Bug 1422657. P3 - listen to 'suspend' instead of 'canplaythrough'. draft
authorJW Wang <jwwang@mozilla.com>
Wed, 06 Dec 2017 15:04:57 +0800
changeset 708103 be9ecb4cc04b21665d8d25bdd44c25a06f26aa6d
parent 708102 2b9abaa1a22b78cadbbdbf99d1c778fe82f84eac
child 708105 b95036f19423023f38f6e69486e921a66811fa27
push id92285
push userjwwang@mozilla.com
push dateWed, 06 Dec 2017 07:14:46 +0000
bugs1422657
milestone59.0a1
Bug 1422657. P3 - listen to 'suspend' instead of 'canplaythrough'. See comment 12. There is no guarantee 'canplaythrough' will always fire when download is slow. It should listen to 'suspend' which is fired when download is stopped. MozReview-Commit-ID: GFUtjBpsAcT
browser/components/originattributes/test/browser/browser_cache.js
--- a/browser/components/originattributes/test/browser/browser_cache.js
+++ b/browser/components/originattributes/test/browser/browser_cache.js
@@ -156,17 +156,17 @@ async function doTest(aBrowser) {
     let audioTrack = content.document.createElement("track");
 
     // Append the audio and track element into the body, and wait until they're finished.
     await new Promise(resolve => {
       let audioLoaded = false;
       let trackLoaded = false;
 
       let audioListener = () => {
-        audio.removeEventListener("canplaythrough", audioListener);
+        audio.removeEventListener("suspend", audioListener);
 
         audioLoaded = true;
         if (audioLoaded && trackLoaded) {
           resolve();
         }
       };
 
       let trackListener = () => {
@@ -175,17 +175,17 @@ async function doTest(aBrowser) {
         trackLoaded = true;
         if (audioLoaded && trackLoaded) {
           resolve();
         }
       };
 
       // Add the event listeners before everything in case we lose events.
       audioTrack.addEventListener("load", trackListener);
-      audio.addEventListener("canplaythrough", audioListener);
+      audio.addEventListener("suspend", audioListener);
 
       // Assign attributes for the audio element.
       audioSource.setAttribute("src", audioURL + URLSuffix);
       audioSource.setAttribute("type", "audio/ogg");
       audioTrack.setAttribute("src", trackURL);
       audioTrack.setAttribute("kind", "subtitles");
 
       audio.appendChild(audioSource);
@@ -193,22 +193,22 @@ async function doTest(aBrowser) {
       audio.autoplay = true;
 
       content.document.body.appendChild(audio);
     });
 
     // Append the video element into the body, and wait until it's finished.
     await new Promise(resolve => {
       let listener = () => {
-        video.removeEventListener("canplaythrough", listener);
+        video.removeEventListener("suspend", listener);
         resolve();
       };
 
       // Add the event listener before everything in case we lose the event.
-      video.addEventListener("canplaythrough", listener);
+      video.addEventListener("suspend", listener);
 
       // Assign attributes for the video element.
       video.setAttribute("src", videoURL + URLSuffix);
       video.setAttribute("type", "video/ogg");
 
       content.document.body.appendChild(video);
     });
   });