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

Side by Side 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 unified diff | Download patch
OLDNEW
1 var console = null; 1 var console = null;
2 2
3 function consoleWrite(text) 3 function consoleWrite(text)
4 { 4 {
5 if (!console && document.body) { 5 if (!console && document.body) {
6 console = document.createElement('div'); 6 console = document.createElement('div');
7 document.body.appendChild(console); 7 document.body.appendChild(console);
8 } 8 }
9 var span = document.createElement('span'); 9 var span = document.createElement('span');
10 span.appendChild(document.createTextNode(text)); 10 span.appendChild(document.createTextNode(text));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // currently no way to report a failed test in the test harness, errors 116 // currently no way to report a failed test in the test harness, errors
117 // are reported using force_timeout(). 117 // are reported using force_timeout().
118 if (message) 118 if (message)
119 consoleWrite(message + ': ' + error.message); 119 consoleWrite(message + ': ' + error.message);
120 else if (error) 120 else if (error)
121 consoleWrite(error.message); 121 consoleWrite(error.message);
122 122
123 test.force_timeout(); 123 test.force_timeout();
124 test.done(); 124 test.done();
125 } 125 }
126
127 function extractSingleKeyIdFromMessage(message)
128 {
129 try {
130 var json = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(mes sage)));
131 // Decode the first element of 'kids'.
132 // FIXME: Switch to base64url. See
133 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/en crypted-media.html#using-base64url
134 assert_equals(1, json.kids.length);
135 var decoded_key = atob(json.kids[0]);
136 // Convert to an Uint8Array and return it.
137 return stringToUint8Array(decoded_key);
138 }
139 catch (o) {
140 // Not valid JSON, so return message untouched as Uint8Array.
141 // This is for backwards compatibility.
142 // FIXME: Remove this once the code is switched to return JSON all
143 // the time.
144 return new Uint8Array(message);
145 }
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698