Bug 1315723 - Resolve the timeout problem of the browser_cache.js. r=baku, a=test-only
authorTim Huang <tihuang@mozilla.com>
Tue, 22 Nov 2016 14:57:19 +0800
changeset 349223 de0e24173bdba9cde20adfce848333ffa2efd6e0
parent 349222 3dba6bf0b663a6ba2a3b79d74ab193e2d8c96a81
child 349224 207271d653e47b11aff98e58c5a7fef64b28da9a
push id10337
push userryanvm@gmail.com
push dateWed, 23 Nov 2016 23:06:54 +0000
treeherdermozilla-aurora@116d83d90ce4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, test-only
bugs1315723
milestone52.0a2
Bug 1315723 - Resolve the timeout problem of the browser_cache.js. r=baku, a=test-only
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.