haikuwebkit/LayoutTests/fast/mediastream/get-display-media-muted.html

84 lines
3.4 KiB
HTML
Raw Permalink Normal View History

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mute screen capture, make sure page state updates correctly.</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
if (window.testRunner)
testRunner.setUserMediaPermission(true);
Enforce user gesture for getUserMedia in case a previous getUserMedia call was denied https://bugs.webkit.org/show_bug.cgi?id=203362 Source/WebCore: Reviewed by Eric Carlson. Compute whether a media request is user priviledged or not. It is priviledged if it is created as part of a user gesture and no request of the same type has been previously created for the same user gesture. If getDisplayMedia is called twice as part of a single user gesture, getDisplaMedia will reject for the second call. Remove the internal ability to disable user gesture check. Instead use internals API to simulate a user gesture. Test: fast/mediastream/getUserMedia-deny-persistency5.html and updated test. * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::computeUserGesturePriviledge): (WebCore::MediaDevices::getUserMedia): (WebCore::MediaDevices::getDisplayMedia): (WebCore::MediaDevices::getUserMedia const): Deleted. (WebCore::MediaDevices::getDisplayMedia const): Deleted. * Modules/mediastream/MediaDevices.h: * platform/mediastream/MediaStreamRequest.h: (WebCore::MediaStreamRequest::encode const): (WebCore::MediaStreamRequest::decode): * testing/Internals.cpp: (WebCore::Internals::setMediaStreamSourceInterrupted): (WebCore::Internals::setDisableGetDisplayMediaUserGestureConstraint): Deleted. * testing/Internals.h: * testing/Internals.idl: Source/WebKit: Reviewed by Eric Carlson. In case the request has user gesture priviledge, do not look at denied request history. * UIProcess/UserMediaPermissionRequestManagerProxy.cpp: (WebKit::UserMediaPermissionRequestManagerProxy::getRequestAction): * UIProcess/UserMediaPermissionRequestProxy.h: (WebKit::UserMediaPermissionRequestProxy::isUserGesturePriviledged const): Tools: Reviewed by Eric Carlson. * TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm: (TestWebKitAPI::TEST_F): Update test to take into account the ability to ask again for permission. * TestWebKitAPI/Tests/WebKit/getDisplayMedia.html: Update to make sure we notify test if internals is not available. LayoutTests: <rdar://problem/56648232> Reviewed by Eric Carlson. * fast/mediastream/constraint-intrinsic-size.html: * fast/mediastream/get-display-media-muted.html: * fast/mediastream/getUserMedia-deny-persistency5-expected.txt: * fast/mediastream/getUserMedia-deny-persistency5.html: * fast/mediastream/media-stream-page-muted.html: Use user gesture simulation instead of disabling user gesture check. * fast/mediastream/screencapture-user-gesture.html: * fast/mediastream/screencapture-user-gesture-expected.txt: * http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt: * http/tests/media/media-stream/get-display-media-prompt.html: * http/tests/media/media-stream/resources/get-display-media-devices-iframe.html: * resources/testharnessreport.js: Canonical link: https://commits.webkit.org/217202@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252046 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-11-05 09:14:33 +00:00
function callGetDisplayMedia(options)
{
let promise;
window.internals.withUserGesture(() => {
promise = navigator.mediaDevices.getDisplayMedia(options);
});
return promise;
}
async function waitForPageStateChange(numberOfTries, originalState)
{
return new Promise(async (resolve) => {
while (numberOfTries) {
if (internals.pageMediaState() != originalState) {
resolve(true);
return;
}
await new Promise(resolve => { setTimeout(resolve, 10) });
--numberOfTries;
}
resolve(false);
});
}
promise_test(async (test) => {
await new Promise(async (resolve, reject) => {
Enforce user gesture for getUserMedia in case a previous getUserMedia call was denied https://bugs.webkit.org/show_bug.cgi?id=203362 Source/WebCore: Reviewed by Eric Carlson. Compute whether a media request is user priviledged or not. It is priviledged if it is created as part of a user gesture and no request of the same type has been previously created for the same user gesture. If getDisplayMedia is called twice as part of a single user gesture, getDisplaMedia will reject for the second call. Remove the internal ability to disable user gesture check. Instead use internals API to simulate a user gesture. Test: fast/mediastream/getUserMedia-deny-persistency5.html and updated test. * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::computeUserGesturePriviledge): (WebCore::MediaDevices::getUserMedia): (WebCore::MediaDevices::getDisplayMedia): (WebCore::MediaDevices::getUserMedia const): Deleted. (WebCore::MediaDevices::getDisplayMedia const): Deleted. * Modules/mediastream/MediaDevices.h: * platform/mediastream/MediaStreamRequest.h: (WebCore::MediaStreamRequest::encode const): (WebCore::MediaStreamRequest::decode): * testing/Internals.cpp: (WebCore::Internals::setMediaStreamSourceInterrupted): (WebCore::Internals::setDisableGetDisplayMediaUserGestureConstraint): Deleted. * testing/Internals.h: * testing/Internals.idl: Source/WebKit: Reviewed by Eric Carlson. In case the request has user gesture priviledge, do not look at denied request history. * UIProcess/UserMediaPermissionRequestManagerProxy.cpp: (WebKit::UserMediaPermissionRequestManagerProxy::getRequestAction): * UIProcess/UserMediaPermissionRequestProxy.h: (WebKit::UserMediaPermissionRequestProxy::isUserGesturePriviledged const): Tools: Reviewed by Eric Carlson. * TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm: (TestWebKitAPI::TEST_F): Update test to take into account the ability to ask again for permission. * TestWebKitAPI/Tests/WebKit/getDisplayMedia.html: Update to make sure we notify test if internals is not available. LayoutTests: <rdar://problem/56648232> Reviewed by Eric Carlson. * fast/mediastream/constraint-intrinsic-size.html: * fast/mediastream/get-display-media-muted.html: * fast/mediastream/getUserMedia-deny-persistency5-expected.txt: * fast/mediastream/getUserMedia-deny-persistency5.html: * fast/mediastream/media-stream-page-muted.html: Use user gesture simulation instead of disabling user gesture check. * fast/mediastream/screencapture-user-gesture.html: * fast/mediastream/screencapture-user-gesture-expected.txt: * http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt: * http/tests/media/media-stream/get-display-media-prompt.html: * http/tests/media/media-stream/resources/get-display-media-devices-iframe.html: * resources/testharnessreport.js: Canonical link: https://commits.webkit.org/217202@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252046 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-11-05 09:14:33 +00:00
let stream = await callGetDisplayMedia({ video: true });
let pageMediaState = internals.pageMediaState();
assert_false(pageMediaState.includes('HasMutedDisplayCaptureDevice'), 'page state does not include HasMutedDisplayCaptureDevice');
assert_false(pageMediaState.includes('HasMutedVideoCaptureDevice'), 'page state does not include HasMutedVideoCaptureDevice');
assert_false(pageMediaState.includes('HasMutedAudioCaptureDevice'), 'page state does not include HasMutedAudioCaptureDevice');
let track = stream.getVideoTracks()[0];
track.onunmute = () => { assert_unreached("Got 'unmute' event unexpectedly!") };
track.onmute = async (evt) => {
if (!await waitForPageStateChange(10, pageMediaState))
assert_unreached(`Page state did not change from ${pageMediaState}`);
track.onunmute = async (evt) => {
if (!await waitForPageStateChange(10, pageMediaState))
assert_unreached(`Page state did not change from ${pageMediaState}`);
pageMediaState = internals.pageMediaState();
assert_false(pageMediaState.includes('HasMutedDisplayCaptureDevice'), 'page state does not include HasMutedDisplayCaptureDevice');
assert_true(pageMediaState.includes('HasActiveDisplayCaptureDevice'), 'page state includes HasActiveDisplayCaptureDevice');
resolve()
}
pageMediaState = internals.pageMediaState();
assert_true(pageMediaState.includes('HasMutedDisplayCaptureDevice'), 'page state includes HasMutedDisplayCaptureDevice');
assert_false(pageMediaState.includes('HasActiveDisplayCaptureDevice'), 'page state does not include HasActiveDisplayCaptureDevice');
internals.setMediaStreamTrackMuted(track, false)
}
pageMediaState = internals.pageMediaState();
internals.setMediaStreamTrackMuted(track, true);
setTimeout(() => reject("Muted state did not change in .5 second"), 500);
});
}, "Mute video track during screen capture");
</script>
</head>
<body>
</body>
</html>