Commit e6584c33 authored by Wojciech Dzierżanowski's avatar Wojciech Dzierżanowski Committed by Chromium LUCI CQ

Ensure video started playing in test

Several Picture-in-Picture browser tests require video playback to have
started, but they didn't really enforce it considering that the `play()`
method of the media element is asynchronous. In particular, a test
verifying the visibility of a control bound to a MediaSession action
might never see the control: The control is visible when the video is
actually playing and also it's hidden automatically 2.5 s after the
start of mouse hover. If playback doesn't start during those 2.5 seconds
(which is plausible if the test machines are under heavy load) the
hiding timeout will elapse first.

Bug: 985303
Change-Id: I7f9d62e8496cb5419445dd27c94fde91d541a6ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2635156Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Wojciech Dzierżanowski <wdzierzanowski@opera.com>
Cr-Commit-Position: refs/heads/master@{#845409}
parent eaf0e057
......@@ -556,9 +556,11 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
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, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "enterPictureInPicture();", &result));
EXPECT_TRUE(result);
......@@ -668,9 +670,11 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
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, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "enterPictureInPicture();", &result));
EXPECT_TRUE(result);
......@@ -1862,7 +1866,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
// Play video and check that Skip Ad button is now displayed when
// video plays and mouse is hovering over the window.
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
MoveMouseOverOverlayWindow();
AssertControlsVisible(
{GetOverlayWindow()->skip_ad_controls_view_for_testing()}, true);
......@@ -1988,7 +1995,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
// Play video and check that Next Track button is now displayed when video
// plays and mouse is hovering over the window.
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
MoveMouseOverOverlayWindow();
AssertControlsVisible(
{GetOverlayWindow()->next_track_controls_view_for_testing()}, true);
......@@ -2033,7 +2043,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
// Play video and check that Previous Track button is now displayed when
// video plays and mouse is hovering over the window.
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
MoveMouseOverOverlayWindow();
AssertControlsVisible(
{GetOverlayWindow()->previous_track_controls_view_for_testing()}, true);
......@@ -2055,7 +2068,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
browser(), base::FilePath(kPictureInPictureWindowSizePage));
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
ASSERT_TRUE(content::ExecuteScript(
active_web_contents, "setMediaSessionActionHandler('skipad');"));
base::RunLoop().RunUntilIdle();
......@@ -2076,7 +2092,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
browser(), base::FilePath(kPictureInPictureWindowSizePage));
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
ASSERT_TRUE(content::ExecuteScript(active_web_contents,
"setMediaSessionActionHandler('play');"));
ASSERT_TRUE(content::ExecuteScript(active_web_contents,
......@@ -2110,7 +2129,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
browser(), base::FilePath(kPictureInPictureWindowSizePage));
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
ASSERT_TRUE(content::ExecuteScript(
active_web_contents, "setMediaSessionActionHandler('nexttrack');"));
base::RunLoop().RunUntilIdle();
......@@ -2132,7 +2154,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
browser(), base::FilePath(kPictureInPictureWindowSizePage));
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
ASSERT_TRUE(content::ExecuteScript(
active_web_contents, "setMediaSessionActionHandler('previoustrack');"));
base::RunLoop().RunUntilIdle();
......@@ -2153,7 +2178,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
browser(), base::FilePath(kPictureInPictureWindowSizePage));
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "ensureVideoIsPlaying();", &result));
ASSERT_TRUE(result);
base::RunLoop().RunUntilIdle();
content::MediaSession::Get(active_web_contents)
......
......@@ -68,31 +68,31 @@
}, { once: true });
}
function ensureVideoIsPlaying() {
video.play()
.then(_ => { window.domAutomationController.send(true); })
.catch(e => { window.domAutomationController.send(false); });
}
function changeVideoSrc() {
if (video.srcObject) {
video.srcObject.getTracks().forEach(track => track.stop());
video.srcObject = null;
}
video.src = '../bigbuck.webm';
video.play()
.then(_ => { window.domAutomationController.send(true); })
.catch(e => { window.domAutomationController.send(false); });
ensureVideoIsPlaying();
}
function changeVideoSrcToMediaStream() {
const canvas = document.createElement('canvas');
canvas.getContext('2d').fillRect(0, 0, canvas.width, canvas.height);
video.srcObject = canvas.captureStream();
video.play()
.then(_ => { window.domAutomationController.send(true); })
.catch(e => { window.domAutomationController.send(false); });
ensureVideoIsPlaying();
}
function changeVideoSrcToNoAudioTrackVideo() {
video.src = '../engagement/engagement_no_audio_track.webm';
video.play()
.then(_ => { window.domAutomationController.send(true); })
.catch(e => { window.domAutomationController.send(false); });
ensureVideoIsPlaying();
}
function addVisibilityChangeEventListener() {
......
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