[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / click-placeholder-not-pausing.html
1 <!-- webkit-test-runner [ enableModernMediaControls=false ] -->
2 <html>
3 <head>
4     <title>Click on placeholder on a MediaDocument should not pause.</title>
5     <script src="media-file.js"></script>
6     <script src="video-test.js"></script>
7     <script src="media-controls.js"></script>
8     <script>
9         var mediaElement;
10         var placeholder;
11         var maxAttemptsToTestPlaceholderVisibility = 10;
12         var attemptsToTestPlaceholderVisibility = 0;
13
14
15         if (window.internals)
16             window.internals.settings.setAllowsPictureInPictureMediaPlayback(true);
17
18         function frameLoaded()
19         {
20             consoleWrite("Video frame loaded.");
21
22             var standaloneMediaDocument = document.getElementById("videoframe").contentDocument;
23             mediaElement = standaloneMediaDocument.querySelector("video");
24             if (!mediaElement) {
25                 failTest("ERROR: Video element was not found in frameLoaded().");
26                 return;
27             }
28
29             runWithKeyDown(function(){ mediaElement.play(); });
30
31             if (!('webkitSupportsPresentationMode' in mediaElement && 'webkitPresentationMode' in mediaElement)) {
32                 failTest("Presentation mode is not supported in this video element.")
33                 return;
34             }
35
36             consoleWrite("Going into Picture-in-Picture");
37             mediaElement.addEventListener('webkitpresentationmodechanged', onpresentationmodechanged);
38             runWithKeyDown(function(){ mediaElement.webkitSetPresentationMode('picture-in-picture'); });
39         }
40
41         function onpresentationmodechanged()
42         {
43             testExpected("mediaElement.webkitPresentationMode", "picture-in-picture");
44
45             pollPIPPlaceholderVisibilityChange();
46         }
47
48         function pollPIPPlaceholderVisibilityChange()
49         {
50             placeholder = mediaControlsElement(internals.shadowRoot(mediaElement), '-webkit-media-controls-wireless-playback-status');
51
52             if (placeholder.classList.contains('hidden')) {
53                 if (attemptsToTestPlaceholderVisibility > maxAttemptsToTestPlaceholderVisibility) {
54                     failTest("Inline placeholder did not become visible after video enters picture-in-picture.");
55                     endTest();
56                     return;
57                 }
58
59                 // Use 33 to match PlaceholderPollingDelay in mediaControlsApple.js.
60                 setTimeout(pollPIPPlaceholderVisibilityChange, 33);
61                 attemptsToTestPlaceholderVisibility++;
62                 return;
63             }
64
65             testExpected("placeholder.classList.contains('hidden')", false);
66
67             if (!window.eventSender) {
68                 failTest("ERROR: no event sender.");
69                 return;
70             }
71
72             var boundingRect = placeholder.getBoundingClientRect();
73             var x = boundingRect.left + boundingRect.width / 2;
74             var y = boundingRect.top + boundingRect.height / 2;
75             eventSender.mouseMoveTo(x, y);
76             eventSender.mouseDown();
77             eventSender.mouseUp();
78
79             testExpected("mediaElement.paused", false);
80             endTest();
81         }
82
83     </script>
84 </head>
85 <body>
86     <p>Click on placeholder on a MediaDocument should not pause.</p>
87     <iframe id="videoframe" width=400 height=300"></iframe>
88     <script type="text/javascript">
89         onload = function() {
90             var videoframe = document.getElementById("videoframe");
91             videoframe.onload = frameLoaded;
92             videoframe.src = findMediaFile("video", "content/test");
93         }
94     </script>
95
96 </body>
97 </html>
98