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

Side by Side Diff: LayoutTests/media/encrypted-media/encrypted-media-utils.js

Issue 880313003: Add additional layout tests for MediaKeySession.keyStatuses (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: more js Created 5 years, 10 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return result; 102 return result;
103 } 103 }
104 104
105 function arrayBufferAsString(buffer) 105 function arrayBufferAsString(buffer)
106 { 106 {
107 // MediaKeySession.keyStatuses iterators return an ArrayBuffer, 107 // MediaKeySession.keyStatuses iterators return an ArrayBuffer,
108 // so convert it into a printable string. 108 // so convert it into a printable string.
109 return String.fromCharCode.apply(null, new Uint8Array(buffer)); 109 return String.fromCharCode.apply(null, new Uint8Array(buffer));
110 } 110 }
111 111
112 function dumpKeyStatuses(keyStatuses)
113 {
114 consoleWrite("for (var entry of keyStatuses)");
115 for (var entry of keyStatuses) {
116 consoleWrite(arrayBufferAsString(entry[0]) + ", " + entry[1]);
117 }
118 consoleWrite("for (var key of keyStatuses.keys())");
119 for (var key of keyStatuses.keys()) {
120 consoleWrite(arrayBufferAsString(key));
121 }
122 consoleWrite("for (var value of keyStatuses.values())");
123 for (var value of keyStatuses.values()) {
124 consoleWrite(value);
125 }
126 consoleWrite("for (var entry of keyStatuses.entries())");
127 for (var entry of keyStatuses.entries()) {
128 consoleWrite(arrayBufferAsString(entry[0]) + ", " + entry[1]);
129 }
130 consoleWrite("keyStatuses.forEach()");
131 keyStatuses.forEach(function(value, key, map) {
132 consoleWrite(arrayBufferAsString(key) + ", " + value);
133 });
134 }
135
136 // Verify that |keyStatuses| contains just the keys in |keys.expected|
137 // and none of the keys in |keys.unexpected|. All keys should have status
138 // 'usable'. Example call: verifyKeyStatuses(mediaKeySession.keyStatuses,
139 // { expected: [key1], unexpected: [key2] });
140 function verifyKeyStatuses(keyStatuses, keys)
141 {
142 var expected = keys.expected || [];
143 var unexpected = keys.unexpected || [];
144
145 // |keyStatuses| should have same size as number of |keys.expected|.
146 assert_equals(keyStatuses.size, expected.length);
147
148 // All |keys.expected| should be found.
149 expected.map(function(key) {
150 assert_true(keyStatuses.has(key));
151 assert_equals(keyStatuses.get(key), 'usable');
152 });
153
154 // All |keys.unexpected| should not be found.
155 unexpected.map(function(key) {
156 assert_false(keyStatuses.has(key));
157 assert_equals(keyStatuses.get(key), undefined);
158 });
159 }
160
112 // Encodes data into base64 string without trailing '='. 161 // Encodes data into base64 string without trailing '='.
113 function base64Encode(data) 162 function base64Encode(data)
114 { 163 {
115 var result = btoa(String.fromCharCode.apply(null, data)); 164 var result = btoa(String.fromCharCode.apply(null, data));
116 return result.replace(/=+$/g, ''); 165 return result.replace(/=+$/g, '');
117 } 166 }
118 167
119 // For Clear Key, the License Format is a JSON Web Key (JWK) Set, which contains 168 // For Clear Key, the License Format is a JSON Web Key (JWK) Set, which contains
120 // a set of cryptographic keys represented by JSON. These helper functions help 169 // a set of cryptographic keys represented by JSON. These helper functions help
121 // wrap raw keys into a JWK set. 170 // wrap raw keys into a JWK set.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 return stringToUint8Array(decoded_key); 225 return stringToUint8Array(decoded_key);
177 } 226 }
178 catch (o) { 227 catch (o) {
179 // Not valid JSON, so return message untouched as Uint8Array. 228 // Not valid JSON, so return message untouched as Uint8Array.
180 // This is for backwards compatibility. 229 // This is for backwards compatibility.
181 // FIXME: Remove this once the code is switched to return JSON all 230 // FIXME: Remove this once the code is switched to return JSON all
182 // the time. 231 // the time.
183 return new Uint8Array(message); 232 return new Uint8Array(message);
184 } 233 }
185 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698