Bug 1315723 - Resolve the timeout problem of the browser_cache.js. r=baku
authorTim Huang <tihuang@mozilla.com>
Tue, 22 Nov 2016 14:57:19 +0800
changeset 368761 2824acfb199277acc6e130ab66a07801c8aa10ca
parent 368760 c3452e927deffea3a506d046a2e7998128b961dd
child 368762 875479c06e72908802af7fcec654eceb3012d468
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1315723
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1315723 - Resolve the timeout problem of the browser_cache.js. r=baku
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
@@ -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.