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

[Picture-in-Picture] Resolve with current window if video is pipElement.

This make sures requestPictureInPicture is resolved with existing
Picture-in-Picture window when video is already pictureInPictureElement.

Bug: 806249
Change-Id: I16e3fc2e8e19c2b623e8d2518fe4672a2a16b756
Reviewed-on: https://chromium-review.googlesource.com/1101686
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567934}
parent 9e8bb711
...@@ -34,6 +34,34 @@ promise_test(async t => { ...@@ -34,6 +34,34 @@ promise_test(async t => {
promise_test(async t => { promise_test(async t => {
const video = await loadVideo(); const video = await loadVideo();
video.addEventListener('leavepictureinpicture', t.step_func_done(event => {
assert_unreached('leavepictureinpicture event should not fire.')
}));
let enterCounts = 0;
video.addEventListener('enterpictureinpicture', event => {
enterCounts++;
});
return requestPictureInPictureWithTrustedClick(video)
.then(pipWindow1 => {
pipWindow1.onresize = function foo() {};
return requestPictureInPictureWithTrustedClick(video)
.then(pipWindow2 => {
assert_equals(pipWindow1, pipWindow2);
assert_equals(pipWindow1.width, pipWindow2.width);
assert_equals(pipWindow1.height, pipWindow2.height);
assert_equals(pipWindow1.onresize, pipWindow2.onresize);
assert_equals(enterCounts, 1);
});
});
}, 'Picture-in-Picture window is unchanged after entering ' +
'Picture-in-Picture for video already in Picture-in-Picture');
promise_test(async t => {
const video = await loadVideo();
return requestPictureInPictureWithTrustedClick(video) return requestPictureInPictureWithTrustedClick(video)
.then(pipWindow => { .then(pipWindow => {
return document.exitPictureInPicture() return document.exitPictureInPicture()
......
...@@ -82,9 +82,16 @@ PictureInPictureControllerImpl::IsElementAllowed( ...@@ -82,9 +82,16 @@ PictureInPictureControllerImpl::IsElementAllowed(
void PictureInPictureControllerImpl::EnterPictureInPicture( void PictureInPictureControllerImpl::EnterPictureInPicture(
HTMLVideoElement* element, HTMLVideoElement* element,
ScriptPromiseResolver* resolver) { ScriptPromiseResolver* resolver) {
element->enterPictureInPicture(WTF::Bind( if (picture_in_picture_element_ != element) {
&PictureInPictureControllerImpl::OnEnteredPictureInPicture, element->enterPictureInPicture(
WrapPersistent(this), WrapPersistent(element), WrapPersistent(resolver))); WTF::Bind(&PictureInPictureControllerImpl::OnEnteredPictureInPicture,
WrapPersistent(this), WrapPersistent(element),
WrapPersistent(resolver)));
return;
}
if (resolver)
resolver->Resolve(picture_in_picture_window_);
} }
void PictureInPictureControllerImpl::OnEnteredPictureInPicture( void PictureInPictureControllerImpl::OnEnteredPictureInPicture(
......
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