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

[Picture-in-Picture] Fix crash in Chrome OS.

This make sure starting a new Picture-in-Picture session from the same
video doesn't crash in Chrome OS.

Bug: 852289
Change-Id: I7f4f5f3bed9999c08ee6576e9fe96e559e92009f
Reviewed-on: https://chromium-review.googlesource.com/1102469
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarapacible <apacible@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568355}
parent e406b0db
......@@ -300,6 +300,67 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EXPECT_FALSE(is_paused);
}
// Tests that when starting a new Picture-in-Picture session from the same
// video, the video stays in Picture-in-Picture mode.
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
RequestPictureInPictureTwiceFromSameVideo) {
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 requesting Picture-in-Picture promise was resolved.
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, "exitPictureInPicture();"));
// 'left' is sent when the video leaves Picture-in-Picture.
expected_title = base::ASCIIToUTF16("left");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
EXPECT_TRUE(
content::ExecuteScript(active_web_contents, "enterPictureInPicture();"));
// Check that requesting Picture-in-Picture promise was resolved.
expected_title = base::ASCIIToUTF16("2");
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_TRUE(in_picture_in_picture);
bool is_paused = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(active_web_contents, "isPaused();",
&is_paused));
EXPECT_FALSE(is_paused);
}
// 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,
......
......@@ -30,6 +30,7 @@ OverlaySurfaceEmbedder::~OverlaySurfaceEmbedder() = default;
void OverlaySurfaceEmbedder::SetPrimarySurfaceId(
const viz::SurfaceId& surface_id) {
video_layer_ = window_->GetVideoLayer();
// SurfaceInfo has information about the embedded surface.
video_layer_->SetShowPrimarySurface(
surface_id, window_->GetBounds().size(), SK_ColorBLACK,
......@@ -39,13 +40,17 @@ void OverlaySurfaceEmbedder::SetPrimarySurfaceId(
void OverlaySurfaceEmbedder::UpdateLayerBounds() {
// Update the size and position of the video to stretch on the entire window.
video_layer_ = window_->GetVideoLayer();
video_layer_->SetBounds(window_->GetVideoBounds());
video_layer_->SetSurfaceSize(window_->GetVideoBounds().size());
// Update the size and position of controls.
controls_background_layer_ = window_->GetControlsBackgroundLayer();
controls_background_layer_->SetBounds(
gfx::Rect(gfx::Point(0, 0), window_->GetBounds().size()));
close_controls_layer_ = window_->GetCloseControlsLayer();
close_controls_layer_->SetBounds(window_->GetCloseControlsBounds());
play_pause_controls_layer_ = window_->GetPlayPauseControlsLayer();
play_pause_controls_layer_->SetBounds(window_->GetPlayPauseControlsBounds());
}
......
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