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

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

Issue 2847803005: Cleanup verifyKeyStatuses() to take KeyId/status pairs (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-session-remove-temporary.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var consoleDiv = null; 1 var consoleDiv = null;
2 2
3 function consoleWrite(text) 3 function consoleWrite(text)
4 { 4 {
5 if (!consoleDiv && document.body) { 5 if (!consoleDiv && document.body) {
6 consoleDiv = document.createElement('div'); 6 consoleDiv = document.createElement('div');
7 document.body.appendChild(consoleDiv); 7 document.body.appendChild(consoleDiv);
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 consoleWrite("for (var entry of keyStatuses.entries())"); 174 consoleWrite("for (var entry of keyStatuses.entries())");
175 for (var entry of keyStatuses.entries()) { 175 for (var entry of keyStatuses.entries()) {
176 consoleWrite(arrayBufferAsString(entry[0]) + ": " + entry[1]); 176 consoleWrite(arrayBufferAsString(entry[0]) + ": " + entry[1]);
177 } 177 }
178 consoleWrite("keyStatuses.forEach()"); 178 consoleWrite("keyStatuses.forEach()");
179 keyStatuses.forEach(function(status, keyId) { 179 keyStatuses.forEach(function(status, keyId) {
180 consoleWrite(arrayBufferAsString(keyId) + ": " + status); 180 consoleWrite(arrayBufferAsString(keyId) + ": " + status);
181 }); 181 });
182 } 182 }
183 183
184 // Verify that |keyStatuses| contains just the keys in |keys.expected| 184 // Verify that |keyStatuses| contains just the keys in the array |expected|.
185 // and none of the keys in |keys.unexpected|. All expected keys should have 185 // Each entry specifies the keyId and status expected.
186 // status |status|. Example call: verifyKeyStatuses(mediaKeySession.keyStatuses, 186 // Example call: verifyKeyStatuses(mediaKeySession.keyStatuses,
187 // { expected: [key1], unexpected: [key2] }, 'usable'); 187 // [{keyId: key1, status: 'usable'}, {keyId: key2, status: 'released'}]);
188 function verifyKeyStatuses(keyStatuses, keys, status) { 188 function verifyKeyStatuses(keyStatuses, expected) {
189 var expected = keys.expected || [];
190 var unexpected = keys.unexpected || [];
191 status = status || 'usable';
192
193 // |keyStatuses| should have same size as number of |keys.expected|. 189 // |keyStatuses| should have same size as number of |keys.expected|.
194 assert_equals(keyStatuses.size, expected.length); 190 assert_equals(keyStatuses.size, expected.length);
195 191
196 // All |keys.expected| should be found. 192 // All |expected| should be found.
197 expected.map(function(key) { 193 expected.map(function(item) {
198 assert_true(keyStatuses.has(key)); 194 assert_true(keyStatuses.has(item.keyId));
199 assert_equals(keyStatuses.get(key), status); 195 assert_equals(keyStatuses.get(item.keyId), item.status);
200 });
201
202 // All |keys.unexpected| should not be found.
203 unexpected.map(function(key) {
204 assert_false(keyStatuses.has(key));
205 assert_equals(keyStatuses.get(key), undefined);
206 }); 196 });
207 } 197 }
208 198
209 // Encodes |data| into base64url string. There is no '=' padding, and the 199 // Encodes |data| into base64url string. There is no '=' padding, and the
210 // characters '-' and '_' must be used instead of '+' and '/', respectively. 200 // characters '-' and '_' must be used instead of '+' and '/', respectively.
211 function base64urlEncode(data) 201 function base64urlEncode(data)
212 { 202 {
213 var result = btoa(String.fromCharCode.apply(null, data)); 203 var result = btoa(String.fromCharCode.apply(null, data));
214 return result.replace(/=+$/g, '').replace(/\+/g, "-").replace(/\//g, "_"); 204 return result.replace(/=+$/g, '').replace(/\+/g, "-").replace(/\//g, "_");
215 } 205 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 function verifyMediaKeyAndMediaKeySessionCount( 337 function verifyMediaKeyAndMediaKeySessionCount(
348 expectedMediaKeysCount, expectedMediaKeySessionCount, description) 338 expectedMediaKeysCount, expectedMediaKeySessionCount, description)
349 { 339 {
350 assert_equals(window.internals.mediaKeysCount(), 340 assert_equals(window.internals.mediaKeysCount(),
351 expectedMediaKeysCount, 341 expectedMediaKeysCount,
352 description + ', MediaKeys:'); 342 description + ', MediaKeys:');
353 assert_equals(window.internals.mediaKeySessionCount(), 343 assert_equals(window.internals.mediaKeySessionCount(),
354 expectedMediaKeySessionCount, 344 expectedMediaKeySessionCount,
355 description + ', MediaKeySession:'); 345 description + ', MediaKeySession:');
356 } 346 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/media/encrypted-media/encrypted-media-session-remove-temporary.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698