| <!DOCTYPE html> |
| <title>media controls cast button</title> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="media-file.js"></script> |
| <script src="media-controls.js"></script> |
| <video controls width="500"></video> |
| <script> |
| async_test(function(t) { |
| var video = document.querySelector("video"); |
| video.src = findMediaFile("video", "content/test"); |
| |
| video.onloadedmetadata = t.step_func_done(function() { |
| // Should not have a cast button by default |
| var button = castButton(video); |
| assert_equals(button.style.display, "none", "button should not be visible with no cast devices"); |
| |
| // Pretend we have a cast device |
| internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true); |
| |
| // Now should have cast button |
| assert_false(("display" in button.style) && (button.style.display == "none"), "button should exist"); |
| var buttonBoundingRect = button.getBoundingClientRect(); |
| var dimensions = new Array(buttonBoundingRect.width, buttonBoundingRect.height); |
| assert_not_equals(dimensions[0], 0, "button should exist"); |
| assert_not_equals(dimensions[1], 0, "button should exist"); |
| |
| // Check its position is to the right of the timeline |
| // (can't test against volume control or closed caption button, since these don't always exist) |
| var x = buttonBoundingRect.left + buttonBoundingRect.width / 2; |
| var timelinePosition = mediaControlsButtonCoordinates(video, "timeline"); |
| assert_greater_than(x, timelinePosition[0], "button should be to right of timeline"); |
| |
| // Check that we don't have an overlay cast button |
| var overlayButton = overlayCastButton(video); |
| assert_equals(overlayButton.style.display, "none", "Overlay button should not be visible with controls"); |
| |
| // And to the right of the fullscreen button |
| var fullscreenPosition = mediaControlsButtonCoordinates(video, "fullscreen-button"); |
| assert_greater_than(x, fullscreenPosition[0], "button should be to right of fullscreen button"); |
| |
| // Remove cast device - cast button should go away |
| internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false); |
| assert_equals(button.style.display, "none", "button should not be visible after cast device goes away"); |
| }); |
| |
| function castButton(element) { |
| var controlID = "-internal-media-controls-cast-button"; |
| var button = mediaControlsElement(internals.shadowRoot(element).firstChild, controlID); |
| if (!button) |
| throw "Failed to find cast button"; |
| return button; |
| } |
| |
| function overlayCastButton(element) { |
| var controlID = "-internal-media-controls-overlay-cast-button"; |
| var button = mediaControlsElement(internals.shadowRoot(element).firstChild, controlID); |
| if (!button) |
| throw "Failed to find cast button"; |
| return button; |
| } |
| }); |
| </script> |