Commit 3f485e99 authored by Wojciech Dzierżanowski's avatar Wojciech Dzierżanowski Committed by Commit Bot

Move remaining PiP/fullscreen tests to //content

Follow up on
https://chromium-review.googlesource.com/c/chromium/src/+/2470525 by
moving the remaining fullscreen tests to
PictureInPictureContentBrowserTest. The focus is on the video element
state transitions rather than the PiP UI.

This also improves testing stability: Even though these tests are not
marked as flaky, they do fail from time to time when run locally.

Last but not least, fullscreen as implemented in Content Shell is less
obtrusive than Chrome's full-fledged fullscreen when running tests, so
this improves the developer's experience.

Bug: 1138168
Change-Id: I51adf3541f8a8ab74ac0f7259e29efaa024b14ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2511252
Commit-Queue: Wojciech Dzierżanowski <wdzierzanowski@opera.com>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825323}
parent 28ebde16
...@@ -1250,53 +1250,6 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest, ...@@ -1250,53 +1250,6 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EXPECT_TRUE(second_controller->GetWindowForTesting()->IsVisible()); EXPECT_TRUE(second_controller->GetWindowForTesting()->IsVisible());
} }
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EnterPictureInPictureThenFullscreen) {
LoadTabAndEnterPictureInPicture(
browser(), base::FilePath(kPictureInPictureWindowSizePage));
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "enterFullscreen()"));
base::string16 expected_title = base::ASCIIToUTF16("fullscreen");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
EXPECT_TRUE(active_web_contents->IsFullscreen());
EXPECT_FALSE(window_controller()->GetWindowForTesting()->IsVisible());
}
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EnterFullscreenThenPictureInPicture) {
GURL test_page_url = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(kPictureInPictureWindowSizePage));
ui_test_utils::NavigateToURL(browser(), test_page_url);
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_web_contents != nullptr);
SetUpWindowController(active_web_contents);
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "enterFullscreen()"));
base::string16 expected_title = base::ASCIIToUTF16("fullscreen");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "enterPictureInPicture();", &result));
EXPECT_TRUE(result);
EXPECT_FALSE(active_web_contents->IsFullscreen());
EXPECT_TRUE(window_controller()->GetWindowForTesting()->IsVisible());
}
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest, IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EnterPictureInPictureThenNavigateAwayCloseWindow) { EnterPictureInPictureThenNavigateAwayCloseWindow) {
GURL test_page_url = ui_test_utils::GetTestUrl( GURL test_page_url = ui_test_utils::GetTestUrl(
......
...@@ -17,12 +17,8 @@ ...@@ -17,12 +17,8 @@
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "services/media_session/public/cpp/features.h" #include "services/media_session/public/cpp/features.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/mojom/picture_in_picture/picture_in_picture.mojom.h" #include "third_party/blink/public/mojom/picture_in_picture/picture_in_picture.mojom.h"
using testing::Mock;
using testing::NiceMock;
namespace content { namespace content {
namespace { namespace {
...@@ -91,13 +87,16 @@ class TestWebContentsDelegate : public WebContentsDelegate { ...@@ -91,13 +87,16 @@ class TestWebContentsDelegate : public WebContentsDelegate {
WebContents* web_contents, WebContents* web_contents,
const viz::SurfaceId&, const viz::SurfaceId&,
const gfx::Size& natural_size) override { const gfx::Size& natural_size) override {
is_in_picture_in_picture_ = true;
return PictureInPictureResult::kSuccess; return PictureInPictureResult::kSuccess;
} }
void ExitPictureInPicture() override { is_in_picture_in_picture_ = false; }
MOCK_METHOD0(ExitPictureInPicture, void()); bool is_in_picture_in_picture() const { return is_in_picture_in_picture_; }
private: private:
Shell* const shell_; Shell* const shell_;
bool is_in_picture_in_picture_ = false;
}; };
class PictureInPictureContentBrowserTest : public ContentBrowserTest { class PictureInPictureContentBrowserTest : public ContentBrowserTest {
...@@ -116,8 +115,7 @@ class PictureInPictureContentBrowserTest : public ContentBrowserTest { ...@@ -116,8 +115,7 @@ class PictureInPictureContentBrowserTest : public ContentBrowserTest {
old_browser_client_ = SetBrowserClientForTesting(&content_browser_client_); old_browser_client_ = SetBrowserClientForTesting(&content_browser_client_);
web_contents_delegate_ = web_contents_delegate_ = std::make_unique<TestWebContentsDelegate>(shell());
std::make_unique<NiceMock<TestWebContentsDelegate>>(shell());
shell()->web_contents()->SetDelegate(web_contents_delegate_.get()); shell()->web_contents()->SetDelegate(web_contents_delegate_.get());
} }
...@@ -151,8 +149,6 @@ class PictureInPictureContentBrowserTest : public ContentBrowserTest { ...@@ -151,8 +149,6 @@ class PictureInPictureContentBrowserTest : public ContentBrowserTest {
IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
RequestSecondVideoInSameRFHDoesNotCloseWindow) { RequestSecondVideoInSameRFHDoesNotCloseWindow) {
EXPECT_CALL(*web_contents_delegate(), ExitPictureInPicture()).Times(0);
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
shell(), GetTestUrl("media/picture_in_picture", "two-videos.html"))); shell(), GetTestUrl("media/picture_in_picture", "two-videos.html")));
...@@ -172,6 +168,8 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, ...@@ -172,6 +168,8 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
expected_title, expected_title,
TitleWatcher(shell()->web_contents(), expected_title).WaitAndGetTitle()); TitleWatcher(shell()->web_contents(), expected_title).WaitAndGetTitle());
ASSERT_FALSE(web_contents_delegate()->is_in_picture_in_picture());
// Send first video in Picture-in-Picture. // Send first video in Picture-in-Picture.
ASSERT_TRUE(ExecuteScript(shell()->web_contents(), ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
"videos[0].requestPictureInPicture();")); "videos[0].requestPictureInPicture();"));
...@@ -180,6 +178,7 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, ...@@ -180,6 +178,7 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
EXPECT_EQ( EXPECT_EQ(
expected_title, expected_title,
TitleWatcher(shell()->web_contents(), expected_title).WaitAndGetTitle()); TitleWatcher(shell()->web_contents(), expected_title).WaitAndGetTitle());
EXPECT_TRUE(web_contents_delegate()->is_in_picture_in_picture());
// Send second video in Picture-in-Picture. // Send second video in Picture-in-Picture.
ASSERT_TRUE(ExecuteScript(shell()->web_contents(), ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
...@@ -192,14 +191,11 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, ...@@ -192,14 +191,11 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
// The session should still be active and ExitPictureInPicture() never called. // The session should still be active and ExitPictureInPicture() never called.
EXPECT_NE(nullptr, window_controller()->active_session_for_testing()); EXPECT_NE(nullptr, window_controller()->active_session_for_testing());
EXPECT_TRUE(web_contents_delegate()->is_in_picture_in_picture());
Mock::VerifyAndClearExpectations(web_contents_delegate());
} }
IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
RequestSecondVideoInDifferentRFHDoesNotCloseWindow) { RequestSecondVideoInDifferentRFHDoesNotCloseWindow) {
EXPECT_CALL(*web_contents_delegate(), ExitPictureInPicture()).Times(0);
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_TRUE(NavigateToURL( EXPECT_TRUE(NavigateToURL(
...@@ -229,6 +225,8 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, ...@@ -229,6 +225,8 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
expected_title, expected_title,
TitleWatcher(shell()->web_contents(), expected_title).WaitAndGetTitle()); TitleWatcher(shell()->web_contents(), expected_title).WaitAndGetTitle());
ASSERT_FALSE(web_contents_delegate()->is_in_picture_in_picture());
// Send first video in Picture-in-Picture. // Send first video in Picture-in-Picture.
ASSERT_TRUE(ExecuteScript(shell()->web_contents(), ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
"videos[0].requestPictureInPicture();")); "videos[0].requestPictureInPicture();"));
...@@ -237,6 +235,7 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, ...@@ -237,6 +235,7 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
EXPECT_EQ( EXPECT_EQ(
expected_title, expected_title,
TitleWatcher(shell()->web_contents(), expected_title).WaitAndGetTitle()); TitleWatcher(shell()->web_contents(), expected_title).WaitAndGetTitle());
EXPECT_TRUE(web_contents_delegate()->is_in_picture_in_picture());
// Send second video in Picture-in-Picture. // Send second video in Picture-in-Picture.
ASSERT_TRUE(ExecuteScript(shell()->web_contents(), ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
...@@ -250,8 +249,49 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, ...@@ -250,8 +249,49 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
// The session should still be active and ExitPictureInPicture() never called. // The session should still be active and ExitPictureInPicture() never called.
EXPECT_NE(nullptr, window_controller()->active_session_for_testing()); EXPECT_NE(nullptr, window_controller()->active_session_for_testing());
EXPECT_TRUE(web_contents_delegate()->is_in_picture_in_picture());
}
IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
EnterPictureInPictureThenFullscreen) {
ASSERT_TRUE(NavigateToURL(
shell(), GetTestUrl("media/picture_in_picture", "one-video.html")));
bool result = false;
ASSERT_TRUE(ExecuteScriptAndExtractBool(
shell()->web_contents(), "enterPictureInPictureAndGetResult();",
&result));
ASSERT_TRUE(result);
ASSERT_TRUE(web_contents_delegate()->is_in_picture_in_picture());
// The Picture-in-Picture window should be closed upon entering fullscreen.
ASSERT_TRUE(ExecuteScriptAndExtractBool(
shell()->web_contents(), "enterFullscreenAndGetResult();", &result));
ASSERT_TRUE(result);
EXPECT_TRUE(shell()->web_contents()->IsFullscreen());
EXPECT_FALSE(web_contents_delegate()->is_in_picture_in_picture());
}
IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
EnterFullscreenThenPictureInPicture) {
ASSERT_TRUE(NavigateToURL(
shell(), GetTestUrl("media/picture_in_picture", "one-video.html")));
bool result = false;
ASSERT_TRUE(ExecuteScriptAndExtractBool(
shell()->web_contents(), "enterFullscreenAndGetResult();", &result));
ASSERT_TRUE(result);
ASSERT_TRUE(shell()->web_contents()->IsFullscreen());
// We should leave fullscreen upon entering Picture-in-Picture.
ASSERT_TRUE(ExecuteScriptAndExtractBool(
shell()->web_contents(), "enterPictureInPictureAndGetResult();",
&result));
ASSERT_TRUE(result);
Mock::VerifyAndClearExpectations(web_contents_delegate()); EXPECT_FALSE(shell()->web_contents()->IsFullscreen());
EXPECT_TRUE(web_contents_delegate()->is_in_picture_in_picture());
} }
// Check that the playback state in the Picture-in-Picture window follows the // Check that the playback state in the Picture-in-Picture window follows the
...@@ -269,8 +309,9 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest, ...@@ -269,8 +309,9 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureContentBrowserTest,
ASSERT_TRUE(ExecuteScript(shell()->web_contents(), "video.pause();")); ASSERT_TRUE(ExecuteScript(shell()->web_contents(), "video.pause();"));
ASSERT_TRUE(ExecuteScriptAndExtractBool(shell()->web_contents(), ASSERT_TRUE(ExecuteScriptAndExtractBool(
"enterPictureInPicture();", &result)); shell()->web_contents(), "enterPictureInPictureAndGetResult();",
&result));
ASSERT_TRUE(result); ASSERT_TRUE(result);
EXPECT_EQ(overlay_window()->playback_state(), EXPECT_EQ(overlay_window()->playback_state(),
OverlayWindow::PlaybackState::kPaused); OverlayWindow::PlaybackState::kPaused);
...@@ -331,8 +372,9 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureContentBrowserTest, ...@@ -331,8 +372,9 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureContentBrowserTest,
ASSERT_TRUE(ExecuteScript(shell()->web_contents(), "video.pause();")); ASSERT_TRUE(ExecuteScript(shell()->web_contents(), "video.pause();"));
ASSERT_TRUE(ExecuteScriptAndExtractBool(shell()->web_contents(), ASSERT_TRUE(ExecuteScriptAndExtractBool(
"enterPictureInPicture();", &result)); shell()->web_contents(), "enterPictureInPictureAndGetResult();",
&result));
ASSERT_TRUE(result); ASSERT_TRUE(result);
EXPECT_EQ(overlay_window()->playback_state(), EXPECT_EQ(overlay_window()->playback_state(),
OverlayWindow::PlaybackState::kPaused); OverlayWindow::PlaybackState::kPaused);
...@@ -388,8 +430,8 @@ IN_PROC_BROWSER_TEST_F(AutoPictureInPictureContentBrowserTest, ...@@ -388,8 +430,8 @@ IN_PROC_BROWSER_TEST_F(AutoPictureInPictureContentBrowserTest,
shell(), GetTestUrl("media/picture_in_picture", "one-video.html"))); shell(), GetTestUrl("media/picture_in_picture", "one-video.html")));
bool result = false; bool result = false;
ASSERT_TRUE(ExecuteScriptAndExtractBool(shell()->web_contents(), ASSERT_TRUE(ExecuteScriptAndExtractBool(
"enterFullscreen();", &result)); shell()->web_contents(), "enterFullscreenAndGetResult();", &result));
ASSERT_TRUE(result); ASSERT_TRUE(result);
ASSERT_TRUE(ExecuteScript(shell()->web_contents(), ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
......
...@@ -22,13 +22,13 @@ ...@@ -22,13 +22,13 @@
.catch(e => window.domAutomationController.send(false)); .catch(e => window.domAutomationController.send(false));
} }
function enterPictureInPicture() { function enterPictureInPictureAndGetResult() {
video.requestPictureInPicture() video.requestPictureInPicture()
.then(_ => window.domAutomationController.send(true)) .then(_ => window.domAutomationController.send(true))
.catch(e => window.domAutomationController.send(false)); .catch(e => window.domAutomationController.send(false));
} }
function enterFullscreen() { function enterFullscreenAndGetResult() {
video.requestFullscreen() video.requestFullscreen()
.then(_ => window.domAutomationController.send(true)) .then(_ => window.domAutomationController.send(true))
.catch(e => window.domAutomationController.send(false)); .catch(e => window.domAutomationController.send(false));
......
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