| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src=media-file.js></script> | 3 <script src=media-file.js></script> |
| 4 <!-- TODO(mlamouri): use testharness.js, see https://crbug.com/588956 --> | 4 <!-- TODO(mlamouri): use testharness.js, see https://crbug.com/588956 --> |
| 5 <script src=video-test.js></script> | 5 <script src=video-test.js></script> |
| 6 | 6 |
| 7 <script> | 7 <script> |
| 8 // This is testing the behavior of play() with regards to the returned | 8 // This is testing the behavior of play() with regards to the returned |
| 9 // promise. This test file is creating a small framework in order to be able | 9 // promise. This test file is creating a small framework in order to be able |
| 10 // to test different cases easily and independently of each other. | 10 // to test different cases easily and independently of each other. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // Assuming running in Blink LayoutTests. | 58 // Assuming running in Blink LayoutTests. |
| 59 eventSender.mouseMoveTo(x, y); | 59 eventSender.mouseMoveTo(x, y); |
| 60 eventSender.mouseDown(); | 60 eventSender.mouseDown(); |
| 61 eventSender.mouseUp(); | 61 eventSender.mouseUp(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 var currentTest = -1; | 64 var currentTest = -1; |
| 65 | 65 |
| 66 var TESTS = [ | 66 var TESTS = [ |
| 67 // Test that play() on an element that doesn't have enough data will | 67 // Test that play() on an element that doesn't have enough data will |
| 68 // return a promise that resolves successfuly. | 68 // return a promise that resolves successfully. |
| 69 function playBeforeCanPlay() | 69 function playBeforeCanPlay() |
| 70 { | 70 { |
| 71 consoleWrite("playBeforeCanPlay()"); | 71 consoleWrite("playBeforeCanPlay()"); |
| 72 internals.settings.setMediaPlaybackRequiresUserGesture(false); | 72 internals.settings.setMediaPlaybackRequiresUserGesture(false); |
| 73 | 73 |
| 74 run("mediaElement = document.createElement('audio')"); | 74 run("mediaElement = document.createElement('audio')"); |
| 75 var mediaFile = findMediaFile("audio", "content/test"); | 75 var mediaFile = findMediaFile("audio", "content/test"); |
| 76 run("mediaElement.src = '" + mediaFile + "'"); | 76 run("mediaElement.src = '" + mediaFile + "'"); |
| 77 | 77 |
| 78 waitForEvent('loadedmetadata'); | 78 waitForEvent('loadedmetadata'); |
| 79 waitForEvent('loadeddata'); | 79 waitForEvent('loadeddata'); |
| 80 waitForEvent('canplay'); | 80 waitForEvent('canplay'); |
| 81 waitForEvent('playing'); | 81 waitForEvent('playing'); |
| 82 | 82 |
| 83 testExpected("mediaElement.readyState", HTMLMediaElement.HAVE_NOTHIN
G); | 83 testExpected("mediaElement.readyState", HTMLMediaElement.HAVE_NOTHIN
G); |
| 84 play(); | 84 play(); |
| 85 }, | 85 }, |
| 86 | 86 |
| 87 // Test that play() on an element that has enough data will return a | 87 // Test that play() on an element that has enough data will return a |
| 88 // promise that resolves successfuly. | 88 // promise that resolves successfully. |
| 89 function playWhenCanPlay() | 89 function playWhenCanPlay() |
| 90 { | 90 { |
| 91 consoleWrite("playWhenCanPlay()"); | 91 consoleWrite("playWhenCanPlay()"); |
| 92 internals.settings.setMediaPlaybackRequiresUserGesture(false); | 92 internals.settings.setMediaPlaybackRequiresUserGesture(false); |
| 93 | 93 |
| 94 run("mediaElement = document.createElement('audio')"); | 94 run("mediaElement = document.createElement('audio')"); |
| 95 var mediaFile = findMediaFile("audio", "content/test"); | 95 var mediaFile = findMediaFile("audio", "content/test"); |
| 96 run("mediaElement.src = '" + mediaFile + "'"); | 96 run("mediaElement.src = '" + mediaFile + "'"); |
| 97 | 97 |
| 98 waitForEvent('playing'); | 98 waitForEvent('playing'); |
| 99 | 99 |
| 100 waitForEvent('canplay', function() { | 100 waitForEvent('canplay', function() { |
| 101 testExpected("mediaElement.readyState", HTMLMediaElement.HAVE_FU
TURE_DATA, ">="); | 101 testExpected("mediaElement.readyState", HTMLMediaElement.HAVE_FU
TURE_DATA, ">="); |
| 102 testExpected("mediaElement.paused", true); | 102 testExpected("mediaElement.paused", true); |
| 103 | 103 |
| 104 play(); | 104 play(); |
| 105 }); | 105 }); |
| 106 }, | 106 }, |
| 107 | 107 |
| 108 // Test that play() on an element that is already playing returns a |
| 109 // promise that resolves successfully. |
| 108 function playAfterPlaybackStarted() | 110 function playAfterPlaybackStarted() |
| 109 { | 111 { |
| 110 consoleWrite("playAfterPlaybackStarted()"); | 112 consoleWrite("playAfterPlaybackStarted()"); |
| 111 internals.settings.setMediaPlaybackRequiresUserGesture(false); | 113 internals.settings.setMediaPlaybackRequiresUserGesture(false); |
| 112 | 114 |
| 113 run("mediaElement = document.createElement('audio')"); | 115 run("mediaElement = document.createElement('audio')"); |
| 114 mediaElement.preload = "auto"; | 116 mediaElement.preload = "auto"; |
| 115 var mediaFile = findMediaFile("audio", "content/test"); | 117 var mediaFile = findMediaFile("audio", "content/test"); |
| 116 run("mediaElement.src = '" + mediaFile + "'"); | 118 run("mediaElement.src = '" + mediaFile + "'"); |
| 117 | 119 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 waitForEvent('error', function() { | 386 waitForEvent('error', function() { |
| 385 // Until https://crbug.com/587871 is fixed, the events will be | 387 // Until https://crbug.com/587871 is fixed, the events will be |
| 386 // [ volumechange, volumechange, promise ], it should be | 388 // [ volumechange, volumechange, promise ], it should be |
| 387 // [ volumechange, promise, volumechange ]. | 389 // [ volumechange, promise, volumechange ]. |
| 388 waitForEvent('volumechange'); | 390 waitForEvent('volumechange'); |
| 389 run("mediaElement.volume = 0.1"); | 391 run("mediaElement.volume = 0.1"); |
| 390 play(); | 392 play(); |
| 391 run("mediaElement.volume = 0.2"); | 393 run("mediaElement.volume = 0.2"); |
| 392 }); | 394 }); |
| 393 | 395 |
| 394 } | 396 }, |
| 397 |
| 398 // Test that calling pause() then play() on an element that is already |
| 399 // playing returns a promise that resolves successfully. |
| 400 function pausePlayAfterPlaybackStarted() |
| 401 { |
| 402 consoleWrite("pausePlayAfterPlaybackStarted()"); |
| 403 internals.settings.setMediaPlaybackRequiresUserGesture(false); |
| 404 |
| 405 run("mediaElement = document.createElement('audio')"); |
| 406 mediaElement.preload = "auto"; |
| 407 var mediaFile = findMediaFile("audio", "content/test"); |
| 408 run("mediaElement.src = '" + mediaFile + "'"); |
| 409 |
| 410 waitForEvent('playing', function() { |
| 411 testExpected("mediaElement.readyState", HTMLMediaElement.HAVE_EN
OUGH_DATA); |
| 412 testExpected("mediaElement.paused", false); |
| 413 |
| 414 run("mediaElement.pause()"); |
| 415 play(); |
| 416 }); |
| 417 |
| 418 waitForEvent('canplaythrough', function() { |
| 419 run("mediaElement.play()"); |
| 420 }); |
| 421 }, |
| 395 ]; | 422 ]; |
| 396 | 423 |
| 397 function start() | 424 function start() |
| 398 { | 425 { |
| 399 if (!('eventSender' in window) || !('internals' in window)) { | 426 if (!('eventSender' in window) || !('internals' in window)) { |
| 400 failTest("Not running in LayoutTests."); | 427 failTest("Not running in LayoutTests."); |
| 401 return; | 428 return; |
| 402 } | 429 } |
| 403 runNextTestOrFinish(); | 430 runNextTestOrFinish(); |
| 404 } | 431 } |
| 405 | 432 |
| 406 </script> | 433 </script> |
| 407 </head> | 434 </head> |
| 408 | 435 |
| 409 <body onload="start()"> | 436 <body onload="start()"> |
| 410 | 437 |
| 411 <p>Test the play() behaviour with regards to the returned promise for media elem
ents.</p> | 438 <p>Test the play() behaviour with regards to the returned promise for media elem
ents.</p> |
| 412 | 439 |
| 413 </body> | 440 </body> |
| 414 </html> | 441 </html> |
| OLD | NEW |