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

Unified Diff: LayoutTests/media/encrypted-media/encrypted-media-utils.js

Issue 429033003: Allow JSON messages to be returned for ClearKey. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: extractSingleKeyIdFromMessage 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/media/encrypted-media/encrypted-media-utils.js
diff --git a/LayoutTests/media/encrypted-media/encrypted-media-utils.js b/LayoutTests/media/encrypted-media/encrypted-media-utils.js
index ed59afe2881e47190e86f15365f91b7ab7d90c78..a91023926f119eaab05070103c33f55359286d26 100644
--- a/LayoutTests/media/encrypted-media/encrypted-media-utils.js
+++ b/LayoutTests/media/encrypted-media/encrypted-media-utils.js
@@ -123,3 +123,24 @@ function forceTestFailureFromPromise(test, error, message)
test.force_timeout();
test.done();
}
+
+function extractSingleKeyIdFromMessage(message)
+{
+ try {
+ var json = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(message)));
+ // Decode the first element of 'kids'.
+ // FIXME: Switch to base64url. See
+ // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#using-base64url
+ assert_equals(1, json.kids.length);
+ var decoded_key = atob(json.kids[0]);
+ // Convert to an Uint8Array and return it.
+ return stringToUint8Array(decoded_key);
+ }
+ catch (o) {
+ // Not valid JSON, so return message untouched as Uint8Array.
+ // This is for backwards compatibility.
+ // FIXME: Remove this once the code is switched to return JSON all
+ // the time.
+ return new Uint8Array(message);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698