Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / media / controls-cast-button-narrow.html
blobe5a2a912969b215f1a8583eff5bf20a909e87843
1 <!doctype html>
2 <html>
3 <head>
4 <title>media controls cast button</title>
5 <script src="../resources/testharness.js"></script>
6 <script src="../resources/testharnessreport.js"></script>
7 <script src="media-file.js"></script>
8 <script src="media-controls.js"></script>
9 <script src="video-test.js"></script>
10 </head>
11 <body>
12 <video width="100" controls></video>
13 <script>
14 function castButton(element)
16 var controlID = "-internal-media-controls-cast-button";
17 var button = mediaControlsElement(window.internals.shadowRoot(element).firstChild, controlID);
18 if (!button)
19 throw "Failed to find cast button";
20 return button;
22 function overlayCastButton(element)
24 var controlID = "-internal-media-controls-overlay-cast-button";
25 var button = mediaControlsElement(window.internals.shadowRoot(element).firstChild, controlID);
26 if (!button)
27 throw "Failed to find cast button";
28 return button;
30 function castButtonDimensions(element)
32 var button = castButton(element);
33 var buttonBoundingRect = button.getBoundingClientRect();
34 return new Array(buttonBoundingRect.width, buttonBoundingRect.height);
36 function castButtonCoordinates(element, id)
38 var button = castButton(element);
39 var buttonBoundingRect = button.getBoundingClientRect();
40 var x = buttonBoundingRect.left + buttonBoundingRect.width / 2;
41 var y = buttonBoundingRect.top + buttonBoundingRect.height / 2;
42 return new Array(x, y);
44 async_test(function(t)
46 findMediaElement();
47 video.src = findMediaFile("video", "content/test");
48 mediaElement.addEventListener("loadedmetadata", function()
50 // Pretend we have a cast device
51 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true);
53 // Video should not have a cast button since the video is too narrow
54 button = castButton(video);
55 assert_equals(button.style.display, "none", "button should not be visible with no cast devices");
57 // It should, however, have an overlay cast button instead
58 button = overlayCastButton(video);
59 rect = button.getBoundingClientRect();
60 videoRect = video.getBoundingClientRect();
61 assert_greater_than_equal(rect.top, videoRect.top, "button should be at top left of video");
62 assert_greater_than_equal(rect.left, videoRect.left, "button should be at top left of video");
63 assert_less_than_equal(rect.bottom, videoRect.top + videoRect.height / 2, "button should be at top left of video");
64 assert_less_than_equal(rect.right, videoRect.left + videoRect.width / 2, "button should be at top left of video");
66 t.done();
68 });
69 </script>
70 </body>
71 </html>