Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: media/test/data/eme_player_js/player_utils.js

Issue 2426813002: EME: Close existing sessions on CDM failure (Closed)
Patch Set: add new tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The PlayerUtils provides utility functions to binding common media events 5 // The PlayerUtils provides utility functions to binding common media events
6 // to specific player functions. It also provides functions to load media source 6 // to specific player functions. It also provides functions to load media source
7 // base on test configurations. 7 // base on test configurations.
8 var PlayerUtils = new function() { 8 var PlayerUtils = new function() {
9 } 9 }
10 10
(...skipping 10 matching lines...) Expand all
21 var eventListenerFunction = player[eventListenerMap[eventName]]; 21 var eventListenerFunction = player[eventListenerMap[eventName]];
22 if (eventListenerFunction) { 22 if (eventListenerFunction) {
23 player.video.addEventListener(eventName, function(e) { 23 player.video.addEventListener(eventName, function(e) {
24 player[eventListenerMap[e.type]](e); 24 player[eventListenerMap[e.type]](e);
25 }); 25 });
26 } 26 }
27 } 27 }
28 28
29 player.video.addEventListener('error', function(error) { 29 player.video.addEventListener('error', function(error) {
30 // This most likely happens on pipeline failures (e.g. when the CDM 30 // This most likely happens on pipeline failures (e.g. when the CDM
31 // crashes). 31 // crashes). Don't report a failure if the test is checking that sessions
32 // are closed on a crash.
32 Utils.timeLog('onHTMLElementError', error); 33 Utils.timeLog('onHTMLElementError', error);
33 Utils.failTest(error); 34 if (player.testConfig.keySystem != CLOSE_ON_CRASH_TEST_KEYSYSTEM) {
35 Utils.failTest(error);
36 }
34 }); 37 });
35 }; 38 };
36 39
37 // Register the necessary event handlers needed when playing encrypted content. 40 // Register the necessary event handlers needed when playing encrypted content.
38 // Returns a promise that resolves to the player. 41 // Returns a promise that resolves to the player.
39 PlayerUtils.registerEMEEventListeners = function(player) { 42 PlayerUtils.registerEMEEventListeners = function(player) {
40 player.video.addEventListener('encrypted', function(message) { 43 player.video.addEventListener('encrypted', function(message) {
41 44
42 function addMediaKeySessionListeners(mediaKeySession) { 45 function addMediaKeySessionListeners(mediaKeySession) {
43 mediaKeySession.addEventListener('message', function(message) { 46 mediaKeySession.addEventListener('message', function(message) {
(...skipping 26 matching lines...) Expand all
70 }, 73 },
71 function(error) { Utils.failTest(error, EME_LOAD_FAILED); }); 74 function(error) { Utils.failTest(error, EME_LOAD_FAILED); });
72 } else { 75 } else {
73 Utils.timeLog('Creating new media key session for initDataType: ' + 76 Utils.timeLog('Creating new media key session for initDataType: ' +
74 message.initDataType + ', initData: ' + 77 message.initDataType + ', initData: ' +
75 Utils.getHexString(new Uint8Array(message.initData))); 78 Utils.getHexString(new Uint8Array(message.initData)));
76 var session = message.target.mediaKeys.createSession(); 79 var session = message.target.mediaKeys.createSession();
77 addMediaKeySessionListeners(session); 80 addMediaKeySessionListeners(session);
78 session.generateRequest(message.initDataType, message.initData) 81 session.generateRequest(message.initDataType, message.initData)
79 .catch(function(error) { 82 .catch(function(error) {
80 // Ignore the error if a crash is expected. This ensures that 83 if (this.testConfig.keySystem == CLOSE_ON_CRASH_TEST_KEYSYSTEM) {
81 // the decoder actually detects and reports the error. 84 // Failure is expected, wait for the session to be closed.
82 if (this.testConfig.keySystem != 85 session.closed.then(
83 'org.chromium.externalclearkey.crash') { 86 function(result) {
87 Utils.setResultInTitle('SESSION_CLOSED');
88 },
89 function(error) { Utils.failTest(error); });
90 } else if (
91 this.testConfig.keySystem == ERROR_ON_CRASH_TEST_KEYSYSTEM) {
92 // Ignore the failure if a crash is expected. This ensures that
93 // the decoder actually detects and reports the error.
94 } else {
84 Utils.failTest(error, EME_GENERATEREQUEST_FAILED); 95 Utils.failTest(error, EME_GENERATEREQUEST_FAILED);
85 } 96 }
86 }); 97 });
87 } 98 }
88 } catch (e) { 99 } catch (e) {
89 Utils.failTest(e); 100 Utils.failTest(e);
90 } 101 }
91 }); 102 });
92 103
93 this.registerDefaultEventListeners(player); 104 this.registerDefaultEventListeners(player);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 203
193 // Return the appropriate player based on test configuration. 204 // Return the appropriate player based on test configuration.
194 PlayerUtils.createPlayer = function(video, testConfig) { 205 PlayerUtils.createPlayer = function(video, testConfig) {
195 function getPlayerType(keySystem) { 206 function getPlayerType(keySystem) {
196 switch (keySystem) { 207 switch (keySystem) {
197 case WIDEVINE_KEYSYSTEM: 208 case WIDEVINE_KEYSYSTEM:
198 return WidevinePlayer; 209 return WidevinePlayer;
199 case CLEARKEY: 210 case CLEARKEY:
200 case EXTERNAL_CLEARKEY: 211 case EXTERNAL_CLEARKEY:
201 case EXTERNAL_CLEARKEY_RENEWAL: 212 case EXTERNAL_CLEARKEY_RENEWAL:
213 case ERROR_ON_CRASH_TEST_KEYSYSTEM:
214 case CLOSE_ON_CRASH_TEST_KEYSYSTEM:
202 return ClearKeyPlayer; 215 return ClearKeyPlayer;
203 case FILE_IO_TEST_KEYSYSTEM: 216 case FILE_IO_TEST_KEYSYSTEM:
204 case OUTPUT_PROTECTION_TEST_KEYSYSTEM: 217 case OUTPUT_PROTECTION_TEST_KEYSYSTEM:
205 case PLATFORM_VERIFICATION_TEST_KEYSYSTEM: 218 case PLATFORM_VERIFICATION_TEST_KEYSYSTEM:
206 return UnitTestPlayer; 219 return UnitTestPlayer;
207 default: 220 default:
208 Utils.timeLog(keySystem + ' is not a known key system'); 221 Utils.timeLog(keySystem + ' is not a known key system');
209 return ClearKeyPlayer; 222 return ClearKeyPlayer;
210 } 223 }
211 } 224 }
212 var Player = getPlayerType(testConfig.keySystem); 225 var Player = getPlayerType(testConfig.keySystem);
213 return new Player(video, testConfig); 226 return new Player(video, testConfig);
214 }; 227 };
OLDNEW
« media/test/data/eme_player_js/clearkey_player.js ('K') | « media/test/data/eme_player_js/globals.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698