OLD | NEW |
1 <html> | 1 <!DOCTYPE html> |
2 <head> | 2 <title>Test that video play does not work unless a user gesture is involved in p
laying a video.</title> |
3 <title>Test that video play does not work unless a user gesture is invol
ved in playing a video</title> | 3 <script src="../resources/testharness.js"></script> |
4 <script src=media-controls.js></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src=media-file.js></script> | 5 <script src="media-controls.js"></script> |
6 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 6 <script src="media-file.js"></script> |
7 (Please avoid writing new tests using video-test.js) --> | 7 <script> |
8 <script src=video-test.js></script> | 8 internals.settings.setMediaPlaybackRequiresUserGesture(true); |
9 <script> | 9 </script> |
10 var userGestureInitiated = 0; | 10 <video controls></video> |
11 if (window.internals) | 11 <script> |
12 window.internals.settings.setMediaPlaybackRequiresUserGesture(tr
ue); | 12 async_test(function(t) { |
| 13 var userGestureInitiated = false; |
| 14 var video = document.querySelector("video"); |
13 | 15 |
14 function click() | 16 video.oncanplaythrough = t.step_func(function() { |
15 { | 17 // No user gesture initiated. |
16 if (window.eventSender) { | 18 video.play(); |
17 var playCoords; | 19 assert_true(video.paused); |
18 try { | |
19 playCoords = mediaControlsButtonCoordinates(video, "play
-button"); | |
20 } catch (exception) { | |
21 failTest(exception.description); | |
22 return; | |
23 } | |
24 var x = playCoords[0]; | |
25 var y = playCoords[1]; | |
26 | 20 |
27 userGestureInitiated = 1; | 21 // User gesture initiated. |
28 eventSender.mouseMoveTo(x, y); | 22 userGestureInitiated = true; |
29 eventSender.mouseDown(); | 23 var playCoords = mediaControlsButtonCoordinates(video, "play-button"); |
30 eventSender.mouseUp(); | 24 eventSender.mouseMoveTo(playCoords[0], playCoords[1]); |
31 } | 25 eventSender.mouseDown(); |
32 } | 26 eventSender.mouseUp(); |
| 27 }); |
33 | 28 |
34 function playing() | 29 video.onplaying = t.step_func(function() { |
35 { | 30 assert_true(userGestureInitiated); |
36 if (userGestureInitiated == 0) { | 31 video.pause(); |
37 failTest("Should not play without user gesture."); | 32 }); |
38 } else { | |
39 run("video.pause()"); | |
40 } | |
41 } | |
42 | 33 |
43 function pause() | 34 video.onpause = t.step_func_done(function() { |
44 { | 35 assert_true(video.paused); |
45 testExpected("video.paused", true); | 36 }); |
46 endTest(); | |
47 } | |
48 | 37 |
49 function canplaythrough() | 38 video.src = findMediaFile("video", "content/test"); |
50 { | 39 }); |
51 consoleWrite(""); | 40 </script> |
52 consoleWrite("* No user gesture initiated"); | |
53 run("video.play()"); | |
54 testExpected("video.paused", true); | |
55 consoleWrite(""); | |
56 | |
57 consoleWrite("* User gesture initiated"); | |
58 click(); | |
59 } | |
60 | |
61 function start() | |
62 { | |
63 findMediaElement(); | |
64 waitForEvent('canplaythrough', canplaythrough); | |
65 waitForEvent('playing', playing); | |
66 waitForEvent('pause', pause); | |
67 video.src = findMediaFile("video", "content/test"); | |
68 } | |
69 </script> | |
70 </head> | |
71 | |
72 <body onload="start()"> | |
73 <p>Test that video play() does not work unless a user clicked on the play bu
tton.</p> | |
74 <video controls></video> | |
75 </body> | |
76 </html> | |
OLD | NEW |