1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105

media / test / data / multiple_cdm_types.html [blame]

<!DOCTYPE html>
<title>Test running different types of CDM in the system</title>
<div id="console"></div>
<script src='eme_player_js/app_loader.js' type='text/javascript'></script>
<script type='text/javascript'>

  function log(message) {
    let consoleElement = document.getElementById('console');
    let entry = document.createElement('div');
    entry.appendChild(document.createTextNode(message));
    consoleElement.appendChild(entry);
    console.log(message);
  }

  const EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE
      = 'org.chromium.externalclearkey.differentcdmtype';
  const crashKeyId = 'crash';
  const normalJwkSet = Utils.createJWKData(KEY_ID, KEY);
  const crashJwkSet = Utils.createJWKData(crashKeyId, KEY);

  var config = {
    initDataTypes : [ 'keyids' ],
    videoCapabilities: [{contentType: 'video/webm; codecs="vp8"'}],
    persistentState: 'optional',
    sessionTypes: ['temporary'],
  };

  function createMediaKeySession(key_system) {
    var mediaKeySession;
    return navigator.requestMediaKeySystemAccess(key_system, [config])
        .then(function(access) {
      initDataType = access.getConfiguration().initDataTypes[0];
      initData = Utils.createKeyIdsInitializationData(KEY_ID)
      return access.createMediaKeys();
    }).then(function(result) {
      log('CDM created');
      var mediaKeys = result;
      mediaKeySession = mediaKeys.createSession();
      return mediaKeySession.generateRequest(initDataType, initData);
    }).then(function() {
      mediaKeySession.update(normalJwkSet);
    }).then(function() {
      return mediaKeySession;
    });
  }

  log('Start test');

  // Using EXTERNAL_CLEARKEY
  var session1;

  // Both using EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE
  var session2;
  var session3;

  // The following creates 3 MediaKeys instances each with a MediaKeySession.
  // MediaKeys using different CDM type will run in different processes.
  // |session1| uses EXTERNAL_CLEARKEY that is registered with the default type
  // for Clear Key CDM. |session2/3| use EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE that
  // is registered with a different type. So |session1| will run in process1,
  // and |session2/3| will run in process2.
  //
  // Then we send a special response |crashJwkSet| to session2 which will cause
  // the process2 to crash. This will close both |session2/3| as they run in the
  // same process. |session1| should not be affected. Then we try to create
  // another MediaKeySession using EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE, and the
  // creation should work as a new process should be started.

  createMediaKeySession(EXTERNAL_CLEARKEY).then(function(session) {
    log('Session1 created');
    session1 = session;
    return createMediaKeySession(EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE);
  }).then(function(session) {
    log('Session2 created');
    session2 = session;
    return createMediaKeySession(EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE);
  }).then(function(session) {
    log('Session3 created');
    session3 = session;
    log('Crash session2');
    return session2.update(crashJwkSet);
  }).finally(function() {
    // Due to the crash, the update() above could resolve or reject.
    // So use "finally" so that we continue the test regardless.
    log('Session2 crashed');
    return session2.closed;
  }).then(function() {
    log('Session2 closed');
    return session3.closed;
  }).then(function() {
    log('Session3 also closed');
    return session1.update(normalJwkSet);
  }).then(function() {
    log('Session1 still works');
    return createMediaKeySession(EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE);
  }).then(function(session) {
    log('Can still create a session after crash');
    Utils.setResultInTitle('ENDED');
  }).catch(function(error) {
    log('Error: ' + error);
    Utils.failTest('Test failed: ' + error);
  });

</script>
</html>