Bug 1395922 - [P6][Test] Playback should resume after reattaching same MediaKeys with valid sessions. draft
authorKilik Kuo <kikuo@mozilla.com>
Fri, 20 Oct 2017 18:20:53 +0800
changeset 683874 8ac47067c13a3c9687c0428f755272ac8c82f0d8
parent 683873 cb3fb4321bdff6d88de83767e1a175ddd7aaa013
child 736740 e122c4b0ba70bfc4785645c9bc58ce3de632e422
push id85477
push userkikuo@mozilla.com
push dateFri, 20 Oct 2017 10:21:33 +0000
bugs1395922
milestone57.0a1
Bug 1395922 - [P6][Test] Playback should resume after reattaching same MediaKeys with valid sessions. MozReview-Commit-ID: LnAwXmdJIXb
dom/media/test/mochitest.ini
dom/media/test/test_eme_detach_reattach_same_mediakeys_during_playback.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -755,16 +755,18 @@ skip-if = android_version == '17' # andr
 skip-if = toolkit == 'android' # bug 1149374
 [test_eme_pssh_in_moof.html]
 skip-if = toolkit == 'android' # bug 1149374
 [test_eme_session_callable_value.html]
 [test_eme_canvas_blocked.html]
 skip-if = toolkit == 'android' # bug 1149374
 [test_eme_detach_media_keys.html]
 skip-if = toolkit == 'android' # bug 1149374
+[test_eme_detach_reattach_same_mediakeys_during_playback.html]
+skip-if = toolkit == 'android' # bug 1149374
 [test_eme_initDataTypes.html]
 skip-if = toolkit == 'android' # bug 1149374
 [test_eme_missing_pssh.html]
 skip-if = toolkit == 'android' # bug 1149374
 [test_eme_non_mse_fails.html]
 skip-if = toolkit == 'android' # bug 1149374
 [test_eme_request_notifications.html]
 skip-if = toolkit == 'android' # bug 1149374
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_eme_detach_reattach_same_mediakeys_during_playback.html
@@ -0,0 +1,155 @@
+<!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">
+<video id="v" controls></video>
+<script class="testbody" type="text/javascript">
+var manager = new MediaTestManager;
+
+var EMEmanifest = [
+  {
+    name:"bipbop 10s",
+    tracks: [
+      {
+          name:"video",
+          type:"video/mp4; codecs=\"avc1.4d4015\"",
+          fragments:[ "bipbop-cenc-video-10s.mp4",
+                    ]
+      }
+    ],
+    keys: {
+      "7e571d037e571d037e571d037e571d11" : "7e5733337e5733337e5733337e573311",
+    },
+    sessionType:"temporary",
+    sessionCount:1,
+    duration:10.01
+  },
+];
+
+function sleep(time) {
+  return new Promise((resolve) => setTimeout(resolve, time));
+}
+
+// To check if playback can be blocked and resumed correctly after
+// detaching original mediakeys and reattach it back.
+function startTest(test, token)
+{
+  manager.started(token);
+
+  var m;
+  function createAndSet() {
+    return new Promise(function(resolve, reject) {
+      navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, gCencMediaKeySystemConfig)
+      .then(function (access) {
+        return access.createMediaKeys();
+      })
+      .then(function (mediaKeys) {
+        m = mediaKeys;
+      });
+    }
+  )}
+  createAndSet();
+
+  var mk_ori;
+  let finish = new EMEPromise;
+
+  let v = document.getElementById("v");
+  let sessions = [];
+  function onSessionCreated(session) {
+    sessions.push(session);
+  }
+
+  function closeSessions() {
+    let p = new EMEPromise;
+    Promise.all(sessions.map(s => s.close()))
+    .then(p.resolve, p.reject);
+    return p.promise;
+  }
+
+  function setMediaKeysToElement(mk, solve, reject) {
+    v.setMediaKeys(mk).then(solve, reject);
+  }
+
+  function ReattachOriMediaKeys() {
+    function onOriMediaKeysSetOK() {
+      ok(true, TimeStamp(token) + " (ENCRYPTED) Set original MediaKeys back OK!");
+    }
+    function onOriMediaKeysSetFailed() {
+      ok(false, " Failed to set original mediakeys back.");
+    }
+    function onCanPlayAgain(ev) {
+      Promise.all([closeSessions()])
+      .then(() => {
+        ok(true, " (ENCRYPTED) Playback can be resumed.");
+        manager.finished(token);
+      }, () => {
+        ok(false, TimeStamp(token) + " Sessions are closed incorrectly.");
+        manager.finished(token);
+      });
+    }
+    once(v, "canplay", onCanPlayAgain);
+    setMediaKeysToElement(mk_ori, onOriMediaKeysSetOK, onOriMediaKeysSetFailed)
+  }
+
+  function triggerSeek() {
+    v.currentTime = v.duration / 2;
+  }
+
+  function onCanPlay(ev) {
+    function onSetMediaKeysToNullOK() {
+      ok(true, TimeStamp(token) + " Set MediaKeys to null. OK!");
+
+      triggerSeek();
+
+      SimpleTest.requestFlakyTimeout("To reattach mediakeys back again in 5s.");
+      sleep(5000).then(ReattachOriMediaKeys);
+    }
+    function onSetMediaKeysToNullFailed() {
+      ok(false, TimeStamp(token) + " Set MediaKeys to null. FAILED!");
+    }
+    SimpleTest.requestFlakyTimeout("To detach mediakeys after receiving 'canplay' event in 2s");
+    sleep(2000).then(() => {
+      setMediaKeysToElement(null, onSetMediaKeysToNullOK, onSetMediaKeysToNullFailed);
+    });
+  }
+
+  once(v, "canplay", onCanPlay);
+
+  var p1 = LoadInitData(v, test, token);
+  var p2 = CreateAndSetMediaKeys(v, test, token);
+  var p3 = LoadTest(test, v, token);
+  Promise.all([p1, p2, p3])
+  .then(values => {
+    let initData = values[0];
+    // stash the mediakeys
+    mk_ori = v.mediaKeys;
+    initData.map(ev => {
+      let session = v.mediaKeys.createSession();
+      onSessionCreated(session);
+      MakeRequest(test, token, ev, session);
+    });
+  })
+  .then(() => {
+    return finish.promise;
+  })
+  .catch(reason => ok(false, reason))
+}
+
+function beginTest() {
+  manager.runTests(EMEmanifest, startTest);
+}
+
+SimpleTest.waitForExplicitFinish();
+SetupEMEPref(beginTest);
+
+</script>
+</pre>
+</body>
+</html>