multiple_cdm_types.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!DOCTYPE html>
  2. <title>Test running different types of CDM in the system</title>
  3. <div id="console"></div>
  4. <script src='eme_player_js/app_loader.js' type='text/javascript'></script>
  5. <script type='text/javascript'>
  6. function log(message) {
  7. let consoleElement = document.getElementById('console');
  8. let entry = document.createElement('div');
  9. entry.appendChild(document.createTextNode(message));
  10. consoleElement.appendChild(entry);
  11. console.log(message);
  12. }
  13. const EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE
  14. = 'org.chromium.externalclearkey.differentcdmtype';
  15. const crashKeyId = 'crash';
  16. const normalJwkSet = Utils.createJWKData(KEY_ID, KEY);
  17. const crashJwkSet = Utils.createJWKData(crashKeyId, KEY);
  18. var config = {
  19. initDataTypes : [ 'keyids' ],
  20. videoCapabilities: [{contentType: 'video/webm; codecs="vp8"'}],
  21. persistentState: 'optional',
  22. sessionTypes: ['temporary'],
  23. };
  24. function createMediaKeySession(key_system) {
  25. var mediaKeySession;
  26. return navigator.requestMediaKeySystemAccess(key_system, [config])
  27. .then(function(access) {
  28. initDataType = access.getConfiguration().initDataTypes[0];
  29. initData = Utils.createKeyIdsInitializationData(KEY_ID)
  30. return access.createMediaKeys();
  31. }).then(function(result) {
  32. log('CDM created');
  33. var mediaKeys = result;
  34. mediaKeySession = mediaKeys.createSession();
  35. return mediaKeySession.generateRequest(initDataType, initData);
  36. }).then(function() {
  37. mediaKeySession.update(normalJwkSet);
  38. }).then(function() {
  39. return mediaKeySession;
  40. });
  41. }
  42. log('Start test');
  43. // Using EXTERNAL_CLEARKEY
  44. var session1;
  45. // Both using EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE
  46. var session2;
  47. var session3;
  48. // The following creates 3 MediaKeys instances each with a MediaKeySession.
  49. // MediaKeys using different CDM type will run in different processes.
  50. // |session1| uses EXTERNAL_CLEARKEY that is registered with the default type
  51. // for Clear Key CDM. |session2/3| use EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE that
  52. // is registered with a different type. So |session1| will run in process1,
  53. // and |session2/3| will run in process2.
  54. //
  55. // Then we send a special response |crashJwkSet| to session2 which will cause
  56. // the process2 to crash. This will close both |session2/3| as they run in the
  57. // same process. |session1| should not be affected. Then we try to create
  58. // another MediaKeySession using EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE, and the
  59. // creation should work as a new process should be started.
  60. createMediaKeySession(EXTERNAL_CLEARKEY).then(function(session) {
  61. log('Session1 created');
  62. session1 = session;
  63. return createMediaKeySession(EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE);
  64. }).then(function(session) {
  65. log('Session2 created');
  66. session2 = session;
  67. return createMediaKeySession(EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE);
  68. }).then(function(session) {
  69. log('Session3 created');
  70. session3 = session;
  71. log('Crash session2');
  72. return session.update(crashJwkSet);
  73. }).finally(function() {
  74. // Due to the crash, the update() above could resolve or reject.
  75. // So use "finally" so that we continue the test regardless.
  76. log('Session2 crashed');
  77. return session2.closed;
  78. }).then(function() {
  79. log('Session2 closed');
  80. return session3.closed;
  81. }).then(function() {
  82. log('Session3 also closed');
  83. return session1.update(normalJwkSet);
  84. }).then(function() {
  85. log('Session1 still works');
  86. return createMediaKeySession(EXTERNAL_CLEARKEY_DIFFERENTCDMTYPE);
  87. }).then(function(session) {
  88. log('Can still create a session after crash');
  89. Utils.setResultInTitle('ENDED');
  90. }).catch(function(error) {
  91. log('Error: ' + error);
  92. Utils.failTest('Test failed: ' + error);
  93. });
  94. </script>
  95. </html>