| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Test the play() behaviour with regards to the returned promise for media
elements.</title> | 2 <title>Test the play() behaviour with regards to the returned promise for media
elements.</title> |
| 3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="media-file.js"></script> | 5 <script src="media-file.js"></script> |
| 6 <script> | 6 <script> |
| 7 // This is testing the behavior of play() with regards to the returned | 7 // This is testing the behavior of play() with regards to the returned |
| 8 // promise. This test file is creating a small framework in order to be able | 8 // promise. This test file is creating a small framework in order to be able |
| 9 // to test different cases easily and independently of each other. | 9 // to test different cases easily and independently of each other. |
| 10 // All tests have to be part of the tests and testsWithUserGesture arrays. | 10 // All tests have to be part of the tests and testsWithUserGesture arrays. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 audio.onplaying = t.step_func(function() { | 213 audio.onplaying = t.step_func(function() { |
| 214 assert_equals(audio.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA); | 214 assert_equals(audio.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA); |
| 215 assert_false(audio.paused); | 215 assert_false(audio.paused); |
| 216 audio.pause(); | 216 audio.pause(); |
| 217 playExpectingResolvedPromise(t, audio); | 217 playExpectingResolvedPromise(t, audio); |
| 218 }); | 218 }); |
| 219 | 219 |
| 220 audio.oncanplaythrough = t.step_func(function() { | 220 audio.oncanplaythrough = t.step_func(function() { |
| 221 audio.play(); | 221 audio.play(); |
| 222 }); | 222 }); |
| 223 } | 223 }, |
| 224 |
| 225 // Test that running the load algorithm will not drop all the promises about |
| 226 // to be resolved. |
| 227 function loadAlgorithmDoesNotCancelTasks(t, audio) { |
| 228 audio.src = findMediaFile('audio', 'content/test'); |
| 229 audio.addEventListener('canplaythrough', t.step_func(function() { |
| 230 // The play() promise will be queued to be resolved. |
| 231 playExpectingResolvedPromise(t, audio); |
| 232 audio.src = findMediaFile('audio', 'content/test'); |
| 233 assert_true(audio.paused); |
| 234 })); |
| 235 }, |
| 236 |
| 237 // Test that when the load algorithm is run, if it does not pause the |
| 238 // playback, it will leave the promise pending, allowing it to be resolved. |
| 239 function loadAlgorithmKeepPromisesPendingWhenNotPausing(t, audio) { |
| 240 playExpectingResolvedPromise(t, audio); |
| 241 setTimeout(_ => audio.src = findMediaFile('audio', 'content/test'), 0); |
| 242 assert_false(audio.paused); |
| 243 }, |
| 244 |
| 245 // Test that when the load algorithm is run, if it does not pause the |
| 246 // playback, it will leave the promise pending, allowing it to be resolved |
| 247 // (version with preload='none'). |
| 248 // TODO(mlamouri): there is a bug in Blink where the media element ends up |
| 249 // in a broken state, see https://crbug.com/633591 |
| 250 // function loadAlgorithmKeepPromisesPendingWhenNotPausingAndPreloadNone(t,
audio) { |
| 251 // audio.preload = 'none'; |
| 252 // playExpectingRejectedPromise(t, audio, 'AbortError'); |
| 253 // setTimeout(_ => audio.src = findMediaFile('audio', 'content/test'), 0
); |
| 254 // }, |
| 255 |
| 256 // Test that when the load algorithm is run, if it does pause the playback, |
| 257 // it will reject the pending promises. |
| 258 function loadAlgorithmRejectPromisesWhenPausing(t, audio) { |
| 259 playExpectingRejectedPromise(t, audio, 'AbortError'); |
| 260 audio.src = findMediaFile('audio', 'content/test'); |
| 261 assert_true(audio.paused); |
| 262 }, |
| 263 |
| 264 // Test that when the load algorithm is run, if it does pause the playback, |
| 265 // it will reject the pending promises (version with preload='none'). |
| 266 function loadAlgorithmRejectPromisesWhenPausingAndPreloadNone(t, audio) { |
| 267 audio.preload = 'none'; |
| 268 playExpectingRejectedPromise(t, audio, 'AbortError'); |
| 269 audio.src = findMediaFile('audio', 'content/test'); |
| 270 assert_true(audio.paused); |
| 271 }, |
| 224 ]; | 272 ]; |
| 225 | 273 |
| 226 tests.forEach(function(test) { | 274 tests.forEach(function(test) { |
| 227 internals.settings.setMediaPlaybackRequiresUserGesture(false); | 275 internals.settings.setMediaPlaybackRequiresUserGesture(false); |
| 228 async_test(function(t) { | 276 async_test(function(t) { |
| 229 var audio = document.createElement("audio"); | 277 var audio = document.createElement("audio"); |
| 230 test(t, audio); | 278 test(t, audio); |
| 231 }, test.name); | 279 }, test.name); |
| 232 }); | 280 }); |
| 233 | 281 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 319 |
| 272 function playWithUserGesture(t, audio) { | 320 function playWithUserGesture(t, audio) { |
| 273 document.onclick = function() { | 321 document.onclick = function() { |
| 274 playExpectingResolvedPromise(t, audio); | 322 playExpectingResolvedPromise(t, audio); |
| 275 document.onclick = null; | 323 document.onclick = null; |
| 276 }; | 324 }; |
| 277 | 325 |
| 278 eventSender.mouseDown(); | 326 eventSender.mouseDown(); |
| 279 eventSender.mouseUp(); | 327 eventSender.mouseUp(); |
| 280 } | 328 } |
| 281 </script> | 329 </script> |
| OLD | NEW |