Bug 1395922 - [P6][Test] Playback should resume after reattaching same MediaKeys with valid sessions. r=cpearce
authorKilik Kuo <kikuo@mozilla.com>
Fri, 03 Nov 2017 20:15:48 +0800
changeset 443932 c432ab6709bc170b6b083e46f92647387b01336a
parent 443931 3adbfd979a270a2a3f2af2530b41794878b74b3d
child 443933 29e511fbcd627fecb2c3f5b4b99d0a747223bfd6
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1395922
milestone58.0a1
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
Bug 1395922 - [P6][Test] Playback should resume after reattaching same MediaKeys with valid sessions. r=cpearce MozReview-Commit-ID: CASXy2SN4fh
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,144 @@
+<!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 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>