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