| <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" autoplay controls></video> |
| <div id="host"></div> |
| <script type="text/javascript"> |
| |
| window.jsTestIsAsync = true; |
| |
| description("Testing that dragging the volume slider to 0 turns the mute button on and that pressing the mute button resets the volume to the previous value."); |
| |
| 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; |
| |
| function runTest() |
| { |
| media.removeEventListener("play", runTest); |
| media.pause(); |
| |
| shouldBe("media.volume", "1"); |
| shouldBe("mediaController.controls.volumeSlider.value", "1"); |
| |
| media.volume = 0.5; |
| shouldBecomeEqual("media.volume", "0.5", () => { |
| 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", () => { |
| dragVolumeSlider(0.5, 0); |
| shouldBecomeEqual("media.muted", "true", () => { |
| debug(""); |
| debug("We click on the mute button which should set the volume back to 0.5"); |
| pressOnElement(muteButton); |
| shouldBecomeEqual("media.volume", "0.5", () => { |
| shouldBeFalse("media.muted"); |
| debug(""); |
| container.remove(); |
| media.remove(); |
| finishJSTest(); |
| }); |
| }); |
| }); |
| }); |
| }); |
| } |
| |
| media.addEventListener("play", runTest); |
| |
| function dragVolumeSlider(fromVolume, toVolume) |
| { |
| debug(""); |
| debug(`We drag the volume slider to set the volume from ${fromVolume} to ${toVolume}`); |
| |
| const bounds = volumeSlider.getBoundingClientRect(); |
| const centerX = bounds.left + bounds.width / 2; |
| const dragStartY = bounds.top + bounds.height * (1 - fromVolume); |
| const dragEndY = bounds.top + bounds.height * (1 - toVolume); |
| const delta = dragEndY - dragStartY; |
| const iterations = Math.abs(delta); |
| |
| eventSender.mouseMoveTo(centerX, dragStartY); |
| eventSender.mouseDown(); |
| for (let i = 1; i <= iterations; ++i) |
| eventSender.mouseMoveTo(dragVolumeSlider, dragStartY + i * Math.sign(delta)); |
| eventSender.mouseUp(); |
| } |
| |
| </script> |
| <script src="../../../resources/js-test-post.js"></script> |
| </body> |