| OLD | NEW |
| 1 <script src=media-file.js></script> | 1 <script src=media-file.js></script> |
| 2 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 | 2 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 |
| 3 (Please avoid writing new tests using video-test.js) --> | 3 (Please avoid writing new tests using video-test.js) --> |
| 4 <script src=video-test.js></script> | 4 <script src=video-test.js></script> |
| 5 <script> | 5 <script> |
| 6 | 6 |
| 7 function runTest() | 7 function runTest() |
| 8 { | 8 { |
| 9 var canPlayThroughCount = 0; | 9 var canPlayThroughCount = 0; |
| 10 var videoShouldPlay; | 10 var videoShouldPlay; |
| 11 var videoShouldNotPlay; | 11 var videoShouldNotPlay; |
| 12 | 12 |
| 13 testRunner.waitUntilDone(); | 13 testRunner.waitUntilDone(); |
| 14 | 14 |
| 15 function canPlayThrough() | 15 function canPlayThrough() |
| 16 { | 16 { |
| 17 canPlayThroughCount++; | 17 canPlayThroughCount++; |
| 18 if (canPlayThroughCount == 2) { | 18 if (canPlayThroughCount == 2) { |
| 19 // Pause() will clear the autoplaying flag, which should also preven
t the | 19 // Pause() will clear the autoplaying flag, which should also preven
t the |
| 20 // gesture override experiment from autoplaying. | 20 // gesture override experiment from autoplaying. |
| 21 videoShouldNotPlay.pause(); | 21 videoShouldNotPlay.pause(); |
| 22 | 22 |
| 23 // Mute them both, and see if only one starts. | 23 // Scroll them into view, and see if they start playing. |
| 24 videoShouldPlay.muted = true; | 24 parent.scrollIntoView(true); |
| 25 videoShouldNotPlay.muted = true; | 25 // TODO(liberato): remove once autoplay gesture override experiment
concludes. |
| 26 window.internals.triggerAutoplayViewportCheck(videoShouldPlay); |
| 27 window.internals.triggerAutoplayViewportCheck(videoShouldNotPlay); |
| 26 logResult(didPlaybackStart(videoShouldPlay), "First video should pla
y"); | 28 logResult(didPlaybackStart(videoShouldPlay), "First video should pla
y"); |
| 27 logResult(!didPlaybackStart(videoShouldNotPlay), "Second video shoul
d not play"); | 29 logResult(!didPlaybackStart(videoShouldNotPlay), "Second video shoul
d not play"); |
| 28 testRunner.notifyDone(); | 30 testRunner.notifyDone(); |
| 29 } | 31 } |
| 30 } | 32 } |
| 31 | 33 |
| 32 function prepareVideo(parent) | 34 function prepareVideo(parent) |
| 33 { | 35 { |
| 34 var video = document.createElement("video"); | 36 var video = document.createElement("video"); |
| 35 video.oncanplaythrough = canPlayThrough; | 37 video.oncanplaythrough = canPlayThrough; |
| 36 video.src = findMediaFile("video", "content/test"); | 38 video.src = findMediaFile("video", "content/test"); |
| 37 video.autoplay = true; | 39 video.autoplay = true; |
| 38 parent.appendChild(video); | 40 parent.appendChild(video); |
| 39 | 41 |
| 40 return video; | 42 return video; |
| 41 } | 43 } |
| 42 | 44 |
| 43 function didPlaybackStart(element) | 45 function didPlaybackStart(element) |
| 44 { | 46 { |
| 45 return !element.paused || element.ended; | 47 return !element.paused || element.ended; |
| 46 } | 48 } |
| 47 | 49 |
| 50 // Start the videos off-screen. |
| 51 var spacer = document.createElement("div"); |
| 52 spacer.style.height="1000px"; |
| 53 spacer.style.bgcolor="blue"; |
| 54 spacer.innerHTML="<p></p>"; |
| 55 document.body.appendChild(spacer); |
| 56 |
| 57 // Create a container for the videos. |
| 48 var parent = document.createElement("div"); | 58 var parent = document.createElement("div"); |
| 49 document.body.appendChild(parent); | 59 document.body.appendChild(parent); |
| 50 | 60 |
| 51 // Require a user gesture, but override it for muted videos. | 61 // Require a user gesture, but override it for visible videos. |
| 52 internals.settings.setMediaPlaybackRequiresUserGesture(true); | 62 internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| 53 internals.settings.setAutoplayExperimentMode("enabled-forvideo-ifmuted"); | 63 internals.settings.setAutoplayExperimentMode("enabled-forvideo-ifviewport"); |
| 54 | 64 |
| 55 videoShouldPlay = prepareVideo(parent); | 65 videoShouldPlay = prepareVideo(parent); |
| 56 videoShouldNotPlay = prepareVideo(parent); | 66 videoShouldNotPlay = prepareVideo(parent); |
| 57 } | 67 } |
| 58 | 68 |
| 59 </script> | 69 </script> |
| 60 <p>Test that the autoplay experiment doesn't play media once the media | 70 <p>Test that the autoplay experiment doesn't play media once the media |
| 61 is no longer eligible for autoplay.</p> | 71 is no longer eligible for autoplay.</p> |
| 62 <body onLoad="runTest()"> | 72 <body onLoad="runTest()"> |
| 63 </body> | 73 </body> |
| OLD | NEW |