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

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

Issue 823743002: Fix Flaky EncryptedMediaTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 } catch (e) { 74 } catch (e) {
75 Utils.failTest(e); 75 Utils.failTest(e);
76 } 76 }
77 }); 77 });
78 78
79 this.registerDefaultEventListeners(player); 79 this.registerDefaultEventListeners(player);
80 try { 80 try {
81 Utils.timeLog('Setting video media keys: ' + player.testConfig.keySystem); 81 Utils.timeLog('Setting video media keys: ' + player.testConfig.keySystem);
82 if (typeof navigator.requestMediaKeySystemAccess == 'function') { 82 if (typeof navigator.requestMediaKeySystemAccess == 'function') {
83 navigator.requestMediaKeySystemAccess(player.testConfig.keySystem) 83 return navigator.requestMediaKeySystemAccess(player.testConfig.keySystem)
84 .then(function(access) { return access.createMediaKeys(); }) 84 .then(function(access) { return access.createMediaKeys(); })
85 .then(function(mediaKeys) { player.video.setMediaKeys(mediaKeys); }) 85 .then(function(mediaKeys) { player.video.setMediaKeys(mediaKeys); })
86 .catch(function(error) { Utils.failTest(error, NOTSUPPORTEDERROR); }); 86 .catch(function(error) { Utils.failTest(error, NOTSUPPORTEDERROR); });
87 } else { 87 } else {
88 // TODO(jrummell): Remove this once the blink change for 88 // TODO(jrummell): Remove this once the blink change for
89 // requestMediaKeySystemAccess lands. 89 // requestMediaKeySystemAccess lands.
90 MediaKeys.create(player.testConfig.keySystem) 90 return MediaKeys.create(player.testConfig.keySystem)
91 .then(function(mediaKeys) { player.video.setMediaKeys(mediaKeys); }) 91 .then(function(mediaKeys) { player.video.setMediaKeys(mediaKeys); })
92 .catch(function(error) { Utils.failTest(error, NOTSUPPORTEDERROR); }); 92 .catch(function(error) { Utils.failTest(error, NOTSUPPORTEDERROR); });
93 } 93 }
94 } catch (e) { 94 } catch (e) {
95 Utils.failTest(e); 95 Utils.failTest(e);
96 // Return a failing promise.
97 return new Promise(function(resolve, reject) { reject(Error(e)); });
96 } 98 }
97 }; 99 };
98 100
99 PlayerUtils.registerPrefixedEMEEventListeners = function(player) { 101 PlayerUtils.registerPrefixedEMEEventListeners = function(player) {
100 player.video.addEventListener('webkitneedkey', function(message) { 102 player.video.addEventListener('webkitneedkey', function(message) {
101 var initData = message.initData; 103 var initData = message.initData;
102 if (player.testConfig.sessionToLoad) { 104 if (player.testConfig.sessionToLoad) {
103 Utils.timeLog('Loading session: ' + player.testConfig.sessionToLoad); 105 Utils.timeLog('Loading session: ' + player.testConfig.sessionToLoad);
104 initData = Utils.convertToUint8Array( 106 initData = Utils.convertToUint8Array(
105 PREFIXED_API_LOAD_SESSION_HEADER + player.testConfig.sessionToLoad); 107 PREFIXED_API_LOAD_SESSION_HEADER + player.testConfig.sessionToLoad);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 var mediaSource = 144 var mediaSource =
143 MediaSourceUtils.loadMediaSourceFromTestConfig(player.testConfig); 145 MediaSourceUtils.loadMediaSourceFromTestConfig(player.testConfig);
144 player.video.src = window.URL.createObjectURL(mediaSource); 146 player.video.src = window.URL.createObjectURL(mediaSource);
145 } else { 147 } else {
146 Utils.timeLog('Loading media using src.'); 148 Utils.timeLog('Loading media using src.');
147 player.video.src = player.testConfig.mediaFile; 149 player.video.src = player.testConfig.mediaFile;
148 } 150 }
149 }; 151 };
150 152
151 PlayerUtils.initEMEPlayer = function(player) { 153 PlayerUtils.initEMEPlayer = function(player) {
152 this.registerEMEEventListeners(player); 154 var promise = this.registerEMEEventListeners(player);
153 this.setVideoSource(player); 155 promise.then(function(result) { PlayerUtils.setVideoSource(player); })
156 .catch(function(error) { Utils.failTest(error, NOTSUPPORTEDERROR); });
154 }; 157 };
155 158
156 PlayerUtils.initPrefixedEMEPlayer = function(player) { 159 PlayerUtils.initPrefixedEMEPlayer = function(player) {
157 this.registerPrefixedEMEEventListeners(player); 160 this.registerPrefixedEMEEventListeners(player);
158 this.setVideoSource(player); 161 this.setVideoSource(player);
159 }; 162 };
160 163
161 // Return the appropriate player based on test configuration. 164 // Return the appropriate player based on test configuration.
162 PlayerUtils.createPlayer = function(video, testConfig) { 165 PlayerUtils.createPlayer = function(video, testConfig) {
163 // Update keySystem if using prefixed Clear Key since it is not available as a 166 // Update keySystem if using prefixed Clear Key since it is not available as a
(...skipping 21 matching lines...) Expand all
185 default: 188 default:
186 Utils.timeLog(keySystem + ' is not a known key system'); 189 Utils.timeLog(keySystem + ' is not a known key system');
187 if (usePrefixedEME) 190 if (usePrefixedEME)
188 return PrefixedClearKeyPlayer; 191 return PrefixedClearKeyPlayer;
189 return ClearKeyPlayer; 192 return ClearKeyPlayer;
190 } 193 }
191 } 194 }
192 var Player = getPlayerType(testConfig.keySystem); 195 var Player = getPlayerType(testConfig.keySystem);
193 return new Player(video, testConfig); 196 return new Player(video, testConfig);
194 }; 197 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698