Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / media / controls-overlay-cast-button.html
blob32719d6c42c633426cc4437226b8aaf7786457bb
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></video>
13 <script>
14 function overlayCastButton(element)
16 var controlID = "-internal-media-controls-overlay-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 overlayCastButtonDimensions(element)
24 var button = overlayCastButton(element);
25 var buttonBoundingRect = button.getBoundingClientRect();
26 return new Array(buttonBoundingRect.width, buttonBoundingRect.height);
28 async_test(function(t)
30 findMediaElement();
31 video.src = findMediaFile("video", "content/test");
32 mediaElement.addEventListener("loadedmetadata", function()
34 // Should not have a cast button by default
35 button = overlayCastButton(video);
36 assert_equals(button.style.display, "none", "button should not be visible with no cast devices");
38 // Pretend we have a cast device
39 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true);
40 // Now should have cast button
41 assert_false(("display" in button.style) && (button.style.display == "none"), "button should exist");
42 dimensions = overlayCastButtonDimensions(video);
43 assert_not_equals(dimensions[0], 0, "button should exist");
44 assert_not_equals(dimensions[1], 0, "button should exist");
46 // Check position, should be in the top left corner of the video
47 rect = button.getBoundingClientRect();
48 videoRect = video.getBoundingClientRect();
49 assert_greater_than_equal(rect.top, videoRect.top, "button should be at top left of video");
50 assert_greater_than_equal(rect.left, videoRect.left, "button should be at top left of video");
51 assert_less_than_equal(rect.bottom, videoRect.top + videoRect.height / 2, "button should be at top left of video");
52 assert_less_than_equal(rect.right, videoRect.left + videoRect.width / 2, "button should be at top left of video");
54 // Remove cast device - cast button should go away
55 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false);
56 assert_equals(button.style.display, "none", "button should not be visible after cast device goes away");
57 t.done();
59 });
60 </script>
61 </body>
62 </html>