Bug 1315723 - Resolve the timeout problem of the browser_cache.js. r?baku draft
authorTim Huang <tihuang@mozilla.com>
Tue, 22 Nov 2016 14:57:19 +0800
changeset 442314 cb548510ab3b46cccd1b61e051059ae42ec39eaf
parent 442068 0534254e9a40b4bade2577c631fe4cfa0b5db41d
child 537774 7cc93fd7d9165f186a5519428a2e7b7485ddfa8a
push id36675
push userbmo:tihuang@mozilla.com
push dateTue, 22 Nov 2016 09:44:51 +0000
reviewersbaku
bugs1315723
milestone53.0a1
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.