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
--- 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);
});
});