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

Unified Diff: chrome/test/data/media/eme_player_js/utils.js

Issue 308553002: Integrate browser tests with new EME player. (Closed) Base URL: http://git.chromium.org/chromium/src.git@eme_player
Patch Set: Add support for FileIO and LoadSession test cases Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/media/eme_player_js/utils.js
diff --git a/chrome/test/data/media/eme_player_js/utils.js b/chrome/test/data/media/eme_player_js/utils.js
index e9ecd2de6347f0903cc1557ae400852e35753235..f19abce925625563a965afef8cd8bcc800b0350d 100644
--- a/chrome/test/data/media/eme_player_js/utils.js
+++ b/chrome/test/data/media/eme_player_js/utils.js
@@ -5,11 +5,18 @@
// Utils provide logging functions and other JS functions commonly used by the
// app and media players.
var Utils = new function() {
-}
+ this.titleChanged = false;
+};
-Utils.isHeartBeatMessage = function(msg) {
- var message = String.fromCharCode.apply(null, msg);
- return message.substring(0, HEART_BEAT_HEADER.length) == HEART_BEAT_HEADER;
+// Adds options to document element.
+Utils.addOptions = function(elementID, keyValueOptions) {
+ var selectElement = document.getElementById(elementID);
+ var keys = Object.keys(keyValueOptions);
+ for (var i = 0; i < keys.length; i++) {
+ var option = new Option(keys[i], keyValueOptions[keys[i]]);
+ option.title = keyValueOptions[keys[i]];
+ selectElement.options.add(option);
+ }
};
Utils.convertToArray = function(input) {
@@ -18,17 +25,6 @@ Utils.convertToArray = function(input) {
return [input];
};
-Utils.getHexString = function(uintArray) {
- var hex_str = '';
- for (var i = 0; i < uintArray.length; i++) {
- var hex = uintArray[i].toString(16);
- if (hex.length == 1)
- hex = '0' + hex;
- hex_str += hex;
- }
- return hex_str;
-};
-
Utils.convertToUint8Array = function(msg) {
var ans = new Uint8Array(msg.length);
for (var i = 0; i < msg.length; i++) {
@@ -37,81 +33,6 @@ Utils.convertToUint8Array = function(msg) {
return ans;
};
-Utils.timeLog = function(/**/) {
- function documentLog(time, log) {
- var time = '<span style="color: green">' + time + '</span>';
- docLogs.innerHTML = time + ' - ' + log + '<br>' + docLogs.innerHTML;
- }
-
- if (arguments.length == 0)
- return;
- var time = Utils.getCurrentTimeString();
- // Log to document.
- documentLog(time, arguments[0]);
-
- // Log to JS console.
- var args = [];
- args.push(time + ' - ');
- for (var i = 0; i < arguments.length; i++) {
- args.push(arguments[i]);
- }
- console.log.apply(console, args);
-};
-
-Utils.getCurrentTimeString = function() {
- var date = new Date();
- var hours = ('0' + date.getHours()).slice(-2);
- var minutes = ('0' + date.getMinutes()).slice(-2);
- var secs = ('0' + date.getSeconds()).slice(-2);
- var milliSecs = ('00' + date.getMilliseconds()).slice(-3);
- return hours + ':' + minutes + ':' + secs + '.' + milliSecs;
-};
-
-Utils.failTest = function(msg) {
- var failMessage = 'FAIL: ';
- // Handle exception messages;
- if (msg.message) {
- failMessage += msg.name ? msg.name : 'Error ';
- failMessage += msg.message;
- }
- // Handle failing events.
- else if (msg instanceof Event)
- failMessage = msg.target + '.' + msg.type;
- else
- failMessage = msg;
- Utils.timeLog('<span style="color: red">' + failMessage + '</span>', msg);
-};
-
-Utils.sendRequest = function(requestType, responseType, message, serverURL,
- onSuccessCallbackFn) {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.responseType = responseType;
- xmlhttp.open(requestType, serverURL, true);
-
- xmlhttp.onload = function(e) {
- if (this.status == 200) {
- if (onSuccessCallbackFn)
- onSuccessCallbackFn(this.response);
- } else {
- Utils.timeLog('Bad response status: ' + this.status);
- Utils.timeLog('Bad response: ' + this.response);
- }
- };
- Utils.timeLog('Sending request to server: ' + serverURL);
- xmlhttp.send(message);
-};
-
-// Adds options to document element.
-Utils.addOptions = function(elementID, keyValueOptions) {
- var selectElement = document.getElementById(elementID);
- var keys = Object.keys(keyValueOptions);
- for (var i = 0; i < keys.length; i++) {
- var option = new Option(keys[i], keyValueOptions[keys[i]]);
- option.title = keyValueOptions[keys[i]];
- selectElement.options.add(option);
- }
-};
-
Utils.createJWKData = function(keyId, key) {
// JWK routines copied from third_party/WebKit/LayoutTests/media/
// encrypted-media/encrypted-media-utils.js
@@ -148,3 +69,180 @@ Utils.createJWKData = function(keyId, key) {
return Utils.convertToUint8Array(createJWKSet(createJWK(keyId, key)));
};
+
+Utils.documentLog = function(log, success, time) {
+ if (!docLogs)
+ return;
+ time = time || Utils.getCurrentTimeString();
+ var timeLog = '<span style="color: green">' + time + '</span>';
+ var logColor = !success ? 'red' : 'black'; // default is true.
+ log = '<span style="color: "' + logColor + '>' + log + '</span>';
+ docLogs.innerHTML = timeLog + ' - ' + log + '<br>' + docLogs.innerHTML;
+};
+
+Utils.ensureOptionInList = function(listID, option) {
+ var selectElement = document.getElementById(listID);
+ for (var i = 0; i < selectElement.length; i++) {
+ if (selectElement.options[i].value == option) {
+ selectElement.value = option;
+ return;
+ }
+ }
+ // The list does not have the option, let's add it and select it.
+ var optionElement = new Option(option, option);
+ optionElement.title = option;
+ selectElement.options.add(optionElement);
+ selectElement.value = option;
+};
+
+Utils.failTest = function(msg, newTitle) {
+ var failMessage = 'FAIL: ';
+ var title = 'FAILED';
+ // Handle exception messages;
+ if (msg.message) {
+ failMessage += (msg.name || 'Error') + ' ' + msg.message;
+ title = msg.name;
jrummell 2014/06/13 21:53:59 Do you need || 'Error' here as well? Or +=?
shadi 2014/06/19 01:07:04 Done.
+ } else if (msg instanceof Event) {
+ // Handle failing events.
+ failMessage = msg.target + '.' + msg.type;
+ title = msg.type;
+ } else {
+ failMessage += msg;
+ }
+ // Force newTitle if passed.
+ title = newTitle || title;
+ // Log failure.
+ Utils.documentLog(failMessage, false);
+ console.log(failMessage, msg);
+ Utils.setResultInTitle(title);
+};
+
+Utils.getCurrentTimeString = function() {
+ var date = new Date();
+ var hours = ('0' + date.getHours()).slice(-2);
+ var minutes = ('0' + date.getMinutes()).slice(-2);
+ var secs = ('0' + date.getSeconds()).slice(-2);
+ var milliSecs = ('00' + date.getMilliseconds()).slice(-3);
+ return hours + ':' + minutes + ':' + secs + '.' + milliSecs;
+};
+
+Utils.getDefaultKey = function(forceInvalidResponse) {
+ if (forceInvalidResponse) {
+ Utils.timeLog('Forcing invalid key data.');
+ return new Uint8Array([0xAA]);
+ }
+ return KEY;
+};
+
+Utils.getHexString = function(uintArray) {
+ var hex_str = '';
+ for (var i = 0; i < uintArray.length; i++) {
+ var hex = uintArray[i].toString(16);
+ if (hex.length == 1)
+ hex = '0' + hex;
+ hex_str += hex;
+ }
+ return hex_str;
+};
+
+Utils.getInitDataFromMessage = function(message, mediaType) {
+ var initData = message.message;
+ if (mediaType.indexOf('mp4') != -1) {
+ // Temporary hack for Clear Key in v0.1.
+ // If content uses mp4, then message.message is PSSH data. Instead of
+ // parsing that data we hard code the initData.
+ initData = Utils.convertToUint8Array(KEY_ID);
+ }
+ return initData;
+};
+
+Utils.hasPrefix = function(msg, prefix) {
jrummell 2014/06/13 21:53:59 I think it would be simpler to use the code from i
shadi 2014/06/19 01:07:04 Done.
+ if (msg.length < prefix.length)
+ return false;
+ for (var i = 0; i < prefix.length; ++i) {
+ if (String.fromCharCode(msg[i]) != prefix[i])
+ return false;
+ }
+ return true;
+};
+
+Utils.installTitleEventHandler = function(element, event) {
+ element.addEventListener(event, function(e) {
+ Utils.setResultInTitle(e.type);
+ }, false);
+};
+
+Utils.isHeartBeatMessage = function(msg) {
+ var message = String.fromCharCode.apply(null, msg);
+ return message.substring(0, HEART_BEAT_HEADER.length) == HEART_BEAT_HEADER;
+};
+
+Utils.resetTitleChange = function() {
+ this.titleChanged = false;
+ document.title = '';
+};
+
+Utils.sendRequest = function(requestType, responseType, message, serverURL,
+ onSuccessCallbackFn, forceInvalidResponse) {
+ var requestAttemptCount = 0;
+ var MAXIMUM_REQUEST_ATTEMPTS = 3;
+ var REQUEST_RETRY_DELAY_MS = 3000;
+
+ function sendRequestAttempt() {
+ requestAttemptCount++;
+ if (requestAttemptCount == MAXIMUM_REQUEST_ATTEMPTS) {
+ Utils.failTest('FAILED: Exceeded maximum license request attempts.');
+ return;
+ }
+
+ var xmlhttp = new XMLHttpRequest();
+ xmlhttp.responseType = responseType;
+ xmlhttp.open(requestType, serverURL, true);
+
+ xmlhttp.onload = function(e) {
+ if (this.status == 200) {
+ if (onSuccessCallbackFn)
+ onSuccessCallbackFn(this.response);
+ } else {
+ Utils.timeLog('Bad response status: ' + this.status);
+ Utils.timeLog('Bad response: ' + this.response);
+ Utils.timeLog('Retrying request if possible in ' +
+ LICENSE_REQUEST_RETRY_DELAY_MS + 'ms');
+ setTimeout(sendRequestAttempt, LICENSE_REQUEST_RETRY_DELAY_MS);
+ }
+ };
+ Utils.timeLog('Attempt (' + requestAttemptCount +
+ '): sending request to server: ' + serverURL);
+ xmlhttp.send(message);
+ }
+
+ if (forceInvalidResponse) {
+ Utils.timeLog('Not sending request - forcing an invalid response.');
+ return onSuccessCallbackFn([0xAA]);
+ }
+ sendRequestAttempt();
+};
+
+Utils.setResultInTitle = function(title) {
+ // If document title is 'ENDED', then update it with new title to possibly
+ // mark a test as failure. Otherwise, keep the first title change in place.
+ if (!this.titleChanged || document.title.toUpperCase() == 'ENDED')
+ document.title = title.toUpperCase();
+ Utils.timeLog('Set document title to: ' + title + ', updated title: ' +
+ document.title);
+ this.titleChanged = true;
+};
+
+Utils.timeLog = function(/**/) {
+ if (arguments.length == 0)
+ return;
+ var time = Utils.getCurrentTimeString();
+ // Log to document.
+ Utils.documentLog(arguments[0], time);
+ // Log to JS console.
+ var logString = time + ' - ';
+ for (var i = 0; i < arguments.length; i++) {
+ logString += ' ' + arguments[i];
+ }
+ console.log(logString);
+};

Powered by Google App Engine
This is Rietveld 408576698