dom/media/test/test_eme_unsetMediaKeys_then_capture.html
author Kilik Kuo <kikuo@mozilla.com>
Fri, 01 Dec 2017 10:59:57 +0800
changeset 394643 2a5765cbd308215f11ea6bc7b52e71228709d971
parent 390910 c7c230ee775e023a243f2a80601b0f7b4d80188e
child 469641 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Bug 1421920 - Remove unnecessary script in test_eme_unsetMediaKeys_then_capture.html for further debugging. r=jwwang There're several causes for Bug 1414464. Removing unnecessary script in this test to eliminate the uncertainty for further debugging. MozReview-Commit-ID: IWvvlzJ24gw

<!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="https://example.com:443/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.");

    function playClearVideo() {
      var p1 = 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]).then(() => {
        manager.finished(token);
      }, () => {
        ok(false, TimeStamp(token) + " Something wrong.");
        manager.finished(token);
      });
    }

    closeSessions()
    .then(() => {
      v.setMediaKeys(null)
      .then(() => {
        ok(true, TimeStamp(token) + " Setting MediaKeys to null.");
        playClearVideo();
      }, () => {
        ok(false, TimeStamp(token) + " Setting MediaKeys to null.");
      });;
    });
  }

  once(v, "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>