haikuwebkit/LayoutTests/fast/web-share/share-transient-activation-...

60 lines
1.8 KiB
HTML
Raw Permalink Normal View History

Using Web Share API preceded by an AJAX call https://bugs.webkit.org/show_bug.cgi?id=197779 <rdar://problem/50708309> Reviewed by Dean Jackson. Source/WebCore: As per the Web Share specification, navigator.share() is supposed to reject the promise with a "NotAllowedError" DOMException if the relevant global object of this does not have transient activation [1]. However, our implementation was stricter and would reject the promise if we are not currently processing a user-gesture. This behavior did not match Chrome and does not appear to be Web compatible. To address the issue, this patch introduces the concept of transient activation [2] in WebKit and uses it in navigator.share() to match the specification more closely. Note that we are still a bit stricter than the specification because calling navigator.share() will currently "consume the activation" [3] to prevent the JS from presenting the share sheet more than once based on a single activation. However, our new behavior is still more permissive and more aligned with Chrome. [1] https://w3c.github.io/web-share/#dom-navigator-share [2] https://html.spec.whatwg.org/multipage/interaction.html#transient-activation [3] https://html.spec.whatwg.org/multipage/interaction.html#consume-user-activation Tests: fast/web-share/share-transient-activation-expired.html fast/web-share/share-transient-activation.html * dom/UserGestureIndicator.cpp: * dom/UserGestureIndicator.h: (WebCore::UserGestureToken::startTime const): * page/DOMWindow.cpp: (WebCore::transientActivationDurationOverrideForTesting): (WebCore::transientActivationDuration): (WebCore::DOMWindow::origin const): (WebCore::DOMWindow::securityOrigin const): (WebCore::DOMWindow::overrideTransientActivationDurationForTesting): (WebCore::DOMWindow::hasTransientActivation const): (WebCore::DOMWindow::consumeTransientActivation): (WebCore::DOMWindow::notifyActivated): * page/DOMWindow.h: * page/Navigator.cpp: (WebCore::Navigator::share): * testing/Internals.cpp: (WebCore::Internals::resetToConsistentState): (WebCore::Internals::setTransientActivationDuration): * testing/Internals.h: * testing/Internals.idl: LayoutTests: Add layout test coverage. * fast/web-share/share-transient-activation-expected.txt: Added. * fast/web-share/share-transient-activation-expired-expected.txt: Added. * fast/web-share/share-transient-activation-expired.html: Added. * fast/web-share/share-transient-activation.html: Added. Canonical link: https://commits.webkit.org/219037@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-08 01:07:25 +00:00
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
<html>
<meta name="viewport" content="initial-scale=5, width=device-width">
<head>
<script src="../../resources/ui-helper.js"></script>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
if (window.internals)
internals.setTransientActivationDuration(0.01); // Use very short 10ms transient activation duration for testing.
let write = (message) => output.innerHTML += (message + "<br>");
function runTest()
{
document.getElementById("target").addEventListener("click", () => {
fetch("../files/resources/abe.png").then(() => {
// Cause the transient activation to expire with a setTimeout.
setTimeout(() => {
navigator.share({ title: "Example Page", url: "http://webkit.org", text: "text" }).then((result) => {
Using Web Share API preceded by an AJAX call https://bugs.webkit.org/show_bug.cgi?id=197779 <rdar://problem/50708309> Reviewed by Dean Jackson. Source/WebCore: As per the Web Share specification, navigator.share() is supposed to reject the promise with a "NotAllowedError" DOMException if the relevant global object of this does not have transient activation [1]. However, our implementation was stricter and would reject the promise if we are not currently processing a user-gesture. This behavior did not match Chrome and does not appear to be Web compatible. To address the issue, this patch introduces the concept of transient activation [2] in WebKit and uses it in navigator.share() to match the specification more closely. Note that we are still a bit stricter than the specification because calling navigator.share() will currently "consume the activation" [3] to prevent the JS from presenting the share sheet more than once based on a single activation. However, our new behavior is still more permissive and more aligned with Chrome. [1] https://w3c.github.io/web-share/#dom-navigator-share [2] https://html.spec.whatwg.org/multipage/interaction.html#transient-activation [3] https://html.spec.whatwg.org/multipage/interaction.html#consume-user-activation Tests: fast/web-share/share-transient-activation-expired.html fast/web-share/share-transient-activation.html * dom/UserGestureIndicator.cpp: * dom/UserGestureIndicator.h: (WebCore::UserGestureToken::startTime const): * page/DOMWindow.cpp: (WebCore::transientActivationDurationOverrideForTesting): (WebCore::transientActivationDuration): (WebCore::DOMWindow::origin const): (WebCore::DOMWindow::securityOrigin const): (WebCore::DOMWindow::overrideTransientActivationDurationForTesting): (WebCore::DOMWindow::hasTransientActivation const): (WebCore::DOMWindow::consumeTransientActivation): (WebCore::DOMWindow::notifyActivated): * page/DOMWindow.h: * page/Navigator.cpp: (WebCore::Navigator::share): * testing/Internals.cpp: (WebCore::Internals::resetToConsistentState): (WebCore::Internals::setTransientActivationDuration): * testing/Internals.h: * testing/Internals.idl: LayoutTests: Add layout test coverage. * fast/web-share/share-transient-activation-expected.txt: Added. * fast/web-share/share-transient-activation-expired-expected.txt: Added. * fast/web-share/share-transient-activation-expired.html: Added. * fast/web-share/share-transient-activation.html: Added. Canonical link: https://commits.webkit.org/219037@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-08 01:07:25 +00:00
write("FAIL: Share sheet invoked.");
testRunner.notifyDone();
}, (exception) => {
write("PASS: Share promise was rejected: " + exception);
testRunner.notifyDone();
});
}, 100);
}, (exception) => {
write("FAIL: Fetch promise was rejected");
testRunner.notifyDone();
});
});
[ iOS wk2 ] imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https.html is a constant timeout https://bugs.webkit.org/show_bug.cgi?id=214694 <rdar://problem/66001110> Reviewed by Tim Horton. Tools: The test was failing because there was a share sheet still being presented from a previous Web Share test. TestController::platformResetStateToConsistentValues() would wait for that share sheet to get dismiss and would eventually give up and report the test as timing out. The issue is that WebKit layout test were relying on a UIScriptController function to dismiss the share sheet but Web Platform Tests did not. To address the issue, we now always promptly dismiss the share sheet in WebKitTestRunner, without the need for a UIScriptController function call. The Share Sheet now gets dismissed promptly in both WebKit tests and WPT tests. For robustness, I also added code in WebKitTestRunner to dismiss any remaining presented view controller after waiting, to avoid failing on the next test in such cases. * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl: * TestRunnerShared/UIScriptContext/UIScriptController.h: (WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted. * WebKitTestRunner/cocoa/UIScriptControllerCocoa.h: * WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm: (WTR::UIScriptControllerCocoa::setShareSheetCompletesImmediatelyWithResolution): Deleted. Delete UIScriptController.setShareSheetCompletesImmediatelyWithResolution() utility function for tests now that it is the default in WebKit TestRunner. * WebKitTestRunner/ios/TestControllerIOS.mm: (WTR::TestController::platformResetStateToConsistentValues): - Call _setShareSheetCompletesImmediatelyWithResolutionForTesting:YES on the test WKWebView instead of relying on individual tests to do that. - For robustness, if there is still a presented view controller after waiting, we now dismiss it ourselves instead of failing. This otherwise leads to next test to be reported as failing (or timing out) because there is a presented view controller that remains from the previous test. Note that this is not needed to fix the layout test in question since we now properly dismiss the share UI in WPT tests but I still think it is a good thing to do for robustness and avoid test flakiness. LayoutTests: * fast/web-share/share-transient-activation-expired.html: * fast/web-share/share-transient-activation.html: * fast/web-share/share-with-files.html: * fast/web-share/share-with-no-url.html: * fast/web-share/share.html: * platform/ios/TestExpectations: * resources/ui-helper.js: (window.UIHelper.setShareSheetCompletesImmediatelyWithResolution): Deleted. Update existing layout test so stop calling UIHelper.setShareSheetCompletesImmediatelyWithResolution() now that it is the default in WebKitTestRunner. * platform/ios/TestExpectations: Unskip test that is no longer timing out. Canonical link: https://commits.webkit.org/227560@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@264834 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-07-24 16:44:55 +00:00
UIHelper.activateAt(50, 50);
Using Web Share API preceded by an AJAX call https://bugs.webkit.org/show_bug.cgi?id=197779 <rdar://problem/50708309> Reviewed by Dean Jackson. Source/WebCore: As per the Web Share specification, navigator.share() is supposed to reject the promise with a "NotAllowedError" DOMException if the relevant global object of this does not have transient activation [1]. However, our implementation was stricter and would reject the promise if we are not currently processing a user-gesture. This behavior did not match Chrome and does not appear to be Web compatible. To address the issue, this patch introduces the concept of transient activation [2] in WebKit and uses it in navigator.share() to match the specification more closely. Note that we are still a bit stricter than the specification because calling navigator.share() will currently "consume the activation" [3] to prevent the JS from presenting the share sheet more than once based on a single activation. However, our new behavior is still more permissive and more aligned with Chrome. [1] https://w3c.github.io/web-share/#dom-navigator-share [2] https://html.spec.whatwg.org/multipage/interaction.html#transient-activation [3] https://html.spec.whatwg.org/multipage/interaction.html#consume-user-activation Tests: fast/web-share/share-transient-activation-expired.html fast/web-share/share-transient-activation.html * dom/UserGestureIndicator.cpp: * dom/UserGestureIndicator.h: (WebCore::UserGestureToken::startTime const): * page/DOMWindow.cpp: (WebCore::transientActivationDurationOverrideForTesting): (WebCore::transientActivationDuration): (WebCore::DOMWindow::origin const): (WebCore::DOMWindow::securityOrigin const): (WebCore::DOMWindow::overrideTransientActivationDurationForTesting): (WebCore::DOMWindow::hasTransientActivation const): (WebCore::DOMWindow::consumeTransientActivation): (WebCore::DOMWindow::notifyActivated): * page/DOMWindow.h: * page/Navigator.cpp: (WebCore::Navigator::share): * testing/Internals.cpp: (WebCore::Internals::resetToConsistentState): (WebCore::Internals::setTransientActivationDuration): * testing/Internals.h: * testing/Internals.idl: LayoutTests: Add layout test coverage. * fast/web-share/share-transient-activation-expected.txt: Added. * fast/web-share/share-transient-activation-expired-expected.txt: Added. * fast/web-share/share-transient-activation-expired.html: Added. * fast/web-share/share-transient-activation.html: Added. Canonical link: https://commits.webkit.org/219037@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-08 01:07:25 +00:00
}
</script>
<style>
#target {
height: 100px;
width: 100px;
background-color: silver;
}
</style>
</head>
<body onload="runTest()">
<pre id="output"></pre>
<button id="target">
</button>
</body>
</html>