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