Bug 1674666 - Ctrl/Cmd+w should close PiP window. r=mtigley,kpatenio

Differential Revision: https://phabricator.services.mozilla.com/D129106
This commit is contained in:
Evgenia Kotovich 2021-11-22 21:39:09 +00:00
Родитель 285ecd4b8f
Коммит 917e91428e
4 изменённых файлов: 65 добавлений и 0 удалений

Просмотреть файл

@ -1554,6 +1554,9 @@ class PictureInPictureChild extends JSWindowActorChild {
case this.contentWindow.KeyEvent.DOM_VK_SPACE:
keystroke += "space";
break;
case this.contentWindow.KeyEvent.DOM_VK_W:
keystroke += "w";
break;
}
const isVideoStreaming = video.duration == +Infinity;
@ -1571,6 +1574,13 @@ class PictureInPictureChild extends JSWindowActorChild {
video.pause();
}
break;
case "accel-w" /* Close video */:
if (!this.isKeyEnabled(KEYBOARD_CONTROLS.CLOSE)) {
return;
}
this.pause();
this.closePictureInPicture({ reason: "close-player-shortcut" });
break;
case "downArrow" /* Volume decrease */:
if (!this.isKeyEnabled(KEYBOARD_CONTROLS.VOLUME)) {
return;

Просмотреть файл

@ -18,6 +18,7 @@ this.KEYBOARD_CONTROLS = {
MUTE_UNMUTE: 1 << 1,
VOLUME: 1 << 2,
SEEK: 1 << 3,
CLOSE: 1 << 4,
};
// These are the possible toggle positions along the right side of

Просмотреть файл

@ -50,6 +50,7 @@ skip-if =
[browser_fullscreen.js]
skip-if = (os == "mac" && debug) || os == "linux" #Bug 1566173, Bug 1664667
[browser_keyboardShortcut.js]
[browser_keyboardShortcutClosePIP.js]
[browser_keyboardShortcutWithNanDuration.js]
support-files =
test-page-with-nan-video-duration.html

Просмотреть файл

@ -0,0 +1,53 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests that keyboard shortcut ctr + w / cmd + w closing PIP window
*/
add_task(async function test_pip_close_keyboard_shortcut() {
await BrowserTestUtils.withNewTab(
{
url: TEST_PAGE,
gBrowser,
},
async browser => {
await ensureVideosReady(browser);
const VIDEO_ID = "with-controls";
let domWindowOpened = BrowserTestUtils.domWindowOpenedAndLoaded(null);
let videoReady = SpecialPowers.spawn(
browser,
[VIDEO_ID],
async videoID => {
let video = content.document.getElementById(videoID);
await ContentTaskUtils.waitForCondition(() => {
return video.isCloningElementVisually;
}, "Video is being cloned visually.");
}
);
if (AppConstants.platform == "macosx") {
EventUtils.synthesizeKey("]", {
accelKey: true,
shiftKey: true,
altKey: true,
});
} else {
EventUtils.synthesizeKey("]", { accelKey: true, shiftKey: true });
}
let pipWin = await domWindowOpened;
await videoReady;
ok(pipWin, "Got Picture-in-Picture window.");
EventUtils.synthesizeKey("w", { accelKey: true }, pipWin);
await BrowserTestUtils.windowClosed(pipWin);
ok(await isVideoPaused(browser, VIDEO_ID), "The video is paused");
ok(pipWin.closed, "Closed PIP");
}
);
});