Backed out changeset 2b82a84104ae (bug 1148179)
authorWes Kocher <wkocher@mozilla.com>
Fri, 03 Apr 2015 13:09:36 -0700
changeset 237580 3ec4c24bfd480d2103fcb4eb880f00c1ec0750cf
parent 237579 ea7dabcd215ec8a379c53f35e75e1e18bc8389d7
child 237581 5a48da87b7e0f94d4d80a01fe108a277039562aa
push id28540
push userphilringnalda@gmail.com
push dateSat, 04 Apr 2015 17:42:19 +0000
treeherdermozilla-central@035959eef3f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1148179
milestone40.0a1
backs out2b82a84104ae352f5b267bac07bf4fccae5f7a72
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 2b82a84104ae (bug 1148179)
dom/media/test/eme.js
dom/media/test/mochitest.ini
dom/media/test/test_eme_canvas_blocked.html
dom/media/test/test_eme_non_mse_fails.html
dom/media/test/test_eme_obs_notification.html
dom/media/test/test_eme_persistent_sessions.html
dom/media/test/test_eme_playback.html
dom/media/test/test_eme_playback_init_then_keys_then_data.html
dom/media/test/test_eme_stream_capture_blocked.html
--- a/dom/media/test/eme.js
+++ b/dom/media/test/eme.js
@@ -68,65 +68,51 @@ function TimeStamp(token) {
              (ms < 10 ? "  " : (ms < 100 ? " " : ""));
   return token ? (time + " " + token) : time;
 }
 
 function Log(token, msg) {
   info(TimeStamp(token) + " " + msg);
 }
 
