Commit 60a0db35 authored by Wojciech Dzierżanowski's avatar Wojciech Dzierżanowski Committed by Commit Bot

Modernize JS execution in PictureInPictureContentBrowserTest

Replace the semi-deprecated ExecuteScript*() functions with the modern
counterparts ExecJs(), EvalJs().

While we're here, let's make sure the test doesn't try to
requestPictureInPicture() until metadata has been loaded.

Bug: 1138168
Change-Id: Id247c2922f26e922417496f9cc406317ac061ebe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529121
Commit-Queue: Wojciech Dzierżanowski <wdzierzanowski@opera.com>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827738}
parent 719b80d5
......@@ -16,24 +16,6 @@
});
}
function play() {
video.play()
.then(_ => window.domAutomationController.send(true))
.catch(e => window.domAutomationController.send(false));
}
function enterPictureInPictureAndGetResult() {
video.requestPictureInPicture()
.then(_ => window.domAutomationController.send(true))
.catch(e => window.domAutomationController.send(false));
}
function enterFullscreenAndGetResult() {
video.requestFullscreen()
.then(_ => window.domAutomationController.send(true))
.catch(e => window.domAutomationController.send(false));
}
function addPlayEventListener() {
video.addEventListener('play', () => {
document.title = 'play';
......@@ -46,6 +28,35 @@
}, { once: true });
}
async function play() {
await video.play();
return true;
}
async function enterPictureInPicture() {
await _waitForMetadata();
await video.requestPictureInPicture();
return true;
}
function _waitForMetadata() {
return new Promise((resolve, _) => {
if (video.readyState >= HTMLMediaElement.HAVE_METADATA) {
resolve();
return;
}
video.addEventListener('loadedmetadata', () => {
resolve();
}, { once: true });
});
}
async function enterFullscreen() {
await video.requestFullscreen();
return true;
}
function setMediaSessionPlayActionHandler() {
navigator.mediaSession.setActionHandler("play", _ => {
video.play();
......
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