Commit 503fae89 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Picture-in-Picture: stop video in pip when starting a new one in page.

The video is now notified that it is no longer in PIP which allows it
to cleanup its UI.

Bug: 845561
Change-Id: I046da987e51f2568c6af05a3c51a7c0124a6abbe
Reviewed-on: https://chromium-review.googlesource.com/1067748Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarapacible <apacible@chromium.org>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561718}
parent 6f4d713f
...@@ -207,4 +207,51 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest, ...@@ -207,4 +207,51 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
.WaitAndGetTitle()); .WaitAndGetTitle());
} }
// Tests that when starting a new Picture-in-Picture session from the same tab,
// the previous video is no longer in Picture-in-Picture mode.
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
OpenSecondPictureInPictureStopsFirst) {
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();"));
// Check that the Picture-in-Picture window was resized once.
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);
EXPECT_TRUE(
content::ExecuteScript(active_web_contents, "secondPictureInPicture();"));
// 'left' is sent when the first video leaves Picture-in-Picture.
expected_title = base::ASCIIToUTF16("left");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
in_picture_in_picture = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
active_web_contents, "isInPictureInPicture();", &in_picture_in_picture));
EXPECT_FALSE(in_picture_in_picture);
}
#endif // !defined(OS_LINUX) && !defined(OS_WIN) #endif // !defined(OS_LINUX) && !defined(OS_WIN)
...@@ -1410,15 +1410,15 @@ void Browser::OnDidBlockFramebust(content::WebContents* web_contents, ...@@ -1410,15 +1410,15 @@ void Browser::OnDidBlockFramebust(content::WebContents* web_contents,
gfx::Size Browser::EnterPictureInPicture(const viz::SurfaceId& surface_id, gfx::Size Browser::EnterPictureInPicture(const viz::SurfaceId& surface_id,
const gfx::Size& natural_size) { const gfx::Size& natural_size) {
// If there was already a controller, close the existing window before
// creating the next one.
if (pip_window_controller_)
pip_window_controller_->Close();
// Create or update |pip_window_controller_| for the current WebContents.
if (!pip_window_controller_ || if (!pip_window_controller_ ||
pip_window_controller_->GetInitiatorWebContents() != pip_window_controller_->GetInitiatorWebContents() !=
tab_strip_model_->GetActiveWebContents()) { tab_strip_model_->GetActiveWebContents()) {
// If there was already a controller, close the existing window before
// creating the next one.
if (pip_window_controller_)
pip_window_controller_->Close();
// Update |pip_window_controller_| for the current content::WebContents.
pip_window_controller_ = pip_window_controller_ =
content::PictureInPictureWindowController::GetOrCreateForWebContents( content::PictureInPictureWindowController::GetOrCreateForWebContents(
tab_strip_model_->GetActiveWebContents()); tab_strip_model_->GetActiveWebContents());
......
...@@ -11,6 +11,14 @@ ...@@ -11,6 +11,14 @@
let pipWindow = null; let pipWindow = null;
let sizeCountUpdates = 0; let sizeCountUpdates = 0;
// This video is created here in order to be used in
// `secondPictureInPicture()`. Unfortunately, the `requestPictureInPicture()`
// method has to be called during a user activation event handler so it's not
// possible to load the video on-demand.
const secondVideo = document.createElement('video');
secondVideo.src = '../bigbuck.webm';
secondVideo.load();
function updateTitle() { function updateTitle() {
// TODO(mlamouri): ideally, we should send the actual size but it will be // TODO(mlamouri): ideally, we should send the actual size but it will be
// flaky and require some minutia so starting with the basics. // flaky and require some minutia so starting with the basics.
...@@ -19,9 +27,7 @@ ...@@ -19,9 +27,7 @@
} }
function enterPictureInPicture() { function enterPictureInPicture() {
if (video.readyState > 0) enterPictureInPictureInternal();
return enterPictureInPictureInternal();
video.addEventListener('loadedmetadata', enterPictureInPictureInternal, { once: true });
} }
function isInPictureInPicture() { function isInPictureInPicture() {
...@@ -39,5 +45,9 @@ ...@@ -39,5 +45,9 @@
}, { once: true }); }, { once: true });
}); });
} }
function secondPictureInPicture() {
secondVideo.requestPictureInPicture();
}
</script> </script>
</html> </html>
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