-function MediaErrorCodeToString(code)
-{
-  switch (code) {
-  case MediaError.MEDIA_ERROR_ABORTED         : return "MEDIA_ERROR_ABORTED";
-  case MediaError.MEDIA_ERR_NETWORK           : return "MEDIA_ERR_NETWORK";
-  case MediaError.MEDIA_ERR_DECODE            : return "MEDIA_ERR_DECODE";
-  case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED : return "MEDIA_ERR_SRC_NOT_SUPPORTED";
-  default: return String(code);
-  }
-}
-
 function TimeRangesToString(trs)
 {
   var l = trs.length;
   if (l === 0) { return "-"; }
   var s = "";
   var i = 0;
   for (;;) {
     s += trs.start(i) + "-" + trs.end(i);
     if (++i === l) { return s; }
     s += ",";
   }
 }
 
 function SourceBufferToString(sb)
 {
-  if (!sb) {
-    return "?";
-  }
   return ("SourceBuffer{"
-          + (sb
-             ? ((sb.updating ? " updating," : "")
-                + " buffered="
-                + (sb.buffered ? TimeRangesToString(sb.buffered) : "?"))
-             : " ?")
-          + " }");
+    + "AppendMode=" + (sb.AppendMode || "-")
+    + ", updating=" + (sb.updating ? "true" : "false")
+    + ", buffered=" + TimeRangesToString(sb.buffered)
+    + ", audioTracks=" + (sb.audioTracks ? sb.audioTracks.length : "-")
+    + ", videoTracks=" + (sb.videoTracks ? sb.videoTracks.length : "-")
+    + "}");
 }
 
 function SourceBufferListToString(sbl)
 {
   return "SourceBufferList[" + sbl.map(SourceBufferToString).join(", ") + "]";
 }
 
 function UpdateSessionFunc(test, token, sessionType, resolve, reject) {
   return function(ev) {
     var msgStr = ArrayBufferToString(ev.message);
     var msg = JSON.parse(msgStr);
 
-    Log(token, "Session[" + ev.target.sessionId + "], got message from CDM: " + msgStr);
+    Log(token, "got message from CDM: " + msgStr);
     is(msg.type, sessionType, TimeStamp(token) + " key session type should match");
     ok(msg.kids, TimeStamp(token) + " message event should contain key ID array");
 
     var outKeys = [];
 
     for (var i = 0; i < msg.kids.length; i++) {
       var id64 = msg.kids[i];
       var idHex = Base64ToHex(msg.kids[i]).toLowerCase();
@@ -144,23 +130,23 @@ function UpdateSessionFunc(test, token, 
         bail(token + " couldn't find key for key id " + idHex);
       }
     }
 
     var update = JSON.stringify({
       "keys" : outKeys,
       "type" : msg.type
     });
-    Log(token, "Session[" + ev.target.sessionId + "], sending update message to CDM: " + update);
+    Log(token, "sending update message to CDM: " + update);
 
     ev.target.update(StringToArrayBuffer(update)).then(function() {
-      Log(token, "Session[" + ev.target.sessionId + "] update ok!");
+      Log(token, "MediaKeySession update ok!");
       resolve(ev.target);
     }).catch(function(reason) {
-      bail(token + " Session[" + ev.target.sessionId + "] update failed")(reason);
+      bail(token + " MediaKeySession update failed")(reason);
       reject();
     });
   }
 }
 
 function MaybeCrossOriginURI(test, uri)
 {
   if (test.crossOrigin) {
@@ -173,155 +159,98 @@ function MaybeCrossOriginURI(test, uri)
 function AppendTrack(test, ms, track, token)
 {
   return new Promise(function(resolve, reject) {
     var sb;
     var curFragment = 0;
     var resolved = false;
     var fragmentFile;
 
-    var appendBufferTimer = false;
-
-    var addNextFragment = function() {
+    function addNextFragment() {
       if (curFragment >= track.fragments.length) {
         Log(token, track.name + ": end of track");
+        resolve();
         resolved = true;
-        sb.removeEventListener("updateend", handleUpdateEnd);
-        resolve();
         return;
       }
 
       fragmentFile = MaybeCrossOriginURI(test, track.fragments[curFragment++]);
 
       var req = new XMLHttpRequest();
       req.open("GET", fragmentFile);
       req.responseType = "arraybuffer";
-      req.timeout = 10 * 1000; // 10s should be plenty of time to get small fragments!
 
       req.addEventListener("load", function() {
         Log(token, track.name + ": fetch of " + fragmentFile + " complete, appending");
-        appendBufferTimer = setTimeout(function () {
-          reject("Timeout appendBuffer with fragment '" + fragmentFile + "'");
-        }, 10 * 1000);
         sb.appendBuffer(new Uint8Array(req.response));
       });
 
-      ["error", "abort", "timeout"
-      ].forEach(function(issue) {
-        req.addEventListener(issue, function() {
-          info(token + " " + issue + " fetching " + fragmentFile + ", status='" + req.statusText + "'");
-          resolved = true;
-          reject(issue + " fetching " + fragmentFile);
-        });
-      });
+      req.addEventListener("error", function(){info(token + " error fetching " + fragmentFile);});
+      req.addEventListener("abort", function(){info(token + " aborted fetching " + fragmentFile);});
 
       Log(token, track.name + ": addNextFragment() fetching next fragment " + fragmentFile);
       req.send(null);
     }
 
-    if (!ms._test_sourceBuffers || !ms._test_sourceBuffers[track.name]) {
-      Log(token, track.name + ": addSourceBuffer(" + track.type + ")");
-      sb = ms.addSourceBuffer(track.type);
-      ms._test_sourceBuffers[track.name] = sb;
-    } else {
-      Log(token, track.name + ": reusing SourceBuffer(" + track.type + ")");
-      sb = ms._test_sourceBuffers[track.name];
-    }
-
-    var handleUpdateEnd = function() {
-      if (appendBufferTimer) { clearTimeout(appendBufferTimer); appendBufferTimer = false; }
+    Log(token, track.name + ": addSourceBuffer(" + track.type + ")");
+    sb = ms.addSourceBuffer(track.type);
+    sb.addEventListener("updateend", function() {
       if (ms.readyState == "ended") {
         /* We can get another updateevent as a result of calling ms.endOfStream() if
            the highest end time of our source buffers is different from that of the
            media source duration. Due to bug 1065207 this can happen because of
            inaccuracies in the frame duration calculations. Check if we are already
            "ended" and ignore the update event */
         Log(token, track.name + ": updateend when readyState already 'ended'");
         if (!resolved) {
           // Needed if decoder knows this was the last fragment and ended by itself.
           Log(token, track.name + ": but promise not resolved yet -> end of track");
+          resolve();
           resolved = true;
-          sb.removeEventListener("updateend", handleUpdateEnd);
-          resolve();
         }
         return;
       }
       Log(token, track.name + ": updateend for " + fragmentFile + ", " + SourceBufferToString(sb));
       addNextFragment();
-    }
-
-    sb.addEventListener("updateend", handleUpdateEnd);
+    });
 
     addNextFragment();
   });
 }
 
-var LOAD_TEST_ALL = 0;
-var LOAD_TEST_INIT = 1;
-var LOAD_TEST_DATA = 2;
-// Returns a promise that is resolved when the media element is ready to have
-// its play() function called; when it's loaded MSE fragments.
-function LoadTest(test, elem, token, loadWhat = LOAD_TEST_ALL)
+//Returns a promise that is resolved when the media element is ready to have
+//its play() function called; when it's loaded MSE fragments.
+function LoadTest(test, elem, token)
 {
   if (!test.tracks) {
     ok(false, token + " test does not have a tracks list");
     return Promise.reject();
   }
 
+  var ms = new MediaSource();
+  elem.src = URL.createObjectURL(ms);
+
   return new Promise(function (resolve, reject) {
-    var ms;
+    var firstOpen = true;
+    ms.addEventListener("sourceopen", function () {
+      if (!firstOpen) {
+        Log(token, "sourceopen again?");
+        return;
+      }
 
-    function AppendTracks() {
+      firstOpen = false;
+      Log(token, "sourceopen");
       return Promise.all(test.tracks.map(function(track) {
-        if (loadWhat === LOAD_TEST_INIT) {
-          track = { name:track.name,
-                    type:track.type,
-                    fragments:track.fragments.filter(x => x.indexOf("init") >= 0) };
-          Log(token, track.name + ": Load init: " + track.fragments);
-        } else if (loadWhat === LOAD_TEST_DATA) {
-          track = { name:track.name,
-                    type:track.type,
-                    fragments:track.fragments.filter(x => x.indexOf("init") < 0) };
-          Log(token, track.name + ": Load data: " + track.fragments);
-        } else {
-          Log(token, track.name + ": Load everything: " + track.fragments);
-        }
         return AppendTrack(test, ms, track, token);
       })).then(function(){
-        if (loadWhat !== LOAD_TEST_INIT) {
-          Log(token, "end of stream");
-          ms.endOfStream();
-        } else {
-          Log(token, "all init segments loaded");
-        }
+        Log(token, "end of stream");
+        ms.endOfStream();
         resolve();
       });
-    }
-
-    if (!elem._test_MediaSource) {
-      Log(token, "Create MediaSource");
-      ms = new MediaSource();
-      ms._test_sourceBuffers = {};
-      elem._test_MediaSource = ms;
-      elem.src = URL.createObjectURL(ms);
-      var firstOpen = true;
-      ms.addEventListener("sourceopen", function() {
-        if (!firstOpen) {
-          Log(token, "sourceopen again?");
-          return;
-        }
-        firstOpen = false;
-        Log(token, "sourceopen");
-        AppendTracks();
-      });
-    } else {
-      Log(token, "Reuse MediaSource");
-      ms = elem._test_MediaSource;
-      AppendTracks();
-    }
+    })
   });
 }
 
 function SetupEME(test, token, params)
 {
   var v = document.createElement("video");
   v.crossOrigin = test.crossOrigin || false;
 
@@ -344,19 +273,16 @@ function SetupEME(test, token, params)
 
   var firstEncrypted = true;
 
   v.addEventListener("encrypted", function(ev) {
     if (!firstEncrypted) {
       // TODO: Better way to handle 'encrypted'?
       //       Maybe wait for metadataloaded and all expected 'encrypted's?
       Log(token, "got encrypted event again, initDataType=" + ev.initDataType);
-      if (params && params.onsessionupdated) {
-        params.onsessionupdated(null);
-      }
       return;
     }
     firstEncrypted = false;
 
     Log(token, "got encrypted event, initDataType=" + ev.initDataType);
     var options = [
       {
         initDataType: ev.initDataType,
@@ -405,406 +331,16 @@ function SetupEME(test, token, params)
           // be resolve in UpdateSessionFunc().
           bail(token + ": session.generateRequest failed")(reason);
           reject();
         });
       });
     })
 
     .then(function(session) {
-      Log(token, "session[" + session.sessionId + "].generateRequest succeeded");
+      Log(token, ": session.generateRequest succeeded");
       if (params && params.onsessionupdated) {
         params.onsessionupdated(session);
       }
     });
   });
   return v;
 }
