haikuwebkit/LayoutTests/fast/device-orientation/device-orientation-request-...

22 lines
504 B
HTML
Raw Permalink Normal View History

Add support for Device Orientation / Motion permission API https://bugs.webkit.org/show_bug.cgi?id=195329 <rdar://problem/47645367> Reviewed by Geoffrey Garen. Source/WebCore: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 Pages can add event listeners for 'deviceorientation' / 'devicemotion' events but such events will not be fired until the page's JavaScript calls DeviceOrientationEvent.requestPermission() / DeviceMotionEvent.requestPermission() and the user grants the request. The feature is currently behind an experimental feature flag, off by default. Tests: fast/device-orientation/device-motion-request-permission-denied.html fast/device-orientation/device-motion-request-permission-granted.html fast/device-orientation/device-motion-request-permission-user-gesture.html fast/device-orientation/device-orientation-request-permission-denied.html fast/device-orientation/device-orientation-request-permission-granted.html fast/device-orientation/device-orientation-request-permission-user-gesture.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * dom/DeviceMotionEvent.h: * dom/DeviceMotionEvent.idl: * dom/DeviceOrientationAndMotionAccessController.cpp: Added. (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController): (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): (WebCore::DeviceOrientationAndMotionAccessController::setAccessState): * dom/DeviceOrientationAndMotionAccessController.h: Added. (WebCore::DeviceOrientationAndMotionAccessController::accessState const): * dom/DeviceOrientationEvent.h: * dom/DeviceOrientationEvent.idl: * dom/DeviceOrientationOrMotionEvent.cpp: Added. (WebCore::DeviceOrientationOrMotionEvent::requestPermission): * dom/DeviceOrientationOrMotionEvent.h: Added. * dom/DeviceOrientationOrMotionEvent.idl: Added. * dom/DeviceOrientationOrMotionPermissionState.h: Added. * dom/DeviceOrientationOrMotionPermissionState.idl: Added. * dom/Document.cpp: (WebCore::Document::deviceOrientationAndMotionAccessController): * dom/Document.h: * dom/Event.cpp: * dom/MessagePort.cpp: * dom/Microtasks.cpp: * page/ChromeClient.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::addEventListener): (WebCore::DOMWindow::deviceOrientationController const): (WebCore::DOMWindow::deviceMotionController const): (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const): (WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const): (WebCore::DOMWindow::startListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::startListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::removeEventListener): (WebCore::DOMWindow::removeAllEventListeners): * page/DOMWindow.h: * page/DeviceController.cpp: (WebCore::DeviceController::hasDeviceEventListener const): * page/DeviceController.h: * page/Settings.yaml: Source/WebKit: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 This adds new SPI to WKUIDelegatePrivate, until we can make this API. * Shared/WebPreferences.yaml: * UIProcess/API/APIUIClient.h: (API::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/API/C/WKPage.cpp: (WKPageSetPageUIClient): * UIProcess/API/C/WKPageUIClient.h: * UIProcess/API/Cocoa/WKUIDelegate.h: * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: * UIProcess/Cocoa/UIDelegate.h: * UIProcess/Cocoa/UIDelegate.mm: (WebKit::UIDelegate::setDelegate): (WebKit::UIDelegate::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::requestDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebCoreSupport/WebChromeClient.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::nextDeviceOrientationAndMotionPermissionCallbackID): (WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess): (WebKit::WebPage::didReceiveDeviceOrientationAndMotionAccessDecision): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: Tools: Add test infrastructure to help test the Device Orientation / Motion permission API. * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/InjectedBundle/TestRunner.h: * WebKitTestRunner/TestController.cpp: (WTR::shouldAllowDeviceOrientationAndMotionAccess): (WTR::TestController::createWebViewWithOptions): (WTR::TestController::resetStateToConsistentValues): (WTR::TestController::handleDeviceOrientationAndMotionAccessRequest): * WebKitTestRunner/TestController.h: (WTR::TestController::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): LayoutTests: Add layout test coverage. * TestExpectations: * fast/device-orientation/device-motion-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-denied.html: Added. * fast/device-orientation/device-motion-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-granted.html: Added. * fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-user-gesture.html: Added. * fast/device-orientation/device-orientation-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-denied.html: Added. * fast/device-orientation/device-orientation-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-granted.html: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture.html: Added. * http/tests/events/device-orientation-motion-non-secure-context.html: * http/tests/events/device-orientation-motion-secure-context-expected.txt: * http/tests/events/device-orientation-motion-secure-context.html: * platform/ios-wk2/TestExpectations: * platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt: * platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt: Canonical link: https://commits.webkit.org/209800@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242664 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-09 00:30:45 +00:00
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test.js"></script>
<script>
description("Tests that DeviceOrientationEvent.requestPermission() requires a user gesture.");
jsTestIsAsync = true;
DeviceOrientationEvent.requestPermission().then((result) => {
testFailed("requestPermission promise was not rejected");
Device motion / orientation events not working in third-party iframes despite Feature-Policy allowing it https://bugs.webkit.org/show_bug.cgi?id=221399 <rdar://problem/74229227> Reviewed by Youenn Fablet. Source/WebCore: Allow third-party iframes to request access to device motion / orientation events if permitted via Feature-Policy. To match Blink, the following features need to be allowed via Feature-Policy: - DeviceOrientationEvent: gyroscope, accelerometer and magnetometer - DeviceMotionEvent: gyroscope and accelerometer Tests: http/tests/device-orientation/device-motion-allowed-in-first-party-only.html http/tests/device-orientation/device-motion-third-party-iframe-allowed-by-feature-policy.html http/tests/device-orientation/device-motion-third-party-iframe-denied-by-insufficient-feature-policy.html http/tests/device-orientation/device-motion-third-party-iframe-denied.html http/tests/device-orientation/device-orientation-allowed-in-first-party-only.html http/tests/device-orientation/device-orientation-third-party-iframe-allowed-by-feature-policy.html http/tests/device-orientation/device-orientation-third-party-iframe-denied-by-insufficient-feature-policy.html http/tests/device-orientation/device-orientation-third-party-iframe-denied.html * Sources.txt: * WebCore.xcodeproj/project.pbxproj: Drop DeviceOrientationOrMotionEvent class as it is no longer needed. * bindings/js/ScriptController.cpp: (WebCore::ScriptController::executeScriptInWorld): Make sure we specify the document when taking a user gesture when asked to run a script. This is important because some clients want to know that there was a user gesture for a document within their origin (like device motion & orientation). * dom/DeviceMotionEvent.cpp: (WebCore::DeviceMotionEvent::requestPermission): * dom/DeviceMotionEvent.h: * dom/DeviceOrientationEvent.cpp: (WebCore::DeviceOrientationEvent::requestPermission): * dom/DeviceOrientationEvent.h: Move requestPermission() from DeviceOrientationOrMotionEvent class to its subclasses now that their implementations are slightly different. * dom/DeviceOrientationAndMotionAccessController.cpp: (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController): (WebCore::DeviceOrientationAndMotionAccessController::accessState const): (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): (WebCore::DeviceOrientationAndMotionAccessController::clearPermissions): * dom/DeviceOrientationAndMotionAccessController.h: DeviceOrientationAndMotionAccessController is tied to the top document as used to have a single cached 'permission state' since we used to only support device orientation & motion events in first-party content. Now that we support those events in third-party content, I replaced the single 'permission state' data member into a map of 'permission state' per origin. This allows us to know synchronously (and without IPC to the UIProcess) the known permission state of each iframe. Also, I now pass the document to UserGestureIndicator::processingUserGesture() to make sure that interacting with the top frame does not allow a third-party iframe to request permission to use the device motion & orientation API. The user needs to interact with that third-party iframe to allow the iframe to prompt the user. * dom/DeviceOrientationOrMotionEvent.cpp: Removed. * dom/DeviceOrientationOrMotionEvent.h: Removed. Drop DeviceOrientationOrMotionEvent class now that the 2 subclasses need a slightly different implementation of requestPermission(). * dom/UserGestureIndicator.cpp: (WebCore::UserGestureToken::isValidForDocument const): Make parameter const since it can be. (WebCore::UserGestureIndicator::processingUserGesture): Check state first in the condition to avoid doing a null-deref when a UserGestureIndicator gets constructed with no |state| but with a non-null |document|. * dom/UserGestureIndicator.h: * html/FeaturePolicy.cpp: (WebCore::policyTypeName): (WebCore::FeaturePolicy::parse): (WebCore::FeaturePolicy::allows const): * html/FeaturePolicy.h: Add the following feature policies: accelerometer, gyroscope & magnetometer. https://github.com/w3c/webappsec-permissions-policy/blob/main/features.md * page/DOMWindow.cpp: (WebCore::DOMWindow::page const): (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrOrientation const): (WebCore::DOMWindow::isAllowedToUseDeviceMotion const): (WebCore::DOMWindow::isAllowedToUseDeviceOrientation const): (WebCore::DOMWindow::hasPermissionToReceiveDeviceMotionOrOrientationEvents const): (WebCore::DOMWindow::startListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::startListeningForDeviceMotionIfNecessary): * page/DOMWindow.h: Differentiate permission support for device motion and device orientation that they are different. In particular, the two types of events now require a different subset of feature policies. LayoutTests: Add layout test coverage. * TestExpectations: * fast/device-orientation/device-motion-request-permission-denied-expected.txt: * fast/device-orientation/device-motion-request-permission-granted-expected.txt: * fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt: * fast/device-orientation/device-orientation-request-permission-denied-expected.txt: * fast/device-orientation/device-orientation-request-permission-granted-expected.txt: * fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt: * fast/device-orientation/device-orientation-request-permission-user-gesture.html: * http/tests/device-orientation/device-motion-allowed-in-first-party-only-expected.txt: Added. * http/tests/device-orientation/device-motion-allowed-in-first-party-only.html: Added. * http/tests/device-orientation/device-motion-third-party-iframe-allowed-by-feature-policy-expected.txt: Added. * http/tests/device-orientation/device-motion-third-party-iframe-allowed-by-feature-policy.html: Added. * http/tests/device-orientation/device-motion-third-party-iframe-denied-by-insufficient-feature-policy-expected.txt: Added. * http/tests/device-orientation/device-motion-third-party-iframe-denied-by-insufficient-feature-policy.html: Added. * http/tests/device-orientation/device-motion-third-party-iframe-denied-expected.txt: Added. * http/tests/device-orientation/device-motion-third-party-iframe-denied.html: Added. * http/tests/device-orientation/device-orientation-allowed-in-first-party-only-expected.txt: Added. * http/tests/device-orientation/device-orientation-allowed-in-first-party-only.html: Added. * http/tests/device-orientation/device-orientation-third-party-iframe-allowed-by-feature-policy-expected.txt: Added. * http/tests/device-orientation/device-orientation-third-party-iframe-allowed-by-feature-policy.html: Added. * http/tests/device-orientation/device-orientation-third-party-iframe-denied-by-insufficient-feature-policy-expected.txt: Added. * http/tests/device-orientation/device-orientation-third-party-iframe-denied-by-insufficient-feature-policy.html: Added. * http/tests/device-orientation/device-orientation-third-party-iframe-denied-expected.txt: Added. * http/tests/device-orientation/device-orientation-third-party-iframe-denied.html: Added. * http/tests/device-orientation/resources/request-motion-events.html: Added. * http/tests/device-orientation/resources/request-orientation-events.html: Added. * platform/ios-wk2/TestExpectations: Canonical link: https://commits.webkit.org/234538@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273444 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-24 23:17:35 +00:00
finishJSTest();
Add support for Device Orientation / Motion permission API https://bugs.webkit.org/show_bug.cgi?id=195329 <rdar://problem/47645367> Reviewed by Geoffrey Garen. Source/WebCore: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 Pages can add event listeners for 'deviceorientation' / 'devicemotion' events but such events will not be fired until the page's JavaScript calls DeviceOrientationEvent.requestPermission() / DeviceMotionEvent.requestPermission() and the user grants the request. The feature is currently behind an experimental feature flag, off by default. Tests: fast/device-orientation/device-motion-request-permission-denied.html fast/device-orientation/device-motion-request-permission-granted.html fast/device-orientation/device-motion-request-permission-user-gesture.html fast/device-orientation/device-orientation-request-permission-denied.html fast/device-orientation/device-orientation-request-permission-granted.html fast/device-orientation/device-orientation-request-permission-user-gesture.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * dom/DeviceMotionEvent.h: * dom/DeviceMotionEvent.idl: * dom/DeviceOrientationAndMotionAccessController.cpp: Added. (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController): (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): (WebCore::DeviceOrientationAndMotionAccessController::setAccessState): * dom/DeviceOrientationAndMotionAccessController.h: Added. (WebCore::DeviceOrientationAndMotionAccessController::accessState const): * dom/DeviceOrientationEvent.h: * dom/DeviceOrientationEvent.idl: * dom/DeviceOrientationOrMotionEvent.cpp: Added. (WebCore::DeviceOrientationOrMotionEvent::requestPermission): * dom/DeviceOrientationOrMotionEvent.h: Added. * dom/DeviceOrientationOrMotionEvent.idl: Added. * dom/DeviceOrientationOrMotionPermissionState.h: Added. * dom/DeviceOrientationOrMotionPermissionState.idl: Added. * dom/Document.cpp: (WebCore::Document::deviceOrientationAndMotionAccessController): * dom/Document.h: * dom/Event.cpp: * dom/MessagePort.cpp: * dom/Microtasks.cpp: * page/ChromeClient.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::addEventListener): (WebCore::DOMWindow::deviceOrientationController const): (WebCore::DOMWindow::deviceMotionController const): (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const): (WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const): (WebCore::DOMWindow::startListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::startListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::removeEventListener): (WebCore::DOMWindow::removeAllEventListeners): * page/DOMWindow.h: * page/DeviceController.cpp: (WebCore::DeviceController::hasDeviceEventListener const): * page/DeviceController.h: * page/Settings.yaml: Source/WebKit: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 This adds new SPI to WKUIDelegatePrivate, until we can make this API. * Shared/WebPreferences.yaml: * UIProcess/API/APIUIClient.h: (API::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/API/C/WKPage.cpp: (WKPageSetPageUIClient): * UIProcess/API/C/WKPageUIClient.h: * UIProcess/API/Cocoa/WKUIDelegate.h: * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: * UIProcess/Cocoa/UIDelegate.h: * UIProcess/Cocoa/UIDelegate.mm: (WebKit::UIDelegate::setDelegate): (WebKit::UIDelegate::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::requestDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebCoreSupport/WebChromeClient.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::nextDeviceOrientationAndMotionPermissionCallbackID): (WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess): (WebKit::WebPage::didReceiveDeviceOrientationAndMotionAccessDecision): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: Tools: Add test infrastructure to help test the Device Orientation / Motion permission API. * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/InjectedBundle/TestRunner.h: * WebKitTestRunner/TestController.cpp: (WTR::shouldAllowDeviceOrientationAndMotionAccess): (WTR::TestController::createWebViewWithOptions): (WTR::TestController::resetStateToConsistentValues): (WTR::TestController::handleDeviceOrientationAndMotionAccessRequest): * WebKitTestRunner/TestController.h: (WTR::TestController::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): LayoutTests: Add layout test coverage. * TestExpectations: * fast/device-orientation/device-motion-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-denied.html: Added. * fast/device-orientation/device-motion-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-granted.html: Added. * fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-user-gesture.html: Added. * fast/device-orientation/device-orientation-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-denied.html: Added. * fast/device-orientation/device-orientation-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-granted.html: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture.html: Added. * http/tests/events/device-orientation-motion-non-secure-context.html: * http/tests/events/device-orientation-motion-secure-context-expected.txt: * http/tests/events/device-orientation-motion-secure-context.html: * platform/ios-wk2/TestExpectations: * platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt: * platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt: Canonical link: https://commits.webkit.org/209800@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242664 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-09 00:30:45 +00:00
}, (_e) => {
e = _e;
console.log(e);
shouldBeEqualToString("e.name", "NotAllowedError");
finishJSTest();
});
</script>
</body>
</html>