| OLD | NEW |
| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |keys.expected| |
| 185 // and none of the keys in |keys.unexpected|. All keys should have status | 185 // and none of the keys in |keys.unexpected|. All expected keys should have |
| 186 // 'usable'. Example call: verifyKeyStatuses(mediaKeySession.keyStatuses, | 186 // status |status|. Example call: verifyKeyStatuses(mediaKeySession.keyStatuses, |
| 187 // { expected: [key1], unexpected: [key2] }); | 187 // { expected: [key1], unexpected: [key2] }, 'usable'); |
| 188 function verifyKeyStatuses(keyStatuses, keys) | 188 function verifyKeyStatuses(keyStatuses, keys, status) { |
| 189 { | 189 var expected = keys.expected || []; |
| 190 var expected = keys.expected || []; | 190 var unexpected = keys.unexpected || []; |
| 191 var unexpected = keys.unexpected || []; | 191 status = status || 'usable'; |
| 192 | 192 |
| 193 // |keyStatuses| should have same size as number of |keys.expected|. | 193 // |keyStatuses| should have same size as number of |keys.expected|. |
| 194 assert_equals(keyStatuses.size, expected.length); | 194 assert_equals(keyStatuses.size, expected.length); |
| 195 | 195 |
| 196 // All |keys.expected| should be found. | 196 // All |keys.expected| should be found. |
| 197 expected.map(function(key) { | 197 expected.map(function(key) { |
| 198 assert_true(keyStatuses.has(key)); | 198 assert_true(keyStatuses.has(key)); |
| 199 assert_equals(keyStatuses.get(key), 'usable'); | 199 assert_equals(keyStatuses.get(key), status); |
| 200 }); | 200 }); |
| 201 | 201 |
| 202 // All |keys.unexpected| should not be found. | 202 // All |keys.unexpected| should not be found. |
| 203 unexpected.map(function(key) { | 203 unexpected.map(function(key) { |
| 204 assert_false(keyStatuses.has(key)); | 204 assert_false(keyStatuses.has(key)); |
| 205 assert_equals(keyStatuses.get(key), undefined); | 205 assert_equals(keyStatuses.get(key), undefined); |
| 206 }); | 206 }); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Encodes |data| into base64url string. There is no '=' padding, and the | 209 // Encodes |data| into base64url string. There is no '=' padding, and the |
| 210 // characters '-' and '_' must be used instead of '+' and '/', respectively. | 210 // characters '-' and '_' must be used instead of '+' and '/', respectively. |
| 211 function base64urlEncode(data) | 211 function base64urlEncode(data) |
| 212 { | 212 { |
| 213 var result = btoa(String.fromCharCode.apply(null, data)); | 213 var result = btoa(String.fromCharCode.apply(null, data)); |
| 214 return result.replace(/=+$/g, '').replace(/\+/g, "-").replace(/\//g, "_"); | 214 return result.replace(/=+$/g, '').replace(/\+/g, "-").replace(/\//g, "_"); |
| 215 } | 215 } |
| 216 | 216 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 mediaKeys = result; | 307 mediaKeys = result; |
| 308 mediaKeySession = mediaKeys.createSession(); | 308 mediaKeySession = mediaKeys.createSession(); |
| 309 return mediaKeySession.generateRequest('keyids', request); | 309 return mediaKeySession.generateRequest('keyids', request); |
| 310 }).then(function() { | 310 }).then(function() { |
| 311 return mediaKeySession.update(jwkSet); | 311 return mediaKeySession.update(jwkSet); |
| 312 }).then(function() { | 312 }).then(function() { |
| 313 return Promise.resolve(mediaKeys); | 313 return Promise.resolve(mediaKeys); |
| 314 }); | 314 }); |
| 315 } | 315 } |
| 316 | 316 |
| 317 // Convert an event into a promise. When |event| is fired on |object|, |
| 318 // call |func| to handle the event and either resolve or reject the promise. |
| 319 // The event is only fired once. |
| 320 function waitForSingleEvent(object, event, func) { |
| 321 return new Promise(function(resolve, reject) { |
| 322 object.addEventListener(event, function listener(e) { |
| 323 object.removeEventListener(event, listener); |
| 324 func(e, resolve, reject); |
| 325 }); |
| 326 }); |
| 327 }; |
| 328 |
| 317 // Play the specified |content| on |video|. Returns a promise that is resolved | 329 // Play the specified |content| on |video|. Returns a promise that is resolved |
| 318 // after the video plays for |duration| seconds. | 330 // after the video plays for |duration| seconds. |
| 319 function playVideoAndWaitForTimeupdate(video, content, duration) | 331 function playVideoAndWaitForTimeupdate(video, content, duration) |
| 320 { | 332 { |
| 321 video.src = content; | 333 video.src = content; |
| 322 video.play(); | 334 video.play(); |
| 323 return new Promise(function(resolve) { | 335 return new Promise(function(resolve) { |
| 324 video.addEventListener('timeupdate', function listener(event) { | 336 video.addEventListener('timeupdate', function listener(event) { |
| 325 if (event.target.currentTime < duration) | 337 if (event.target.currentTime < duration) |
| 326 return; | 338 return; |
| 327 video.removeEventListener('timeupdate', listener); | 339 video.removeEventListener('timeupdate', listener); |
| 328 resolve('success'); | 340 resolve('success'); |
| 329 }); | 341 }); |
| 330 }); | 342 }); |
| 331 } | 343 } |
| 332 | 344 |
| 333 // Verifies that the number of existing MediaKey and MediaKeySession objects | 345 // Verifies that the number of existing MediaKey and MediaKeySession objects |
| 334 // match what is expected. | 346 // match what is expected. |
| 335 function verifyMediaKeyAndMediaKeySessionCount( | 347 function verifyMediaKeyAndMediaKeySessionCount( |
| 336 expectedMediaKeysCount, expectedMediaKeySessionCount, description) | 348 expectedMediaKeysCount, expectedMediaKeySessionCount, description) |
| 337 { | 349 { |
| 338 assert_equals(window.internals.mediaKeysCount(), | 350 assert_equals(window.internals.mediaKeysCount(), |
| 339 expectedMediaKeysCount, | 351 expectedMediaKeysCount, |
| 340 description + ', MediaKeys:'); | 352 description + ', MediaKeys:'); |
| 341 assert_equals(window.internals.mediaKeySessionCount(), | 353 assert_equals(window.internals.mediaKeySessionCount(), |
| 342 expectedMediaKeySessionCount, | 354 expectedMediaKeySessionCount, |
| 343 description + ', MediaKeySession:'); | 355 description + ', MediaKeySession:'); |
| 344 } | 356 } |
| OLD | NEW |