-
-// Setup an EME test, return the media element.
-function SetupControlledEME(test, token, params)
-{
-  var v = document.createElement("video");
-  v._test_test = test;
-  v._test_token = token;
-  v._test_params = params || {};
-
-  v.crossOrigin = test.crossOrigin || false;
-
-  // Log events dispatched to make debugging easier...
-  [ "canplay", "canplaythrough", "ended", "loadeddata",
-    "loadedmetadata", "loadstart", "pause", "play", "playing", "progress",
-    "stalled", "suspend", "waiting",
-  ].forEach(function (e) {
-    v.addEventListener(e, function(event) {
-      Log(token, "" + e);
-    }, false);
-  });
-  v.addEventListener("error", function(ev) {
-    Log(token, "error: " + MediaErrorCodeToString(ev.target.error.code));
-  }, false);
-
-  return v;
-}
-
-// Return a promise that is resolved when the media element is ready to have
-// its play() function called; i.e., when it's loaded MSE fragments.
-function LoadControlledEME(v)
-{
-  // Resolve promise when 'loadedmetadata' has been received.
-  var promiseLoadedMetadata = new Promise(function (resolve, reject) {
-    function HandleLoadedMetadataAgain(ev)
-    {
-      bail(v._test_token + " Got metadataloaded again!")(ev);
-    }
-    function HandleLoadedMetadata(ev)
-    {
-      v.removeEventListener("loadedmetadata", HandleLoadedMetadata);
-      v.addEventListener("loadedmetadata", HandleLoadedMetadataAgain);
-      resolve(ev);
-    }
-    v.addEventListener("loadedmetadata", HandleLoadedMetadata);
-  });
-
-  // Resolve promise when all 'encrypted' events have been fully handled,
-  // including setting up sessions and updating keys.
-  var promiseEncrypted = new Promise(function (resolve, reject) {
-    var encrypteds = 0;
-    var updated = 0;
-    function HandleEncryptedAgain(ev)
-    {
-      bail(v._test_token + " Got too many 'encrypted' events!")(ev);
-    }
-    function HandleEncrypted(ev)
-    {
-      var sessionType = v._test_test.sessionType || "temporary";
-      PromiseUpdatedSession(v, ev, v._test_test.keys, sessionType)
-      .then(function () {
-        updated += 1;
-        if (updated === v._test_test.sessionCount) {
-          resolve();
-        }
-      });
-      encrypteds += 1;
-      if (encrypteds === v._test_test.sessionCount) {
-        v.removeEventListener("encrypted", HandleEncrypted);
-        v.addEventListener("encrypted", HandleEncryptedAgain);
-      }
-    }
-    v.addEventListener("encrypted", HandleEncrypted);
-  });
-
-  // Prepare MediaSource and SourceBuffers.
-  return Promise.all(v._test_test.tracks.map(function (track) {
-    return PromiseSourceBuffer(v, track.name, track.type);
-  }))
-
-  // Append init fragments for all tracks.
-  .then(function () {
-    Log(v._test_token, "MediaSource and all SourceBuffers ready, load init fragments");
-    return Promise.all(v._test_test.tracks.map(function (track) {
-      var fragments = track.fragments.filter(x => x.indexOf("init") >= 0);
-      return PromiseAppendFragments(v, track.name, fragments, track.type);
-    }));
-  })
-
-  // Wait for loadedmetadata and all up-to-date sessions.
-  .then(function () {
-    Log(v._test_token, "Init fragments loaded, wait for loadedmetadata and all session updates");
-    return Promise.all([promiseLoadedMetadata, promiseEncrypted]);
-  })
-
-  // Append data fragments for all tracks.
-  .then(function () {
-    Log(v._test_token, "All sessions updated, load data fragments");
-    return Promise.all(v._test_test.tracks.map(function (track) {
-      var fragments = track.fragments.filter(x => x.indexOf("init") < 0);
-      return PromiseAppendFragments(v, track.name, fragments, track.type);
-    }));
-  })
-
-  .then(function() {
-    Log(v._test_token, "Fragments loaded, endOfStream");
-    return PromiseEndOfStream(v);
-  })
-}
-
-// Return a promise that resolves into a MediaSource attached to the 'v' element.
-function PromiseMediaSource(v)
-{
-  if (!v._test_mediaSourcePromise) {
-    v._test_mediaSourcePromise = new Promise(function (resolve, reject) {
-      Log(v._test_token, "Create MediaSource");
-      var ms = new MediaSource();
-      v.src = URL.createObjectURL(ms);
-      ms._test_sourceBufferPromises = {};
-      var firstOpen = true;
-      ms.addEventListener("sourceopen", function() {
-        if (!firstOpen) {
-          Log(v._test_token, "sourceopen again?");
-          return;
-        }
-        firstOpen = false;
-        Log(v._test_token, "sourceopen");
-        resolve(ms);
-      });
-    });
-  }
-  return v._test_mediaSourcePromise;
-}
-
-// Return a promise that resolves into a SourceBuffer.
-function PromiseSourceBuffer(v, track, type)
-{
-  return PromiseMediaSource(v)
-  .then(function(ms) {
-    if (!ms._test_sourceBufferPromises[track]) {
-      if (!type) {
-        for (var i in v._test_test.tracks) {
-          if (v._test_test.tracks[i].name === track) {
-            type = v._test_test.tracks[i].type;
-            break;
-          }
-        }
-        if (!type) {
-          return Promise.reject("No type provided for track '" + track + "'");
-        }
-      }
-      ms._test_sourceBufferPromises[track] = new Promise(function(resolve, reject) {
-        Log(v._test_token, track + ": addSourceBuffer(" + type + ")");
-        var sb = ms.addSourceBuffer(type);
-        resolve(sb);
-      });
-    }
-    return ms._test_sourceBufferPromises[track];
-  });
-}
-
-function PromiseXHRGet(v, fragmentFile)
-{
-  return new Promise(function (resolve, reject) {
-    var req = new XMLHttpRequest();
-    req.open("GET", fragmentFile);
-    req.responseType = "arraybuffer";
-    req.timeout = 10 * 1000; // 10s should be plenty of time to get small fragments!
-
-    req.addEventListener("load", function() {
-      if (req.status === 200) {
-        Log(v._test_token, "completed fetching " + fragmentFile + ": " + req.statusText);
-        return resolve(req);
-      } else if (req.status === 206 && v._test_test.crossOrigin) {
-        // When testing CORS, allowed.sjs returns 206.
-        Log(v._test_token, "completed fetching " + fragmentFile + ": " + req.statusText);
-        return resolve(req);
-      } else {
-        Log(v._test_token, "problem fetching " + fragmentFile + ", status='" + req.statusText + "'");
-        return reject(req);
-      }
-    });
-
-    ["error", "abort", "timeout"
-    ].forEach(function(issue) {
-      req.addEventListener(issue, function() {
-        Log(v._test_token, issue + " fetching " + fragmentFile + ", status='" + req.statusText + "'");
-        req.issue = issue;
-        return reject(req);
-      });
-    });
-
-    Log(v._test_token, "Fetching fragment " + fragmentFile);
-    req.send(null);
-  });
-}
-
-// Return a promise that resolves after fragments have been added to a SourceBuffer.
-function PromiseAppendFragments(v, track, fragments, type)
-{
-  return PromiseSourceBuffer(v, track, type)
-  .then(function (sb) {
-    return new Promise(function(resolve, reject) {
-      var curFragment = 0;
-      var fragmentFile;
-
-      var appendBufferTimer = false;
-
-      var addNextFragment = function() {
-        if (curFragment >= fragments.length) {
-          sb.removeEventListener("updateend", handleUpdateEnd);
-          return resolve();
-        }
-
-        fragmentFile = MaybeCrossOriginURI(v._test_test, fragments[curFragment++]);
-
-        PromiseXHRGet(v, fragmentFile)
-        .then(function(req) {
-          Log(v._test_token, track + ": fetch of " + fragmentFile + " complete, appending");
-          appendBufferTimer = setTimeout(function () {
-            reject("Timeout appendBuffer with fragment '" + fragmentFile + "'");
-          }, 10 * 1000);
-          sb.appendBuffer(new Uint8Array(req.response));
-        }, function(req) {
-          if (appendBufferTimer) { clearTimeout(appendBufferTimer); appendBufferTimer = false; }
-          sb.removeEventListener("updateend", handleUpdateEnd);
-          return reject("Cannot load fragment '" + fragmentFile + "'");
-        });
-      }
-
-      var handleUpdateEnd = function() {
-        if (appendBufferTimer) { clearTimeout(appendBufferTimer); appendBufferTimer = false; }
-        Log(v._test_token, track + ": updateend for " + fragmentFile + ", " + SourceBufferToString(sb));
-        addNextFragment();
-      }
-
-      sb.addEventListener("updateend", handleUpdateEnd);
-
-      addNextFragment();
-    });
-  });
-}
-
-function PromiseEndOfStream(v)
-{
-  return PromiseMediaSource(v)
-  .then(function (ms) {
-    Log(v._test_token, "end of stream");
-    ms.endOfStream();
-  });
-}
-
-// Return a promise that resolves into MediaKeys that have been attached to v.
-function PromiseMediaKeys(v, initDataType, videoType, audioType)
-{
-  if (!v._test_mediaKeysPromise) {
-    var createdMediaKeys;
-    v._test_mediaKeysPromise = new Promise(function(resolve, reject) {
-      Log(v._test_token, "Creating MediaKeys - 1. requestMediaKeySystemAccess("
-          + "initDataType=" + initDataType
-          + ", videoType=" + videoType
-          + ", audioType=" + audioType + ")");
-      // TODO: Revisit when bug 1134066 is fixed.
-      var options = [ {
-        initDataType: initDataType,
-        videoType: v._test_test.type,
-        audioType: v._test_test.type,
-      } ];
-      navigator.requestMediaKeySystemAccess(KEYSYSTEM_TYPE, options)
-      .catch(function (reason) {
-        bail(v._test_token + " Failed to request key system access.")(reason);
-        return reject();
-      })
-
-      .then(function(keySystemAccess) {
-        Log(v._test_token, "Creating MediaKeys - 2. createMediaKeys");
-        return keySystemAccess.createMediaKeys();
-      })
-      .catch(function (reason) {
-        bail(v._test_token +  " Failed to create MediaKeys object")(reason);
-        return reject();
-      })
-
-      .then(function(mediaKeys) {
-        Log(v._test_token, "Creating MediaKeys - 3. setMediaKeys on media element");
-        createdMediaKeys = mediaKeys;
-        mediaKeys.sessions = [];
-        return v.setMediaKeys(mediaKeys);
-      })
-      .catch(function (reason) {
-        if (v._test_params && v._test_params.onSetKeysFail) {
-          v._test_params.onSetKeysFail();
-        } else {
-          bail(v._test_token + " Failed to set MediaKeys on <video> element");
-        }
-        return reject();
-      })
-
-      .then(function() {
-        Log(v._test_token, "Creating MediaKeys - 4. Completed");
-        resolve(createdMediaKeys);
-      });
-    });
-  }
-  return v._test_mediaKeysPromise;
-}
-
-// Return a promise when a session has been created and updated with the appropriate keys.
-function PromiseUpdatedSession(v, ev, keys, sessionType)
-{
-  // TODO: Revisit when bug 1134066 is fixed.
-  var videoType = "";
-  var audioType = "";
-  v._test_test.tracks.map(function (track) {
-    if (track.name === "video") { videoType = track.type; }
-    if (track.name === "audio") { audioType = track.type; }
-  });
-
-  return PromiseMediaKeys(v, ev.initDataType, videoType, audioType)
-  .then(function (mk) {
-    sessionType = sessionType || "temporary";
-    var session = mk.createSession(sessionType);
-    Log(v._test_token, "Created session[" + session.sessionId + "] type=" + sessionType);
-
-    session._test_sessionType = sessionType;
-    if (v._test_params && v._test_params.onsessioncreated) {
-      v._test_params.onsessioncreated(session);
-    }
-
-    function UpdateSessionFunc(resolve, reject) {
-      return function(ev) {
-        var msgStr = ArrayBufferToString(ev.message);
-        var msg = JSON.parse(msgStr);
-
-        is(ev.target, session, TimeStamp(v._test_token) + " message target should be previously-created session");
-        Log(v._test_token, "Session[" + session.sessionId + "], got message from CDM: " + msgStr);
-        is(msg.type, session._test_sessionType, TimeStamp(v._test_token) + " key session type should match");
-        ok(msg.kids, TimeStamp(v._test_token) + " message event should contain key ID array");
-
-        var outKeys = [];
-
-        for (var i = 0; i < msg.kids.length; i++) {
-          var id64 = msg.kids[i];
-          var idHex = Base64ToHex(msg.kids[i]).toLowerCase();
-          var key = v._test_test.keys[idHex];
-
-          if (key) {
-            Log(v._test_token, "found key " + key + " for key id " + idHex);
-            outKeys.push({
-              "kty":"oct",
-              "alg":"A128KW",
-              "kid":id64,
-              "k":HexToBase64(key)
-            });
-          } else {
-            bail(v._test_token + " couldn't find key for key id " + idHex);
-          }
-        }
-
-        var update = JSON.stringify({
-          "keys" : outKeys,
-          "type" : msg.type
-        });
-        Log(v._test_token, "Session[" + session.sessionId + "], sending update message to CDM: " + update);
-
-        session.update(StringToArrayBuffer(update)).then(function() {
-          Log(v._test_token, "Session[" + session.sessionId + "] update ok");
-          if (v._test_params && v._test_params.onsessionupdated) {
-            v._test_params.onsessionupdated(session);
-          }
-          return resolve(session);
-        }).catch(function(reason) {
-          bail(v._test_token + " Session[" + session.sessionId + "] update failed")(reason);
-          return reject();
-        });
-      }
-    }
-
-    return new Promise(function (resolve, reject) {
-      session.addEventListener("message", UpdateSessionFunc(resolve, reject));
-      Log(v._test_token, "session[" + session.sessionId + "].generateRequest(" + ev.initDataType + ")");
-      session.generateRequest(ev.initDataType, ev.initData)
-      .catch(function(reason) {
-        // Reject the promise if generateRequest() failed. Otherwise it will
-        // be resolve in UpdateSessionFunc().
-        bail(v.test_token + ": session[" + session.sessionId + "].generateRequest failed")(reason);
-        return reject();
-      });
-    });
-  });
-}
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -378,18 +378,16 @@ skip-if = buildapp == 'b2g' || toolkit =
 #skip-if = buildapp == 'b2g' || toolkit == 'android' # bug 1043403
 # Disabled (bug 1140778) since this test fails and we don't want to remove the
 # functionality being tested by this test. We should still test other observers
 # in future however, so I'm not removing the test, just disabling it.
 [test_eme_persistent_sessions.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' # bug 1043403
 [test_eme_playback.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' # bug 1043403
-[test_eme_playback_init_then_keys_then_data.html]
-skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # bug 1043403, bug 1057908
 [test_eme_requestKeySystemAccess.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' # bug 1043403
 [test_eme_stream_capture_blocked.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || (os == 'win' && !debug) # bug 1043403, bug 1140675
 [test_empty_resource.html]
 [test_error_in_video_document.html]
 skip-if = toolkit == 'android' || (os == 'win' && !debug) || (os == 'mac' && !debug) # bug 608634
 [test_error_on_404.html]
--- a/dom/media/test/test_eme_canvas_blocked.html
+++ b/dom/media/test/test_eme_canvas_blocked.html
@@ -5,17 +5,16 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="manifest.js"></script>
   <script type="text/javascript" src="eme.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
-SimpleTest.requestCompleteLog();
 var manager = new MediaTestManager;
 
 function startTest(test, token)
 {
   manager.started(token);
 
   var sessions = [];
 
@@ -34,24 +33,17 @@ function startTest(test, token)
       ctx.drawImage(video, 0, 0);
     } catch (ex) {
       threwError = true;
     }
     ok(threwError, TimeStamp(token) + " - Should throw an error when trying to draw EME video to canvas.");
     manager.finished(token);
   });
 
-  LoadTest(test, v, token)
-  .then(function() {
-    info(TimeStamp(token) + " - Finished loading.");
-  })
-  .catch(function() {
-    ok(false, TimeStamp(token) + " - Cannot load.");
-    manager.finished(token);
-  });
+  LoadTest(test, v, token);
 }
 
 function beginTest() {
   manager.runTests(gEMETests, startTest);
 }
 
 var prefs = [
   [ "media.mediasource.enabled", true ],
--- a/dom/media/test/test_eme_non_mse_fails.html
+++ b/dom/media/test/test_eme_non_mse_fails.html
@@ -5,17 +5,16 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="manifest.js"></script>
   <script type="text/javascript" src="eme.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
-SimpleTest.requestCompleteLog();
 var manager = new MediaTestManager;
 
 function DoSetMediaKeys(v)
 {
   var options = [{
     initDataType: "cenc",
     videoType: test.type,
   }];
--- a/dom/media/test/test_eme_obs_notification.html
+++ b/dom/media/test/test_eme_obs_notification.html
@@ -5,17 +5,16 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="manifest.js"></script>
   <script type="text/javascript" src="eme.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
-SimpleTest.requestCompleteLog();
 var manager = new MediaTestManager;
 
 var videos = new Set();
 var observedVideos = new Set();
 
 var observer = function(subject) {
   ok(videos.has(subject), "Video should be known to us");
   videos.delete(subject);
@@ -48,24 +47,17 @@ function startTest(test, token)
   v.preload = "auto"; // Required due to "canplay" not firing for MSE unless we do this.
 
   v.addEventListener("loadeddata", function(ev) {
     ok(observedVideos.has(ev.target), "Should have been told about eme video through observer as well.");
     observedVideos.delete(ev.target);
     manager.finished(token);
   });
 
-  LoadTest(test, v, token)
-  .then(function() {
-    info(TimeStamp(token) + " - Finished loading.");
-  })
-  .catch(function() {
-    ok(false, TimeStamp(token) + " - Cannot load.");
-    manager.finished(token);
-  });
+  LoadTest(test, v, token);
 }
 
 function beginTest() {
   manager.runTests(gEMETests, startTest);
 }
 
 var prefs = [
   [ "media.mediasource.enabled", true ],
--- a/dom/media/test/test_eme_persistent_sessions.html
+++ b/dom/media/test/test_eme_persistent_sessions.html
@@ -5,17 +5,16 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="manifest.js"></script>
   <script type="text/javascript" src="eme.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
-SimpleTest.requestCompleteLog();
 var manager = new MediaTestManager;
 
 function UsableKeyIdsMatch(usableKeyIds, expectedKeyIds) {
   var hexKeyIds = usableKeyIds.map(function(keyId) {
     return Base64ToHex(window.btoa(ArrayBufferToString(keyId)));
   }).sort();
   var expected = Object.keys(expectedKeyIds).sort();
   if (expected.length != hexKeyIds.length) {
@@ -68,20 +67,16 @@ function startTest(test, token)
 
   var recreatedSession; // will have remove() called on it.
 
   var keySystemAccess;
 
   var v = SetupEME(test, token,
     {
       onsessionupdated: function(session) {
-        // TODO: Remove this when onsessionupdated is fixed for multiple sessions
-        // in bug 1142379.
-        if (!session) { return; }
-
         Log(token, "Session created");
         var sessionId;
         initialSession = session;
 
         // Once the session has loaded and has all its keys usable, close
         // all sessions without calling remove() on them.
         AwaitAllKeysUsable(session, test.keys, token)
         .then(function() {
@@ -147,24 +142,17 @@ function startTest(test, token)
           manager.finished(token);
         });
 
       },
       sessionType: "persistent",
     }
   );
 
-  LoadTest(test, v, token)
-  .then(function() {
-    info(TimeStamp(token) + " - Finished loading.");
-  })
-  .catch(function() {
-    ok(false, TimeStamp(token) + " - Cannot load.");
-    manager.finished(token);
-  });
+  LoadTest(test, v, token);
 }
 
 function beginTest() {
   manager.runTests(gEMETests, startTest);
 }
 
 var prefs = [
   [ "media.mediasource.enabled", true ],
--- a/dom/media/test/test_eme_playback.html
+++ b/dom/media/test/test_eme_playback.html
@@ -5,17 +5,16 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="manifest.js"></script>
   <script type="text/javascript" src="http://test1.mochi.test:8888/tests/dom/media/test/eme.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
-SimpleTest.requestCompleteLog();
 var manager = new MediaTestManager;
 
 
 function KeysChangeFunc(session, keys, token) {
   session.keyIdsReceived = [];
   for (var keyid in keys) {
     Log(token, "Set " + keyid + " to false in session.keyIdsReceived");
     session.keyIdsReceived[keyid] = false;
@@ -88,40 +87,16 @@ function startTest(test, token)
       }
     }
 
     manager.finished(token);
   });
 
   LoadTest(test, v, token)
   .then(function() {
-    Log(token, "Loading complete -> Play");
-    var lastState = "(before play)";
-    var maxWait_ms = (test.duration * 2 + 1) * 1000;
-    var playTimer = setTimeout(function() {
-      if (lastState !== "ended") {
-        ok(false, TimeStamp(token) + " expected 'ended' around "
-                  + test.duration + "s, got '" + lastState
-                  + "' after " + (maxWait_ms / 1000) + "s");
-        manager.finished(token);
-      }
-    }, maxWait_ms);
-    v.addEventListener("ended", function(ev) {
-      clearTimeout(playTimer);
-      lastState = "ended";
-    });
-    [ "canplay", "canplaythrough", "error", "loadeddata",
-      "loadedmetadata", "loadstart", "pause", "play", "playing", "progress",
-      "stalled", "suspend", "waiting",
-    ].forEach(function(e) {
-      v.addEventListener(e, function(event) {
-        lastState = e;
-      });
-    });
-
     v.play();
   }).catch(function() {
     ok(false, token + " failed to load");
     manager.finished(token);
   });
 }
 
 function beginTest() {
deleted file mode 100644
--- a/dom/media/test/test_eme_playback_init_then_keys_then_data.html
+++ /dev/null
@@ -1,185 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Test Encrypted Media Extensions</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-  <script type="text/javascript" src="manifest.js"></script>
-  <script type="text/javascript" src="http://test1.mochi.test:8888/tests/dom/media/test/eme.js"></script>
-</head>
-<body>
-<pre id="test">
-<script class="testbody" type="text/javascript">
-SimpleTest.requestCompleteLog();
-var manager = new MediaTestManager;
-
-
-function KeysChangeFunc(session, keys, token) {
-  session.keyIdsReceived = [];
-  for (var keyid in keys) {
-    Log(token, "Set " + keyid + " to false in session[" + session.sessionId + "].keyIdsReceived");
-    session.keyIdsReceived[keyid] = false;
-  }
-  return function(ev) {
-    var session = ev.target;
-    session.gotKeysChanged = true;
-
-    var map = session.keyStatuses;
-    for (var [key, val] of map.entries()) {
-      is(val, "usable", token + ": key status should be usable");
-      var kid = Base64ToHex(window.btoa(ArrayBufferToString(key)));
-      ok(kid in session.keyIdsReceived, TimeStamp(token) + " session[" + session.sessionId + "].keyIdsReceived contained " + kid + " as expected.");
-      session.keyIdsReceived[kid] = true;
-    }
-  }
-}
-
-function startTest(test, token)
-{
-  manager.started(token);
-
-  var sessions = [];
-  var updatedSessions = [];
-  var loaded = false;
-
-  var v = SetupControlledEME(test, token,
-    {
-      onsessioncreated: function(session) {
-        ok(sessions.indexOf(session) === -1, "Session[" + session.sessionId + "] should only be created once");
-        sessions.push(session);
-        session.addEventListener("keystatuseschange", KeysChangeFunc(session, test.keys, token), false);
-      },
-      onsessionupdated: function(session) {
-        if (session) {
-          ok(sessions.indexOf(session) !== -1, "Updated session[" + session.sessionId + "] should be in previously-created session list");
-          ok(updatedSessions.indexOf(session) === -1, "Session[" + session.sessionId + "] should only be updated once");
-          updatedSessions.push(session);
-        } else {
-          // Special case for this early test: Just assume 2nd session is updated ok.
-          // Dummy "updatedSessions" for we start loading data...
-          updatedSessions.push("dummy");
-        }
-        if (updatedSessions.length == test.sessionCount) {
-          if (loaded) {
-            Log(token, "Updated all sessions, loading complete -> Play");
-            Play();
-          } else {
-            Log(token, "Updated all sessions, loading not complete -> Don't play yet");
-          }
-        } else {
-          Log(token, "Updated " + updatedSessions.length + "/" + test.sessionCount + " sessions so far");
-        }
-      },
-    }
-  );
-
-  var gotEncrypted = 0;
-  var gotPlaying = false;
-
-  v.addEventListener("encrypted", function(ev) {
-    gotEncrypted += 1;
-  });
-
-  v.addEventListener("playing", function () { gotPlaying = true; });
-
-  v.addEventListener("loadedmetadata", function() {
-    ok(SpecialPowers.do_lookupGetter(v, "isEncrypted").apply(v),
-       TimeStamp(token) + " isEncrypted should be true");
-    is(v.isEncrypted, undefined, "isEncrypted should not be accessible from content");
-  });
-
-  v.addEventListener("ended", function(ev) {
-    ok(true, TimeStamp(token) + " got ended event");
-
-    is(gotEncrypted, test.sessionCount,
-       TimeStamp(token) + " encrypted events expected: " + test.sessionCount
-       + ", actual: " + gotEncrypted);
-    ok(gotPlaying, TimeStamp(token) + " playing event should have fired");
-
-    ok(Math.abs(test.duration - v.duration) < 0.1,
-       TimeStamp(token) + " Duration of video should be corrrect");
-    ok(Math.abs(test.duration - v.currentTime) < 0.1,
-       TimeStamp(token) + " Current time should be same as duration");
-
-    // Verify all sessions had all keys went sent the to the CDM usable, and thus
-    // that we received keystatuseschange event(s).
-    is(sessions.length, test.sessionCount, TimeStamp(token) + " should have "
-                        + test.sessionCount + " session" + (test.sessionCount === 1 ? "" : "s"));
-    for (var i = 0; i < sessions.length; i++) {
-      var session = sessions[i];
-      ok(session.gotKeysChanged, TimeStamp(token) + " should have received at least one keychange event");
-      for (var kid in session.keyIdsReceived) {
-        ok(session.keyIdsReceived[kid], TimeStamp(token) + " key with id " + kid + " was usable as expected");
-      }
-    }
-
-    manager.finished(token);
-  });
-
-  LoadControlledEME(v)
-  .then(function() {
-    loaded = true;
-    if (updatedSessions.length === test.sessionCount) {
-      Log(token, "Loaded all segments, all sessions up-to-date -> Play.");
-      Play();
-    } else {
-      Log(token, "Loaded all segments, only " + updatedSessions.length
-                 + "/" + test.sessionCount + " sessions up-to-date -> Don't play yet");
-    }
-  }).catch(function(reason) {
-    ok(false, token + " failed to load, reason: " + (reason ? reason : "?"));
-    manager.finished(token);
-  });
-
-  function Play()
-  {
-    var lastState = "(before play)";
-    var maxWait_ms = (test.duration * 2 + 1) * 1000;
-    var playTimer = setTimeout(function() {
-      if (lastState !== "ended") {
-        ok(false, TimeStamp(token) + " expected 'ended' around "
-                  + test.duration + "s, got '" + lastState
-                  + "' after " + (maxWait_ms / 1000) + "s");
-        manager.finished(token);
-      }
-    }, maxWait_ms);
-    v.addEventListener("ended", function(ev) {
-      clearTimeout(playTimer);
-      lastState = "ended";
-    });
-    [ "canplay", "canplaythrough", "error", "loadeddata",
-      "loadedmetadata", "loadstart", "pause", "play", "playing", "progress",
-      "stalled", "suspend", "waiting",
-    ].forEach(function(e) {
-      v.addEventListener(e, function(event) {
-        lastState = e;
-      });
-    });
-
-    v.play();
-  }
-}
-
-function beginTest() {
-  manager.runTests(gEMETests, startTest);
-}
-
-var prefs = [
-  [ "media.mediasource.enabled", true ],
-  [ "media.mediasource.whitelist", false ],
-  [ "media.mediasource.mp4.enabled", true ],
-];
-
-if (/Linux/.test(navigator.userAgent) ||
-    !document.createElement('video').canPlayType("video/mp4")) {
-  // XXX remove once we have mp4 PlatformDecoderModules on all platforms.
-  prefs.push([ "media.fragmented-mp4.exposed", true ]);
-  prefs.push([ "media.fragmented-mp4.use-blank-decoder", true ]);
-}
-
-SimpleTest.waitForExplicitFinish();
-SpecialPowers.pushPrefEnv({ "set" : prefs }, beginTest);
-</script>
-</pre>
-</body>
-</html>
--- a/dom/media/test/test_eme_stream_capture_blocked.html
+++ b/dom/media/test/test_eme_stream_capture_blocked.html
@@ -5,17 +5,16 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="manifest.js"></script>
   <script type="text/javascript" src="eme.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
-SimpleTest.requestCompleteLog();
 var manager = new MediaTestManager;
 
 function startTest(test, token)
 {
   // Three cases:
   // 1. setting MediaKeys on an element captured by MediaElementSource should fail, and
   // 2. creating a MediaElementSource on a media element with a MediaKeys should fail, and
   // 3. capturing a media element with mozCaptureStream that has a MediaKeys should fail.
@@ -28,27 +27,17 @@ function startTest(test, token)
   };
   var v1 = SetupEME(test, case1token,  { onSetKeysFail: setKeysFailed });
   var context = new AudioContext();
   var node = context.createMediaElementSource(v1);
   v1.addEventListener("loadeddata", function(ev) {
     ok(false, TimeStamp(case1token) + " should never reach loadeddata, as setMediaKeys should fail");
   });
   manager.started(case1token);
-  manager.started(case1token + "_load");
-  LoadTest(test, v1, case1token)
-  .then(function() {
-    info(TimeStamp(case1token) + " - Finished loading.");
-    manager.finished(case1token + "_load");
-  })
-  .catch(function() {
-    ok(false, TimeStamp(case1token) + " - Cannot load.");
-    manager.finished(case1token + "_load");
-    manager.finished(case1token);
-  });
+  LoadTest(test, v1, case1token);
 
 
   // Case 2. creating a MediaElementSource on a media element with a MediaKeys should fail.
   var case2token = token + "_case2";
   var v2 = SetupEME(test, case2token);
   v2.addEventListener("loadeddata", function(ev) {
     ok(true, case2token + " should reach loadeddata");
     var threw = false;
@@ -57,27 +46,17 @@ function startTest(test, token)
       var node = context.createMediaElementSource(v2);
     } catch (e) {
       threw = true;
     }
     ok(threw, "Should throw an error creating a MediaElementSource on an EME video.");
     manager.finished(case2token);
   });
   manager.started(case2token);
-  manager.started(case2token + "_load");
-  LoadTest(test, v2, case2token)
-  .then(function() {
-    info(TimeStamp(case2token) + " - Finished loading.");
-    manager.finished(case2token + "_load");
-  })
-  .catch(function() {
-    ok(false, TimeStamp(case2token) + " - Cannot load.");
-    manager.finished(case2token + "_load");
-    manager.finished(case2token);
-  });
+  LoadTest(test, v2, case2token);
 
 
   // Case 3. capturing a media element with mozCaptureStream that has a MediaKeys should fail.
   var case3token = token + "_case3";
   var v3 = SetupEME(test, case3token);
   v3.addEventListener("loadeddata", function(ev) {
     ok(true, TimeStamp(case3token) + " should reach loadeddata");
     var threw = false;
@@ -85,27 +64,17 @@ function startTest(test, token)
       var stream = v3.mozCaptureStreamUntilEnded();
     } catch (e) {
       threw = true;
     }
     ok(threw, TimeStamp(case3token) + " Should throw an error calling mozCaptureStreamUntilEnded an EME video.");
     manager.finished(case3token);
   });
   manager.started(case3token);
-  manager.started(case3token + "_load");
-  LoadTest(test, v3, case3token)
-  .then(function() {
-    info(TimeStamp(case3token) + " - Finished loading.");
-    manager.finished(case3token + "_load");
-  })
-  .catch(function() {
-    ok(false, TimeStamp(case3token) + " - Cannot load.");
-    manager.finished(case3token + "_load");
-    manager.finished(case3token);
-  });
+  LoadTest(test, v3, case3token);
 }
 
 function beginTest() {
   manager.runTests(gEMETests, startTest);
 }
 
 var prefs = [
   [ "media.mediasource.enabled", true ],