Commit 6dbae413 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Picture-in-Picture: always notify the player when the window is closed.

At the moment, we only notify the player if it was playing. This will
notify the player all the time but only pause it if it is playing.

Bug: 845560
Change-Id: Ifceafbc5eaa79927935ed4b5f50a147b03f955b5
Reviewed-on: https://chromium-review.googlesource.com/1069713
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarapacible <apacible@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561648}
parent cda05642
......@@ -131,4 +131,80 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
#endif // !defined(OS_ANDROID)
// Tests that when closing a Picture-in-Picture window, the video elemnet is
// reflected as no longer in Picture-in-Picture.
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
CloseWindowWhilePlaying) {
GURL test_page_url = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(
FILE_PATH_LITERAL("media/picture-in-picture/window-size.html")));
ui_test_utils::NavigateToURL(browser(), test_page_url);
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_web_contents);
SetUpWindowController(active_web_contents);
ASSERT_TRUE(window_controller());
EXPECT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
EXPECT_TRUE(
content::ExecuteScript(active_web_contents, "enterPictureInPicture();"));
base::string16 expected_title = base::ASCIIToUTF16("1");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
bool in_picture_in_picture = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
active_web_contents, "isInPictureInPicture();", &in_picture_in_picture));
EXPECT_TRUE(in_picture_in_picture);
window_controller()->Close();
expected_title = base::ASCIIToUTF16("left");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
}
// Ditto, when the video isn't playing.
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
CloseWindowWithoutPlaying) {
GURL test_page_url = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(
FILE_PATH_LITERAL("media/picture-in-picture/window-size.html")));
ui_test_utils::NavigateToURL(browser(), test_page_url);
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_web_contents);
SetUpWindowController(active_web_contents);
ASSERT_TRUE(window_controller());
EXPECT_TRUE(
content::ExecuteScript(active_web_contents, "enterPictureInPicture();"));
base::string16 expected_title = base::ASCIIToUTF16("1");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
bool in_picture_in_picture = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
active_web_contents, "isInPictureInPicture();", &in_picture_in_picture));
EXPECT_TRUE(in_picture_in_picture);
window_controller()->Close();
expected_title = base::ASCIIToUTF16("left");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
}
#endif // !defined(OS_LINUX) && !defined(OS_WIN)
......@@ -24,11 +24,19 @@
video.addEventListener('loadedmetadata', enterPictureInPictureInternal, { once: true });
}
function isInPictureInPicture() {
window.domAutomationController.send(document.pictureInPictureElement == video);
}
function enterPictureInPictureInternal() {
video.requestPictureInPicture().then(win => {
pipWindow = win;
updateTitle();
pipWindow.addEventListener('resize', updateTitle);
video.addEventListener('leavepictureinpicture', () => {
document.title = 'left';
}, { once: true });
});
}
</script>
......
......@@ -147,10 +147,11 @@ void PictureInPictureWindowControllerImpl::OnLeavingPictureInPicture() {
// Pause the current video so there is only one video playing at a time.
media_player_id_->first->Send(new MediaPlayerDelegateMsg_Pause(
media_player_id_->first->GetRoutingID(), media_player_id_->second));
media_player_id_->first->Send(
new MediaPlayerDelegateMsg_EndPictureInPictureMode(
media_player_id_->first->GetRoutingID(), media_player_id_->second));
}
media_player_id_->first->Send(
new MediaPlayerDelegateMsg_EndPictureInPictureMode(
media_player_id_->first->GetRoutingID(), media_player_id_->second));
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment