Commit 93488940 authored by François Beaufort's avatar François Beaufort Committed by Commit Bot

[Picture-in-Picture] Update window playback when video src changes.

This CL make sure the Picture-in-Picture window playback state is
reflected when video src changes. It is a follow-up to
https://chromium-review.googlesource.com/1089331

Bug: 726619
Change-Id: Ic756c03aa023d3e4e229c7495686ea8f322503e3
Reviewed-on: https://chromium-review.googlesource.com/1133168
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarMatthew Wolenetz <wolenetz@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576428}
parent d37f424f
...@@ -474,25 +474,15 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest, ...@@ -474,25 +474,15 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
// keep Picture-in-Picture window opened. // keep Picture-in-Picture window opened.
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest, IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
ResetVideoSrcKeepsPictureInPictureWindowOpened) { ResetVideoSrcKeepsPictureInPictureWindowOpened) {
GURL test_page_url = ui_test_utils::GetTestUrl( LoadTabAndEnterPictureInPicture(browser());
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath( EXPECT_TRUE(window_controller()->GetWindowForTesting()->IsVisible());
FILE_PATH_LITERAL("media/picture-in-picture/window-size.html"))); EXPECT_TRUE(
ui_test_utils::NavigateToURL(browser(), test_page_url); window_controller()->GetWindowForTesting()->GetVideoLayer()->visible());
content::WebContents* active_web_contents = content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_web_contents); EXPECT_TRUE(content::ExecuteScript(active_web_contents, "video.src = null;"));
SetUpWindowController(active_web_contents);
ASSERT_TRUE(window_controller());
EXPECT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "enterPictureInPicture();", &result));
EXPECT_TRUE(result);
bool in_picture_in_picture = false; bool in_picture_in_picture = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool( EXPECT_TRUE(ExecuteScriptAndExtractBool(
...@@ -500,15 +490,43 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest, ...@@ -500,15 +490,43 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EXPECT_TRUE(in_picture_in_picture); EXPECT_TRUE(in_picture_in_picture);
EXPECT_TRUE(window_controller()->GetWindowForTesting()->IsVisible()); EXPECT_TRUE(window_controller()->GetWindowForTesting()->IsVisible());
EXPECT_FALSE(
window_controller()->GetWindowForTesting()->GetVideoLayer()->visible());
}
EXPECT_TRUE(content::ExecuteScript(active_web_contents, "video.src = null;")); #if defined(OS_LINUX)
#define MAYBE_UpdateVideoSrcKeepsPictureInPictureWindowOpened \
DISABLED_UpdateVideoSrcKeepsPictureInPictureWindowOpened
#else
#define MAYBE_UpdateVideoSrcKeepsPictureInPictureWindowOpened \
UpdateVideoSrcKeepsPictureInPictureWindowOpened
#endif
in_picture_in_picture = false; // Tests that updating video src when video is in Picture-in-Picture session
// keep Picture-in-Picture window opened.
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
MAYBE_UpdateVideoSrcKeepsPictureInPictureWindowOpened) {
LoadTabAndEnterPictureInPicture(browser());
EXPECT_TRUE(window_controller()->GetWindowForTesting()->IsVisible());
EXPECT_TRUE(
window_controller()->GetWindowForTesting()->GetVideoLayer()->visible());
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "changeVideoSrc();", &result));
EXPECT_TRUE(result);
bool in_picture_in_picture = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool( EXPECT_TRUE(ExecuteScriptAndExtractBool(
active_web_contents, "isInPictureInPicture();", &in_picture_in_picture)); active_web_contents, "isInPictureInPicture();", &in_picture_in_picture));
EXPECT_TRUE(in_picture_in_picture); EXPECT_TRUE(in_picture_in_picture);
EXPECT_TRUE(window_controller()->GetWindowForTesting()->IsVisible()); EXPECT_TRUE(window_controller()->GetWindowForTesting()->IsVisible());
EXPECT_TRUE(
window_controller()->GetWindowForTesting()->GetVideoLayer()->visible());
} }
// Tests that we can enter Picture-in-Picture when a video is not preloaded, // Tests that we can enter Picture-in-Picture when a video is not preloaded,
......
...@@ -71,5 +71,12 @@ ...@@ -71,5 +71,12 @@
document.title = 'fullscreen'; document.title = 'fullscreen';
}, { once: true }); }, { once: true });
} }
function changeVideoSrc() {
video.addEventListener('loadedmetadata', function() {
window.domAutomationController.send(true);
}, { once: true });
video.src = video.src;
}
</script> </script>
</html> </html>
...@@ -207,7 +207,7 @@ void MediaWebContentsObserver::OnMediaPaused(RenderFrameHost* render_frame_host, ...@@ -207,7 +207,7 @@ void MediaWebContentsObserver::OnMediaPaused(RenderFrameHost* render_frame_host,
UpdateVideoLock(); UpdateVideoLock();
if (!web_contents()->IsBeingDestroyed() && pip_player_.has_value() && if (!web_contents()->IsBeingDestroyed() && pip_player_.has_value() &&
pip_player_ == player_id) { pip_player_->render_frame_host == render_frame_host) {
content::PictureInPictureWindowController::GetOrCreateForWebContents( content::PictureInPictureWindowController::GetOrCreateForWebContents(
web_contents()) web_contents())
->UpdatePlaybackState(false /* is not playing */, ->UpdatePlaybackState(false /* is not playing */,
...@@ -259,7 +259,7 @@ void MediaWebContentsObserver::OnMediaPlaying( ...@@ -259,7 +259,7 @@ void MediaWebContentsObserver::OnMediaPlaying(
} }
if (!web_contents()->IsBeingDestroyed() && pip_player_.has_value() && if (!web_contents()->IsBeingDestroyed() && pip_player_.has_value() &&
pip_player_ == id) { pip_player_->render_frame_host == render_frame_host) {
content::PictureInPictureWindowController::GetOrCreateForWebContents( content::PictureInPictureWindowController::GetOrCreateForWebContents(
web_contents()) web_contents())
->UpdatePlaybackState(true /* is playing */, ->UpdatePlaybackState(true /* is playing */,
......
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