Bug 1315723 - Resolve the timeout problem of the browser_cache.js. r?baku
--- a/browser/components/originattributes/test/browser/browser_cache.js
+++ b/browser/components/originattributes/test/browser/browser_cache.js
@@ -152,22 +152,16 @@ function* doTest(aBrowser) {
let URLSuffix = "?r=" + arg.randomSuffix;
// Create the audio and video elements.
let audio = content.document.createElement('audio');
let video = content.document.createElement('video');
let audioSource = content.document.createElement('source');
let audioTrack = content.document.createElement('track');
- // Assign attributes for the audio element.
- audioSource.setAttribute("src", audioURL + URLSuffix);
- audioSource.setAttribute("type", "audio/ogg");
- audioTrack.setAttribute("src", trackURL);
- audioTrack.setAttribute("kind", "subtitles");
-
// Append the audio and track element into the body, and wait until they're finished.
yield new Promise(resolve => {
let audioLoaded = false;
let trackLoaded = false;
let audioListener = () => {
audio.removeEventListener("canplaythrough", audioListener);
@@ -181,37 +175,47 @@ function* doTest(aBrowser) {
audioTrack.removeEventListener("load", trackListener);
trackLoaded = true;
if (audioLoaded && trackLoaded) {
resolve();
}
};
+ // Add the event listeners before everything in case we lose events.
+ audioTrack.addEventListener("load", trackListener, false);
+ audio.addEventListener("canplaythrough", audioListener, false);
+
+ // 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);
audio.appendChild(audioTrack);
audio.autoplay = true;
- audioTrack.addEventListener("load", trackListener, false);
- audio.addEventListener("canplaythrough", audioListener, false);
content.document.body.appendChild(audio);
});
// Append the video element into the body, and wait until it's finished.
yield new Promise(resolve => {
let listener = () => {
video.removeEventListener("canplaythrough", listener);
resolve();
};
+ // Add the event listener before everything in case we lose the event.
+ video.addEventListener("canplaythrough", listener, false);
+
// Assign attributes for the video element.
video.setAttribute("src", videoURL + URLSuffix);
video.setAttribute("type", "video/ogg");
- video.addEventListener("canplaythrough", listener, false);
content.document.body.appendChild(video);
});
});
return 0;
}
// The check function, which checks the number of cache entries.