Bug 1359725 - add timeout to LoadInitData() in eme.js. r=gerald
authorJW Wang <jwwang@mozilla.com>
Wed, 26 Apr 2017 16:22:08 +0800
changeset 569321 9aeb165cda5b6926145f83de39061dc67ad32974
parent 569320 795609f3011cada963276dba07fa5f341242cab7
child 569322 35c773084736edd72090a2afac358a499ec20b38
push id56143
push userbmo:jeremychen@mozilla.com
push dateThu, 27 Apr 2017 10:17:21 +0000
reviewersgerald
bugs1359725
milestone55.0a1
Bug 1359725 - add timeout to LoadInitData() in eme.js. r=gerald So we can cancel the bad test as soon as possible and give a better description about the error. MozReview-Commit-ID: ExKIK2HqJkN
dom/media/test/eme.js
--- a/dom/media/test/eme.js
+++ b/dom/media/test/eme.js
@@ -315,22 +315,28 @@ function CreateAndSetMediaKeys(v, test, 
  * Collect the init data from 'encrypted' events.
  * Return a promise which will be resolved with the init data when collection
  * is completed (specified by test.sessionCount).
  */
 function LoadInitData(v, test, token) {
   let p = new EMEPromise;
   let initDataQueue = [];
 
+  // Call SimpleTest._originalSetTimeout() to bypass the flaky timeout checker.
+  let timer = SimpleTest._originalSetTimeout.call(window, () => {
+    p.reject(`${token} Timed out in waiting for the init data.`);
+  }, 60000);
+
   function onencrypted(ev) {
     initDataQueue.push(ev);
     Log(token, `got encrypted(${ev.initDataType}, ` +
         `${StringToHex(ArrayBufferToString(ev.initData))}) event.`);
     if (test.sessionCount == initDataQueue.length) {
       p.resolve(initDataQueue);
+      clearTimeout(timer);
     }
   }
 
   v.addEventListener("encrypted", onencrypted);
   return p.promise;
 }
 
 /*