Skip to content

Commit

Permalink
Update browser tests to support upcoming EME parameter type changes.
Browse files Browse the repository at this point in the history
The EME spec is now using ArrayBuffer/ArrayBufferView instead of
Uint8Array as the type for data buffers. Calls from JavaScript
aren't affected as Uint8Array is an ArrayBufferView. However,
"message" events now pass back an ArrayBuffer and the tests expect
Uint8Array. This converts the returned message to a Uint8Array
to keep the code working.

This change works with and without the upcoming changes. If
Uint8Array is passed back, then the result is that another copy of
the view is made.

BUG=358271
TEST=encrypted media browser_tests pass

Review URL: https://codereview.chromium.org/405733003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285672 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jrummell@chromium.org committed Jul 25, 2014
1 parent 62bcec5 commit 80ae1b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
17 changes: 11 additions & 6 deletions media/test/data/eme_player_js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ Utils.convertToArray = function(input) {
};

Utils.convertToUint8Array = function(msg) {
var ans = new Uint8Array(msg.length);
for (var i = 0; i < msg.length; i++) {
ans[i] = msg.charCodeAt(i);
if (typeof msg == 'string') {
var ans = new Uint8Array(msg.length);
for (var i = 0; i < msg.length; i++) {
ans[i] = msg.charCodeAt(i);
}
return ans;
}
return ans;
// Assume it is an ArrayBuffer or ArrayBufferView. If it already is a
// Uint8Array, this will just make a copy of the view.
return new Uint8Array(msg);
};

Utils.createJWKData = function(keyId, key) {
Expand Down Expand Up @@ -150,7 +155,7 @@ Utils.getHexString = function(uintArray) {
};

Utils.getInitDataFromMessage = function(message, mediaType) {
var initData = message.message;
var initData = Utils.convertToUint8Array(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
Expand All @@ -172,7 +177,7 @@ Utils.installTitleEventHandler = function(element, event) {
};

Utils.isHeartBeatMessage = function(msg) {
return Utils.hasPrefix(msg, HEART_BEAT_HEADER);
return Utils.hasPrefix(Utils.convertToUint8Array(msg), HEART_BEAT_HEADER);
};

Utils.resetTitleChange = function() {
Expand Down
7 changes: 5 additions & 2 deletions media/test/data/eme_player_js/widevine_player.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ WidevinePlayer.prototype.onMessage = function(message) {
}

}
Utils.sendRequest('POST', 'arraybuffer', message.message,
this.testConfig.licenseServerURL, onSuccess,
Utils.sendRequest('POST',
'arraybuffer',
Utils.convertToUint8Array(message.message),
this.testConfig.licenseServerURL,
onSuccess,
this.testConfig.forceInvalidResponse);
};

0 comments on commit 80ae1b9

Please sign in to comment.