| 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; |
| 10 var videoShouldPlay; |
| 11 var videoShouldNotPlay; |
| 12 |
| 13 testRunner.waitUntilDone(); |
| 14 |
| 15 function canPlayThrough() |
| 16 { |
| 17 canPlayThroughCount++; |
| 18 if (canPlayThroughCount == 2) { |
| 19 // Pause() will clear the autoplaying flag, which should also preven
t the |
| 20 // gesture override experiment from autoplaying. |
| 21 videoShouldNotPlay.pause(); |
| 22 |
| 23 // Mute them both, and see if only one starts. |
| 24 videoShouldPlay.muted = true; |
| 25 videoShouldNotPlay.muted = true; |
| 26 logResult(didPlaybackStart(videoShouldPlay), "First video should pla
y"); |
| 27 logResult(!didPlaybackStart(videoShouldNotPlay), "Second video shoul
d not play"); |
| 28 testRunner.notifyDone(); |
| 29 } |
| 30 } |
| 31 |
| 9 function prepareVideo(parent) | 32 function prepareVideo(parent) |
| 10 { | 33 { |
| 11 var video = document.createElement("video"); | 34 var video = document.createElement("video"); |
| 35 video.oncanplaythrough = canPlayThrough; |
| 12 video.src = findMediaFile("video", "content/test"); | 36 video.src = findMediaFile("video", "content/test"); |
| 13 video.autoplay = true; | 37 video.autoplay = true; |
| 14 parent.appendChild(video); | 38 parent.appendChild(video); |
| 15 | 39 |
| 16 return video; | 40 return video; |
| 17 } | 41 } |
| 18 | 42 |
| 19 function didPlaybackStart(element) | 43 function didPlaybackStart(element) |
| 20 { | 44 { |
| 21 return !element.paused || element.ended; | 45 return !element.paused || element.ended; |
| 22 } | 46 } |
| 23 | 47 |
| 24 var parent = document.createElement("div"); | 48 var parent = document.createElement("div"); |
| 25 document.body.appendChild(parent); | 49 document.body.appendChild(parent); |
| 26 | 50 |
| 27 // Require a user gesture, but override it for muted videos. | 51 // Require a user gesture, but override it for muted videos. |
| 28 internals.settings.setMediaPlaybackRequiresUserGesture(true); | 52 internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| 29 internals.settings.setAutoplayExperimentMode("enabled-forvideo-ifmuted"); | 53 internals.settings.setAutoplayExperimentMode("enabled-forvideo-ifmuted"); |
| 30 | 54 |
| 31 var videoShouldPlay = prepareVideo(parent); | 55 videoShouldPlay = prepareVideo(parent); |
| 32 var videoShouldNotPlay = prepareVideo(parent); | 56 videoShouldNotPlay = prepareVideo(parent); |
| 33 | |
| 34 // Pause() will clear the autoplaying flag, which should also prevent the | |
| 35 // gesture override experiment from autoplaying. | |
| 36 videoShouldNotPlay.pause(); | |
| 37 | |
| 38 // Mute them both, and see if only one starts. | |
| 39 videoShouldPlay.muted = true; | |
| 40 videoShouldNotPlay.muted = true; | |
| 41 logResult(didPlaybackStart(videoShouldPlay), "First video should play"); | |
| 42 logResult(!didPlaybackStart(videoShouldNotPlay), "Second video should not pl
ay"); | |
| 43 testRunner.notifyDone(); | |
| 44 } | 57 } |
| 45 | 58 |
| 46 </script> | 59 </script> |
| 47 <p>Test that the autoplay experiment doesn't play media once the media | 60 <p>Test that the autoplay experiment doesn't play media once the media |
| 48 is no longer eligible for autoplay.</p> | 61 is no longer eligible for autoplay.</p> |
| 49 <body onLoad="runTest()"> | 62 <body onLoad="runTest()"> |
| 50 </body> | 63 </body> |
| OLD | NEW |