haikuwebkit/LayoutTests/media/presentationmodechanged-fir...

56 lines
1.9 KiB
HTML
Raw Permalink Normal View History

<!DOCTYPE html>
<html>
<head>
<script src="video-test.js"></script>
<script src="media-file.js"></script>
<script>
var eventCount = 0;
function go()
{
Stressing webkitSetPresentationMode leads to wrong inline video dimensions https://bugs.webkit.org/show_bug.cgi?id=202425 Reviewed by Eric Carlson. Source/WebCore: Make the HTMLVideoElement::setFullscreenMode() robust under stress tests by ignoring a request when the video element is not ready yet. Manually tested. * dom/Element.h: (WebCore::Element::didStopBeingFullscreenElement): Add a callback to indicate that the element has exited fullscreen. * dom/FullscreenManager.cpp: (WebCore::FullscreenManager::didExitFullscreen): Call Element::didStopBeingFullscreenElement() when the element has exited fullscreen. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::enterFullscreen): * html/HTMLMediaElement.h: * html/HTMLVideoElement.cpp: (WebCore::HTMLVideoElement::webkitDisplayingFullscreen): This function will return true when a video element is in the process to exit fullscreen/picture-in-picture until it has completed the process. Therefore, a page can safely request the video element to enter fullscreen/picture-in-picture when this function returns false. (WebCore::HTMLVideoElement::setFullscreenMode): (WebCore::HTMLVideoElement::didBecomeFullscreenElement): (WebCore::HTMLVideoElement::didStopBeingFullscreenElement): (WebCore::HTMLVideoElement::didEnterFullscreen): Deleted. (WebCore::HTMLVideoElement::didExitFullscreen): Deleted. * html/HTMLVideoElement.h: Add a flag m_isChangingPresentationMode. webkitSetPresentationMode() will only change the presentation mode when the flag is false. Source/WebKit: * WebProcess/cocoa/VideoFullscreenManager.mm: (WebKit::VideoFullscreenManager::didEnterFullscreen): (WebKit::VideoFullscreenManager::didCleanupFullscreen): Source/WebKitLegacy/mac: Move DumpRenderTree's implementation of the mock video presentation mode from WebView to WebChromeClient and call videoElement.didStopBeingFullscreenElement() when a video element exits fullscreen. * WebCoreSupport/WebChromeClient.h: * WebCoreSupport/WebChromeClient.mm: (WebChromeClient::setMockVideoPresentationModeEnabled): (WebChromeClient::enterVideoFullscreenForVideoElement): (WebChromeClient::exitVideoFullscreenForVideoElement): (WebChromeClient::exitVideoFullscreenToModeWithoutAnimation): * WebView/WebView.mm: (-[WebView _enterVideoFullscreenForVideoElement:mode:]): (-[WebView _exitVideoFullscreen]): (-[WebView _setMockVideoPresentationModeEnabled:]): Deleted. * WebView/WebViewData.h: * WebView/WebViewInternal.h: Tools: * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewCloseAllMediaPresentations.mm: (TEST): LayoutTests: Enable the mock video presentation mode in WebKitTestRunner and only request a video element to enter/exit fullscreen/picture-in-picture when the element is ready to do so (by checking the attribute webkitDisplayingFullscreen). * media/modern-media-controls/placard-support/placard-support-pip-expected.txt: * media/modern-media-controls/placard-support/placard-support-pip.html: * media/presentationmodechanged-fired-once-expected.txt: * media/presentationmodechanged-fired-once.html: * media/video-presentation-mode-expected.txt: * media/video-presentation-mode.html: Canonical link: https://commits.webkit.org/225486@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262456 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-06-02 22:26:02 +00:00
if (window.internals) {
internals.settings.setAllowsPictureInPictureMediaPlayback(true);
internals.setMockVideoPresentationModeEnabled(true);
}
findMediaElement();
run('video.src = findMediaFile("video", "content/test")');
waitForEventOnce('canplaythrough', canPlayThrough);
}
function canPlayThrough()
{
runWithKeyDown('video.play()');
runWithKeyDown('video.webkitSetPresentationMode("picture-in-picture")');
waitForEventOnce("webkitpresentationmodechanged", presentationModeChanged1);
}
Stressing webkitSetPresentationMode leads to wrong inline video dimensions https://bugs.webkit.org/show_bug.cgi?id=202425 Reviewed by Eric Carlson. Source/WebCore: Make the HTMLVideoElement::setFullscreenMode() robust under stress tests by ignoring a request when the video element is not ready yet. Manually tested. * dom/Element.h: (WebCore::Element::didStopBeingFullscreenElement): Add a callback to indicate that the element has exited fullscreen. * dom/FullscreenManager.cpp: (WebCore::FullscreenManager::didExitFullscreen): Call Element::didStopBeingFullscreenElement() when the element has exited fullscreen. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::enterFullscreen): * html/HTMLMediaElement.h: * html/HTMLVideoElement.cpp: (WebCore::HTMLVideoElement::webkitDisplayingFullscreen): This function will return true when a video element is in the process to exit fullscreen/picture-in-picture until it has completed the process. Therefore, a page can safely request the video element to enter fullscreen/picture-in-picture when this function returns false. (WebCore::HTMLVideoElement::setFullscreenMode): (WebCore::HTMLVideoElement::didBecomeFullscreenElement): (WebCore::HTMLVideoElement::didStopBeingFullscreenElement): (WebCore::HTMLVideoElement::didEnterFullscreen): Deleted. (WebCore::HTMLVideoElement::didExitFullscreen): Deleted. * html/HTMLVideoElement.h: Add a flag m_isChangingPresentationMode. webkitSetPresentationMode() will only change the presentation mode when the flag is false. Source/WebKit: * WebProcess/cocoa/VideoFullscreenManager.mm: (WebKit::VideoFullscreenManager::didEnterFullscreen): (WebKit::VideoFullscreenManager::didCleanupFullscreen): Source/WebKitLegacy/mac: Move DumpRenderTree's implementation of the mock video presentation mode from WebView to WebChromeClient and call videoElement.didStopBeingFullscreenElement() when a video element exits fullscreen. * WebCoreSupport/WebChromeClient.h: * WebCoreSupport/WebChromeClient.mm: (WebChromeClient::setMockVideoPresentationModeEnabled): (WebChromeClient::enterVideoFullscreenForVideoElement): (WebChromeClient::exitVideoFullscreenForVideoElement): (WebChromeClient::exitVideoFullscreenToModeWithoutAnimation): * WebView/WebView.mm: (-[WebView _enterVideoFullscreenForVideoElement:mode:]): (-[WebView _exitVideoFullscreen]): (-[WebView _setMockVideoPresentationModeEnabled:]): Deleted. * WebView/WebViewData.h: * WebView/WebViewInternal.h: Tools: * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewCloseAllMediaPresentations.mm: (TEST): LayoutTests: Enable the mock video presentation mode in WebKitTestRunner and only request a video element to enter/exit fullscreen/picture-in-picture when the element is ready to do so (by checking the attribute webkitDisplayingFullscreen). * media/modern-media-controls/placard-support/placard-support-pip-expected.txt: * media/modern-media-controls/placard-support/placard-support-pip.html: * media/presentationmodechanged-fired-once-expected.txt: * media/presentationmodechanged-fired-once.html: * media/video-presentation-mode-expected.txt: * media/video-presentation-mode.html: Canonical link: https://commits.webkit.org/225486@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262456 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-06-02 22:26:02 +00:00
async function presentationModeChanged1()
{
Let webkitDisplayingFullscreen() return true when a video element’s fullscreen mode is not VideoFullscreenModeNone https://bugs.webkit.org/show_bug.cgi?id=216426 Reviewed by Jer Noble. Source/WebCore: This patch moves m_changingVideoFullscreenMode of HTMLVideoElement to HTMLMediaElement. The flag is used to protect interfaces regarding video presentation mode changes. It also guards the code path when we use element fullscreen to implement video fullscreen (VIDEO_USES_ELEMENT_FULLSCREEN). It is better to store the flag in HTMLMediaElement to have fine control. This patch reverts the changing regarding HTMLVideoElement::webkitDisplayingFullscreen in r262456. This function will return true in the same run loop as a webkitpresentationmodechanged event is fired when a video element is entering fullscreen or picture-in-picture. Also, this patch adds Internals::isChangingPresentationMode which can be used by layout tests to check whether a video presentation mode change is completed. Covered by existing tests. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::isFullscreen const): Align the implementation with isStandardFullscreen(). (WebCore::HTMLMediaElement::enterFullscreen): Set m_changingVideoFullscreenMode to true if the video element is changing presentation mode. Also fix a bug about the flag m_waitingToEnterFullscreen. (WebCore::HTMLMediaElement::exitFullscreen): Ditto. (WebCore::HTMLMediaElement::didBecomeFullscreenElement): Ditto. (WebCore::HTMLMediaElement::didStopBeingFullscreenElement): Ditto. * html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::setChangingVideoFullscreenMode): (WebCore::HTMLMediaElement::isChangingVideoFullscreenMode const): (WebCore::HTMLMediaElement::waitingToEnterFullscreen): Deleted. * html/HTMLVideoElement.cpp: (WebCore::HTMLVideoElement::webkitDisplayingFullscreen): Revert the change in r262456. Some web sites expect this function to return true if the video element is entering fullscreen and the event webkitpresentationmodechanged is fired. (WebCore::HTMLVideoElement::setPresentationMode): Remove code regarding m_isChangingVideoFullscreenMode. (WebCore::HTMLVideoElement::didEnterFullscreenOrPictureInPicture): Fix an event firing issue when a video element is entering fullscreen while exiting picture-in-picture. (WebCore::HTMLVideoElement::didExitFullscreenOrPictureInPicture): Fix an event firing issue when a video element is exiting picture-in-picture. (WebCore::HTMLVideoElement::isChangingPresentationMode const): This interface is used by layout tests (through Internals) to check whether a video presentation mode change is completed. (WebCore::HTMLVideoElement::didBecomeFullscreenElement): Deleted. * html/HTMLVideoElement.h: * testing/Internals.cpp: (WebCore::Internals::isChangingPresentationMode const): This interface is used by layout tests to check whether a video presentation mode change is completed. * testing/Internals.h: * testing/Internals.idl: Tools: * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewCloseAllMediaPresentations.mm: (TEST): Use internals.isChangingPresentationMode() to make sure a video presentation mode change (from inline to picture-in-picture) is completed before moving to the next step of the test. LayoutTests: Check Internals::isChangingPresentationMode instead of HTMLVideoElement::webkitDisplayingFullscreen to confirm the video presentation mode change is completed before moving to the next step of a test. * http/tests/media/modern-media-controls/macos-fullscreen-media-controls/macos-fullscreen-media-controls-live-broadcast-expected.txt: * http/tests/media/modern-media-controls/macos-fullscreen-media-controls/macos-fullscreen-media-controls-live-broadcast.html: * media/context-menu-actions.html: * media/media-fullscreen-loop-inline-expected.txt: * media/media-fullscreen-loop-inline.html: * media/media-fullscreen-pause-inline-expected.txt: * media/media-fullscreen-pause-inline.html: * media/media-fullscreen-return-to-inline-expected.txt: * media/media-fullscreen-return-to-inline.html: * media/presentationmodechanged-fired-once-expected.txt: * media/presentationmodechanged-fired-once.html: * media/video-fullscreen-only-playback-expected.txt: * media/video-fullscreen-only-playback.html: * media/video-playsinline-expected.txt: * media/video-playsinline.html: * media/video-presentation-mode-expected.txt: * media/video-presentation-mode.html: * media/video-webkit-playsinline-expected.txt: * media/video-webkit-playsinline.html: * platform/mac/TestExpectations: Canonical link: https://commits.webkit.org/230793@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@268865 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-10-22 15:22:39 +00:00
await testExpectedEventually("internals.isChangingPresentationMode(video)", false);
testExpected("video.webkitPresentationMode", "picture-in-picture");
runWithKeyDown('video.webkitSetPresentationMode("inline")');
waitForEvent("webkitpresentationmodechanged", presentationModeChanged2);
}
function presentationModeChanged2()
{
switch (++eventCount)
{
case 1:
testExpected("video.webkitPresentationMode", "inline");
setTimeout(endTest, 200);
break;
default:
failTest("'webkitpresentationmodechanged' event fired again");
break;
}
}
</script>
</head>
<body onload="go()">
<div>This tests that the "webkitpresentationmodechanged" event is fired only once when the browser switches back to inline from the picture-in-picture mode.</div>
<video controls></video>
</body>
</html>