Bug 1395922 - [P5][Test] Capture clear content with canvas 2d after remove MediaKeys from the same HTMLMediaElement. r=cpearce
authorKilik Kuo <kikuo@mozilla.com>
Fri, 03 Nov 2017 20:15:19 +0800
changeset 443279 f59a7e727f39201d8af28b9cb08b26a45d22007e
parent 443278 9cd31c6a8e2c30132865e7d2a73a91ebb5faffa6
child 443280 f856af63682efa003abcbf478c6e0ad875408775
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 - [P5][Test] Capture clear content with canvas 2d after remove MediaKeys from the same HTMLMediaElement. r=cpearce MozReview-Commit-ID: CUnblsNOmcm
dom/media/test/bipbop_225w_175kbps.mp4^headers^
dom/media/test/mochitest.ini
dom/media/test/test_eme_unsetMediaKeys_then_capture.html
new file mode 100644
--- /dev/null
+++ b/dom/media/test/bipbop_225w_175kbps.mp4^headers^
@@ -0,0 +1,1 @@
+Cache-Control: no-store
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -69,16 +69,18 @@ support-files =
   bipbop-cenc-video1.m4s
   bipbop-cenc-video1.m4s^headers^
   bipbop-cenc-video2.m4s
   bipbop-cenc-video2.m4s^headers^
   bipbop-cenc-videoinit.mp4
   bipbop-cenc-videoinit.mp4^headers^
   bipbop-cenc-video-10s.mp4
   bipbop-cenc-video-10s.mp4^headers^
+  bipbop_225w_175kbps.mp4
+  bipbop_225w_175kbps.mp4^headers^
   bipbop_225w_175kbps-cenc-audio-key1-1.m4s
   bipbop_225w_175kbps-cenc-audio-key1-1.m4s^headers^
   bipbop_225w_175kbps-cenc-audio-key1-2.m4s
   bipbop_225w_175kbps-cenc-audio-key1-2.m4s^headers^
   bipbop_225w_175kbps-cenc-audio-key1-3.m4s
   bipbop_225w_175kbps-cenc-audio-key1-3.m4s^headers^
   bipbop_225w_175kbps-cenc-audio-key1-4.m4s
   bipbop_225w_175kbps-cenc-audio-key1-4.m4s^headers^
@@ -778,16 +780,18 @@ skip-if = toolkit == 'android' # bug 114
 tags=msg capturestream
 skip-if = toolkit == 'android' # bug 1149374
 [test_eme_stream_capture_blocked_case2.html]
 tags=msg capturestream
 skip-if = toolkit == 'android' # bug 1149374
 [test_eme_stream_capture_blocked_case3.html]
 tags=msg capturestream
 skip-if = toolkit == 'android' # bug 1149374
+[test_eme_unsetMediaKeys_then_capture.html]
+skip-if = toolkit == 'android' # bug 1149374
 [test_eme_waitingforkey.html]
 skip-if = toolkit == 'android' # bug 1149374
 [test_empty_resource.html]
 [test_error_in_video_document.html]
 [test_error_on_404.html]
 [test_fastSeek.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
 [test_fastSeek-forwards.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_eme_unsetMediaKeys_then_capture.html
@@ -0,0 +1,117 @@
+<!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">
+var manager = new MediaTestManager;
+
+// Test that if we can capture a video frame while playing clear content after
+// removing the MediaKeys object which was used for a previous encrypted content
+// playback on the same video element
+function startTest(test, token)
+{
+  manager.started(token);
+  var 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;
+  }
+
+  let v = document.createElement("video");
+  document.body.appendChild(v);
+
+  let finish = new EMEPromise;
+
+  function onVideoEnded(ev) {
+    ok(true, TimeStamp(token) + " (ENCRYPTED) content playback ended.");
+    v.removeEventListener("ended", onVideoEnded);
+
+    function playClearVideo() {
+      var p1 = once(v, 'ended', (e) => {
+        ok(true, TimeStamp(token) + " (CLEAR) content playback ended.");
+        console.log(" bipbop.mp4 playback ended !!");
+      });
+      var p2 = once(v, 'loadeddata', (e) => {
+        ok(true, TimeStamp(token) + " Receiving event 'loadeddata' for (CLEAR) content.");
+        canvasElem = document.createElement('canvas');
+        document.body.appendChild(canvasElem);
+        ctx2d = canvasElem.getContext('2d');
+
+        var gotTypeError = false;
+        try {
+          ctx2d.drawImage(v, 0, 0);
+        } catch (e) {
+          if (e instanceof TypeError) {
+            gotTypeError = true;
+          }
+        }
+        ok(!gotTypeError, TimeStamp(token) + " Canvas2D context drawImage succeed.")
+      });
+      v.src = 'bipbop_225w_175kbps.mp4';
+      v.play();
+      Promise.all([p1, p2, closeSessions()]).then(() => {
+        manager.finished(token);
+      }, () => {
+        ok(false, TimeStamp(token) + " Something wrong.");
+        manager.finished(token);
+      });
+    }
+
+    Promise.all(sessions.map(s => s.close()))
+    .then(() => {
+      v.setMediaKeys(null)
+      .then(() => {
+        ok(true, TimeStamp(token) + " Setting MediaKeys to null.");
+        playClearVideo();
+      }, () => {
+        ok(false, TimeStamp(token) + " Setting MediaKeys to null.");
+      });;
+    });
+  }
+
+  v.addEventListener("ended", onVideoEnded);
+
+  // Create a MediaKeys object and set to HTMLMediaElement then start the playback.
+  Promise.all([
+    LoadInitData(v, test, token),
+    CreateAndSetMediaKeys(v, test, token),
+    LoadTest(test, v, token)])
+  .then(values => {
+    let initData = values[0];
+    v.play();
+    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(gEMETests, startTest);
+}
+
+SimpleTest.waitForExplicitFinish();
+SetupEMEPref(beginTest);
+
+</script>
+</pre>
+</body>
+</html>