| <script src="../../../resources/js-test-pre.js"></script> |
| <script src="../resources/media-controls-loader.js" type="text/javascript"></script> |
| <script src="../resources/media-controls-utils.js" type="text/javascript"></script> |
| <body> |
| <style type="text/css" media="screen"> |
| |
| video, #host { |
| position: absolute; |
| top: 0; |
| left: 0; |
| width: 800px; |
| height: 240px; |
| } |
| |
| </style> |
| <video src="../../content/test.mp4" muted autoplay controls></video> |
| <div id="host"></div> |
| <script type="text/javascript"> |
| |
| window.jsTestIsAsync = true; |
| |
| description("Testing the <code>VolumeSupport</code> behavior when dragging the scrubber."); |
| |
| const container = document.querySelector("div#host"); |
| const media = document.querySelector("video"); |
| const mediaController = createControls(container, media, null); |
| |
| const muteButton = mediaController.controls.muteButton.element; |
| const volumeSlider = mediaController.controls.volumeSlider.children[1].element; |
| |
| debug("By default, the volume slider should be set to 0 because the media is muted"); |
| shouldBe("mediaController.controls.volumeSlider.value", "0"); |
| |
| media.addEventListener("play", () => { |
| media.pause(); |
| shouldBecomeDifferent("muteButton.getBoundingClientRect().width", "0", () => { |
| const muteButtonBounds = muteButton.getBoundingClientRect(); |
| // Controls are now visible, let's hover over the mute button to make the volume control visible. |
| eventSender.mouseMoveTo(muteButtonBounds.left + muteButtonBounds.width / 2, muteButtonBounds.top + muteButtonBounds.height / 2); |
| shouldBecomeDifferent("volumeSlider.getBoundingClientRect().width", "0", () => { |
| // Volume slider is visible, let's start dragging in the middle of it. |
| const bounds = volumeSlider.getBoundingClientRect(); |
| const centerX = bounds.left + bounds.width / 2; |
| const dragStartY = bounds.top + bounds.height / 2; |
| const dragEndY = bounds.top; |
| const delta = dragEndY - dragStartY; |
| const iterations = Math.abs(delta); |
| |
| debug(""); |
| debug("Before starting to drag the volume slider, the media should be muted still"); |
| shouldBeTrue("media.muted"); |
| |
| eventSender.mouseMoveTo(centerX, dragStartY); |
| eventSender.mouseDown(); |
| |
| debug(""); |
| debug("We initiated a volume slider drag, the media should no longer be muted and the volume set"); |
| shouldBecomeEqual("media.muted", "false", () => { |
| // Because the slider has a 9pt-wide knob and tests are ran at 1x, we can't get 0.5 here, |
| // and instead get 0.51 since the slider will only increment on whole pixels. |
| shouldBecomeEqual("media.volume", "0.51", () => { |
| for (let i = 1; i <= iterations; ++i) |
| eventSender.mouseMoveTo(bounds.left + bounds.width / 2, dragStartY + i * Math.sign(delta)); |
| |
| eventSender.mouseUp(); |
| |
| debug(""); |
| debug("We finished dragging to set the volume to 1"); |
| shouldBecomeEqual("media.volume", "1", () => { |
| // Ensure the volume slider remains visible. |
| shouldBeTrue("mediaController.controls.volumeSlider.parent.visible"); |
| |
| container.remove(); |
| media.remove(); |
| finishJSTest(); |
| }); |
| }); |
| }); |
| }); |
| }); |
| }); |
| |
| setTimeout(finishJSTest, 3500); |
| |
| </script> |
| <script src="../../../resources/js-test-post.js"></script> |
| </body> |