Bug 1412210 - Respect video error state while adjusting controls to determine the visibility of clickToPlay button. r=jaws
MozReview-Commit-ID: HhKHVYmEsKD
--- a/toolkit/content/tests/widgets/test_videocontrols_error.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_error.html
@@ -1,66 +1,57 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Video controls test - Error</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
<video id="video" controls preload="auto"></video>
</div>
<pre id="test">
<script clas="testbody" type="application/javascript">
- SimpleTest.waitForExplicitFinish();
-
const video = document.getElementById("video");
const statusOverlay = getAnonElementWithinVideoByAttribute(video, "anonid", "statusOverlay");
const statusIcon = getAnonElementWithinVideoByAttribute(video, "anonid", "statusIcon");
+ const clickToPlay = getAnonElementWithinVideoByAttribute(video, "anonid", "clickToPlay");
- const testCases = [];
+ add_task(async function setup() {
+ await new Promise(resolve => window.addEventListener("load", resolve, {once: true}));
+ await SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]});
+ });
- testCases.push(() => new Promise(resolve => {
+ add_task(async function check_normal_status() {
+ await new Promise(resolve => {
+ video.src = "seek_with_sound.ogg";
+ video.addEventListener("loadedmetadata", resolve);
+ });
+
ok(statusOverlay.hidden, "statusOverlay shoud not present without error");
ok(!statusOverlay.hasAttribute("error"), "statusOverlay should not in error state");
isnot(statusIcon.getAttribute("type"), "error", "should not show error icon");
-
- resolve();
- }));
+ });
- testCases.push(() => new Promise(resolve => {
- video.src = "invalid-path.ogg";
- video.addEventListener("error", resolve);
- }));
-
- testCases.push(() => new Promise(resolve => {
+ add_task(async function invalid_source() {
const errorType = "errorNoSource";
+ await new Promise(resolve => {
+ video.src = "invalid_source.ogg";
+ video.addEventListener("error", resolve)
+ });
+
+ ok(clickToPlay.hasAttribute("hidden"), `click to play button should hide`);
ok(!statusOverlay.hidden, `statusOverlay should show when ${errorType}`);
is(statusOverlay.getAttribute("error"), errorType, `statusOverlay should have correct error state: ${errorType}`);
is(statusIcon.getAttribute("type"), "error", `should show error icon when ${errorType}`);
-
- resolve();
- }));
-
- function executeTestCases(tasks) {
- return tasks.reduce((promise, task) => promise.then(task), Promise.resolve());
- }
-
- function startTest() {
- executeTestCases(testCases).then(SimpleTest.finish);
- }
-
- function loadevent() {
- SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, startTest);
- }
-
- window.addEventListener("load", loadevent);
+ });
</script>
</pre>
</body>
</html>
--- a/toolkit/content/tests/widgets/test_videocontrols_vtt.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_vtt.html
@@ -17,17 +17,16 @@
<pre id="test">
<script clas="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
const video = document.getElementById("video");
const ccBtn = getAnonElementWithinVideoByAttribute(video, "anonid", "closedCaptionButton");
const ttList = getAnonElementWithinVideoByAttribute(video, "anonid", "textTrackList");
- const testCases = [];
add_task(async function wait_for_media_ready() {
await new Promise(resolve => window.addEventListener("load", resolve, {once: true}));
await SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]});
await new Promise(resolve => {
video.src = "seek_with_sound.ogg";
video.addEventListener("loadedmetadata", resolve);
});
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -1735,17 +1735,18 @@
const clickToPlayViewRatio = 0.15;
const clickToPlayScaledSize = Math.max(
this.clickToPlay.minWidth, minVideoSideLength * clickToPlayViewRatio);
if (clickToPlayScaledSize >= videoWidth ||
(clickToPlayScaledSize + this.controlBarMinHeight / 2 >= videoHeight / 2 )) {
this.clickToPlay.hideByAdjustment = true;
} else {
- if (this.clickToPlay.hidden && !this.video.played.length && this.video.paused) {
+ if (this.clickToPlay.hidden && !this.video.played.length &&
+ this.video.paused && this.clickToPlay.hideByAdjustment) {
this.clickToPlay.hideByAdjustment = false;
}
this.clickToPlay.style.width = `${clickToPlayScaledSize}px`;
this.clickToPlay.style.height = `${clickToPlayScaledSize}px`;
}
},
init(binding) {