Bug 1611186 - Pause video when PiP close button is pressed r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D61614

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Striemer 2020-02-10 16:09:39 +00:00
parent 7c31ecf30b
commit 2969add02b
3 changed files with 55 additions and 0 deletions

View File

@ -227,6 +227,7 @@ let Player = {
}
case "close": {
this.actor.sendAsyncMessage("PictureInPicture:Pause");
PictureInPicture.closePipWindow({ reason: "close-button" });
break;
}

View File

@ -21,6 +21,7 @@ prefs =
[browser_cannotTriggerFromContent.js]
[browser_contextMenu.js]
[browser_closePlayer.js]
[browser_closeTab.js]
[browser_disabledForMediaStreamVideos.js]
[browser_fullscreen.js]

View File

@ -0,0 +1,53 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests that closing with unpip leaves the video playing but the close button
* will pause the video.
*/
add_task(async () => {
for (let videoID of ["with-controls", "no-controls"]) {
info(`Testing ${videoID} case.`);
let playVideo = () => {
return SpecialPowers.spawn(browser, [videoID], async videoID => {
return content.document.getElementById(videoID).play();
});
};
let isVideoPaused = () => {
return SpecialPowers.spawn(browser, [videoID], async videoID => {
return content.document.getElementById(videoID).paused;
});
};
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
let browser = tab.linkedBrowser;
await playVideo();
// Try the unpip button.
let pipWin = await triggerPictureInPicture(browser, videoID);
ok(pipWin, "Got Picture-in-Picture window.");
ok(!(await isVideoPaused()), "The video is not paused");
let pipClosed = BrowserTestUtils.domWindowClosed(pipWin);
let unpipButton = pipWin.document.getElementById("unpip");
EventUtils.synthesizeMouseAtCenter(unpipButton, {}, pipWin);
await pipClosed;
ok(!(await isVideoPaused()), "The video is not paused");
// Try the close button.
pipWin = await triggerPictureInPicture(browser, videoID);
ok(pipWin, "Got Picture-in-Picture window.");
ok(!(await isVideoPaused()), "The video is not paused");
pipClosed = BrowserTestUtils.domWindowClosed(pipWin);
let closeButton = pipWin.document.getElementById("close");
EventUtils.synthesizeMouseAtCenter(closeButton, {}, pipWin);
await pipClosed;
ok(await isVideoPaused(), "The video is paused");
BrowserTestUtils.removeTab(tab);
}
});