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

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

Issue 405733003: Update browser tests to support upcoming EME parameter type changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 6 years, 4 months 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 | media/test/data/eme_player_js/widevine_player.js » ('j') | 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 // Utils provide logging functions and other JS functions commonly used by the 5 // Utils provide logging functions and other JS functions commonly used by the
6 // app and media players. 6 // app and media players.
7 var Utils = new function() { 7 var Utils = new function() {
8 this.titleChanged = false; 8 this.titleChanged = false;
9 }; 9 };
10 10
(...skipping 12 matching lines...) Expand all
23 } 23 }
24 }; 24 };
25 25
26 Utils.convertToArray = function(input) { 26 Utils.convertToArray = function(input) {
27 if (Array.isArray(input)) 27 if (Array.isArray(input))
28 return input; 28 return input;
29 return [input]; 29 return [input];
30 }; 30 };
31 31
32 Utils.convertToUint8Array = function(msg) { 32 Utils.convertToUint8Array = function(msg) {
33 var ans = new Uint8Array(msg.length); 33 if (typeof msg == 'string') {
34 for (var i = 0; i < msg.length; i++) { 34 var ans = new Uint8Array(msg.length);
35 ans[i] = msg.charCodeAt(i); 35 for (var i = 0; i < msg.length; i++) {
36 ans[i] = msg.charCodeAt(i);
37 }
38 return ans;
36 } 39 }
37 return ans; 40 // Assume it is an ArrayBuffer or ArrayBufferView. If it already is a
41 // Uint8Array, this will just make a copy of the view.
42 return new Uint8Array(msg);
38 }; 43 };
39 44
40 Utils.createJWKData = function(keyId, key) { 45 Utils.createJWKData = function(keyId, key) {
41 // JWK routines copied from third_party/WebKit/LayoutTests/media/ 46 // JWK routines copied from third_party/WebKit/LayoutTests/media/
42 // encrypted-media/encrypted-media-utils.js 47 // encrypted-media/encrypted-media-utils.js
43 // 48 //
44 // Encodes data (Uint8Array) into base64 string without trailing '='. 49 // Encodes data (Uint8Array) into base64 string without trailing '='.
45 // TODO(jrummell): Update once the EME spec is updated to say base64url 50 // TODO(jrummell): Update once the EME spec is updated to say base64url
46 // encoding. 51 // encoding.
47 function base64Encode(data) { 52 function base64Encode(data) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 for (var i = 0; i < uintArray.length; i++) { 148 for (var i = 0; i < uintArray.length; i++) {
144 var hex = uintArray[i].toString(16); 149 var hex = uintArray[i].toString(16);
145 if (hex.length == 1) 150 if (hex.length == 1)
146 hex = '0' + hex; 151 hex = '0' + hex;
147 hex_str += hex; 152 hex_str += hex;
148 } 153 }
149 return hex_str; 154 return hex_str;
150 }; 155 };
151 156
152 Utils.getInitDataFromMessage = function(message, mediaType) { 157 Utils.getInitDataFromMessage = function(message, mediaType) {
153 var initData = message.message; 158 var initData = Utils.convertToUint8Array(message.message);
154 if (mediaType.indexOf('mp4') != -1) { 159 if (mediaType.indexOf('mp4') != -1) {
155 // Temporary hack for Clear Key in v0.1. 160 // Temporary hack for Clear Key in v0.1.
156 // If content uses mp4, then message.message is PSSH data. Instead of 161 // If content uses mp4, then message.message is PSSH data. Instead of
157 // parsing that data we hard code the initData. 162 // parsing that data we hard code the initData.
158 initData = Utils.convertToUint8Array(KEY_ID); 163 initData = Utils.convertToUint8Array(KEY_ID);
159 } 164 }
160 return initData; 165 return initData;
161 }; 166 };
162 167
163 Utils.hasPrefix = function(msg, prefix) { 168 Utils.hasPrefix = function(msg, prefix) {
164 var message = String.fromCharCode.apply(null, msg); 169 var message = String.fromCharCode.apply(null, msg);
165 return message.substring(0, prefix.length) == prefix; 170 return message.substring(0, prefix.length) == prefix;
166 }; 171 };
167 172
168 Utils.installTitleEventHandler = function(element, event) { 173 Utils.installTitleEventHandler = function(element, event) {
169 element.addEventListener(event, function(e) { 174 element.addEventListener(event, function(e) {
170 Utils.setResultInTitle(e.type); 175 Utils.setResultInTitle(e.type);
171 }, false); 176 }, false);
172 }; 177 };
173 178
174 Utils.isHeartBeatMessage = function(msg) { 179 Utils.isHeartBeatMessage = function(msg) {
175 return Utils.hasPrefix(msg, HEART_BEAT_HEADER); 180 return Utils.hasPrefix(Utils.convertToUint8Array(msg), HEART_BEAT_HEADER);
176 }; 181 };
177 182
178 Utils.resetTitleChange = function() { 183 Utils.resetTitleChange = function() {
179 this.titleChanged = false; 184 this.titleChanged = false;
180 document.title = ''; 185 document.title = '';
181 }; 186 };
182 187
183 Utils.sendRequest = function(requestType, responseType, message, serverURL, 188 Utils.sendRequest = function(requestType, responseType, message, serverURL,
184 onSuccessCallbackFn, forceInvalidResponse) { 189 onSuccessCallbackFn, forceInvalidResponse) {
185 var requestAttemptCount = 0; 190 var requestAttemptCount = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 var time = Utils.getCurrentTimeString(); 241 var time = Utils.getCurrentTimeString();
237 // Log to document. 242 // Log to document.
238 Utils.documentLog(arguments[0], time); 243 Utils.documentLog(arguments[0], time);
239 // Log to JS console. 244 // Log to JS console.
240 var logString = time + ' - '; 245 var logString = time + ' - ';
241 for (var i = 0; i < arguments.length; i++) { 246 for (var i = 0; i < arguments.length; i++) {
242 logString += ' ' + arguments[i]; 247 logString += ' ' + arguments[i];
243 } 248 }
244 console.log(logString); 249 console.log(logString);
245 }; 250 };
OLDNEW
« no previous file with comments | « no previous file | media/test/data/eme_player_js/widevine_player.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698