Bug 1340037 - Wait for all initData are processed before finishing the test to avoid "Result logged after SimpleTest.finish()". r=gerald, a=test-only
authorJW Wang <jwwang@mozilla.com>
Wed, 19 Apr 2017 10:52:23 +0800
changeset 393674 ec47fae0f90fe411d9fd5dcd1a5c80f80bad0b8c
parent 393673 ee39b53a33c0f1c908f4dc0499d71420d1a40974
child 393675 8d9384a3168f980d2f22d81bd12085c29111aa67
push id7229
push userryanvm@gmail.com
push dateMon, 24 Apr 2017 19:35:24 +0000
treeherdermozilla-beta@a236801aa022 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, test-only
bugs1340037
milestone54.0
Bug 1340037 - Wait for all initData are processed before finishing the test to avoid "Result logged after SimpleTest.finish()". r=gerald, a=test-only Note this patch doesn't fix the crash in comment 10 which seems to be related to ChromiumCDMParent. MozReview-Commit-ID: CcCPYJCZ39X
dom/media/test/eme.js
dom/media/test/test_eme_canvas_blocked.html
--- a/dom/media/test/eme.js
+++ b/dom/media/test/eme.js
@@ -332,20 +332,29 @@ function SetupEME(test, token, params)
     initDataQueue.push(ev);
     if (params && params.onInitDataQueued) {
       params.onInitDataQueued(ev, ev.initDataType, StringToHex(ArrayBufferToString(ev.initData)));
     }
   }
 
   function processInitDataQueue()
   {
-    if (initDataQueue === null) { return; }
+    function maybeResolveInitDataPromise() {
+      if (params && params.initDataPromise) {
+        params.initDataPromise.resolve();
+      }
+    }
+    if (initDataQueue === null) {
+      maybeResolveInitDataPromise();
+      return;
+    }
     // If we're processed all our init data null the queue to indicate encrypted event handled.
     if (initDataQueue.length === 0) {
       initDataQueue = null;
+      maybeResolveInitDataPromise();
       return;
     }
     var ev = initDataQueue.shift();
 
     var sessionType = (params && params.sessionType) ? params.sessionType : "temporary";
     Log(token, "createSession(" + sessionType + ") for (" + ev.initDataType + ", " + StringToHex(ArrayBufferToString(ev.initData)) + ")");
     var session = v.mediaKeys.createSession(sessionType);
     if (params && params.onsessioncreated) {
--- a/dom/media/test/test_eme_canvas_blocked.html
+++ b/dom/media/test/test_eme_canvas_blocked.html
@@ -12,18 +12,20 @@
 <script class="testbody" type="text/javascript">
 var manager = new MediaTestManager;
 
 function startTest(test, token)
 {
   manager.started(token);
 
   var sessions = [];
+  // Will be resolved when all initData are processed.
+  let initDataPromise = new EMEPromise;
 
-  var v = SetupEME(test, token);
+  var v = SetupEME(test, token, { initDataPromise: initDataPromise });
   v.preload = "auto"; // Required due to "canplay" not firing for MSE unless we do this.
 
   var p1 = new EMEPromise;
   v.addEventListener("loadeddata", function(ev) {
     var video = ev.target;
     var canvas = document.createElement("canvas");
     canvas.width = video.videoWidth;
     canvas.height = video.videoHeight;
@@ -35,17 +37,17 @@ function startTest(test, token)
     } catch (ex) {
       threwError = true;
     }
     ok(threwError, TimeStamp(token) + " - Should throw an error when trying to draw EME video to canvas.");
     p1.resolve();
   });
 
   var p2 = LoadTest(test, v, token, { onlyLoadFirstFragments:2, noEndOfStream:false });
-  EMEPromiseAll(v, token, [p1.promise, p2]);
+  EMEPromiseAll(v, token, [p1.promise, p2, initDataPromise.promise]);
 }
 
 function beginTest() {
   manager.runTests(gEMETests, startTest);
 }
 
 if (!IsMacOSSnowLeopardOrEarlier()) {
   SimpleTest.waitForExplicitFinish();