Bug 1340037 - per comment 11, we need to wait for all initData are processed before finishing the test to avoid "Result logged after SimpleTest.finish()". draft
authorJW Wang <jwwang@mozilla.com>
Wed, 19 Apr 2017 10:52:23 +0800
changeset 564854 22020f98cba3404e6d724aa31e8b723564718ee6
parent 564853 798299202d6422eee468dd7628cbb09a5d0d495b
child 624837 5507bd2231e34487e11998de9007e0f3148f4bc4
push id54700
push userjwwang@mozilla.com
push dateWed, 19 Apr 2017 02:53:26 +0000
bugs1340037
milestone55.0a1
Bug 1340037 - per comment 11, we need to wait for all initData are processed before finishing the test to avoid "Result logged after SimpleTest.finish()". 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();