Diff
Modified: trunk/LayoutTests/ChangeLog (252056 => 252057)
--- trunk/LayoutTests/ChangeLog 2019-11-05 16:58:57 UTC (rev 252056)
+++ trunk/LayoutTests/ChangeLog 2019-11-05 17:13:00 UTC (rev 252057)
@@ -1,3 +1,16 @@
+2019-11-05 Andy Estes <[email protected]>
+
+ ApplePaySession should never prevent entering the back/forward cache
+ https://bugs.webkit.org/show_bug.cgi?id=203087
+ <rdar://problem/56744401>
+
+ Reviewed by Chris Dumez.
+
+ * http/tests/ssl/applepay/page-cache-active-apple-pay-session-expected.txt: Added.
+ * http/tests/ssl/applepay/page-cache-active-apple-pay-session.html: Added.
+ * http/tests/ssl/applepay/page-cache-inactive-apple-pay-session-expected.txt: Added.
+ * http/tests/ssl/applepay/page-cache-inactive-apple-pay-session.html: Added.
+
2019-11-05 youenn fablet <[email protected]>
MessagePort::close cannot assume that is execution context is not null
Added: trunk/LayoutTests/http/tests/ssl/applepay/page-cache-active-apple-pay-session-expected.txt (0 => 252057)
--- trunk/LayoutTests/http/tests/ssl/applepay/page-cache-active-apple-pay-session-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/ssl/applepay/page-cache-active-apple-pay-session-expected.txt 2019-11-05 17:13:00 UTC (rev 252057)
@@ -0,0 +1,14 @@
+Tests that a page with an active ApplePaySession goes into the back/forward cache.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+pageshow - not from cache
+pagehide - entering cache
+pageshow - from cache
+PASS Page did enter and was restored from the back/forward cache
+PASS ApplePaySession received a cancel event.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/http/tests/ssl/applepay/page-cache-active-apple-pay-session.html (0 => 252057)
--- trunk/LayoutTests/http/tests/ssl/applepay/page-cache-active-apple-pay-session.html (rev 0)
+++ trunk/LayoutTests/http/tests/ssl/applepay/page-cache-active-apple-pay-session.html 2019-11-05 17:13:00 UTC (rev 252057)
@@ -0,0 +1,50 @@
+<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
+<!DOCTYPE html>
+<html>
+<body>
+<script src=''></script>
+<script src=''></script>
+<script>
+description('Tests that a page with an active ApplePaySession goes into the back/forward cache.');
+window.jsTestIsAsync = true;
+
+window.addEventListener('pageshow', function(event) {
+ debug('pageshow - ' + (event.persisted ? '' : 'not ') + 'from cache');
+
+ if (event.persisted) {
+ testPassed('Page did enter and was restored from the back/forward cache');
+ }
+}, false);
+
+window.addEventListener('pagehide', function(event) {
+ debug('pagehide - ' + (event.persisted ? '' : 'not ') + 'entering cache');
+ if (!event.persisted) {
+ testFailed('Page failed to enter the back/forward cache.');
+ finishJSTest();
+ }
+}, false);
+
+window.addEventListener('load', function() {
+ UIHelper.withUserGesture(function() {
+ session = new ApplePaySession(1, {
+ countryCode: 'US',
+ currencyCode: 'USD',
+ supportedNetworks: ['visa', 'masterCard'],
+ merchantCapabilities: ['supports3DS'],
+ total: { label: 'Total', amount: '1.00' },
+ });
+ session.begin();
+ });
+
+ session.addEventListener('cancel', function() {
+ testPassed('ApplePaySession received a cancel event.');
+ finishJSTest();
+ });
+
+ setTimeout(function() {
+ window.location.href = '';
+ }, 0);
+}, false);
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/ssl/applepay/page-cache-inactive-apple-pay-session-expected.txt (0 => 252057)
--- trunk/LayoutTests/http/tests/ssl/applepay/page-cache-inactive-apple-pay-session-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/ssl/applepay/page-cache-inactive-apple-pay-session-expected.txt 2019-11-05 17:13:00 UTC (rev 252057)
@@ -0,0 +1,14 @@
+Tests that a page with an inactive ApplePaySession goes into the back/forward cache.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+pageshow - not from cache
+pagehide - entering cache
+pageshow - from cache
+PASS Page did enter and was restored from the back/forward cache
+PASS Idle ApplePaySession was able to begin and abort after restoring from the back/forward cache.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/http/tests/ssl/applepay/page-cache-inactive-apple-pay-session.html (0 => 252057)
--- trunk/LayoutTests/http/tests/ssl/applepay/page-cache-inactive-apple-pay-session.html (rev 0)
+++ trunk/LayoutTests/http/tests/ssl/applepay/page-cache-inactive-apple-pay-session.html 2019-11-05 17:13:00 UTC (rev 252057)
@@ -0,0 +1,55 @@
+<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
+<!DOCTYPE html>
+<html>
+<body>
+<script src=''></script>
+<script src=''></script>
+<script>
+description('Tests that a page with an inactive ApplePaySession goes into the back/forward cache.');
+window.jsTestIsAsync = true;
+
+window.addEventListener('pageshow', function(event) {
+ debug('pageshow - ' + (event.persisted ? '' : 'not ') + 'from cache');
+
+ if (!event.persisted)
+ return;
+
+ testPassed('Page did enter and was restored from the back/forward cache');
+
+ try {
+ session.begin();
+ session.abort();
+ testPassed('Idle ApplePaySession was able to begin and abort after restoring from the back/forward cache.');
+ } catch (e) {
+ testFailed('ApplePaySession was not idle after restoring from the back/forward cache.');
+ }
+
+ finishJSTest();
+}, false);
+
+window.addEventListener('pagehide', function(event) {
+ debug('pagehide - ' + (event.persisted ? '' : 'not ') + 'entering cache');
+ if (!event.persisted) {
+ testFailed('Page failed to enter the back/forward cache.');
+ finishJSTest();
+ }
+}, false);
+
+window.addEventListener('load', function() {
+ UIHelper.withUserGesture(function() {
+ session = new ApplePaySession(1, {
+ countryCode: 'US',
+ currencyCode: 'USD',
+ supportedNetworks: ['visa', 'masterCard'],
+ merchantCapabilities: ['supports3DS'],
+ total: { label: 'Total', amount: '1.00' },
+ });
+ });
+
+ setTimeout(function() {
+ window.location.href = '';
+ }, 0);
+}, false);
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (252056 => 252057)
--- trunk/Source/WebCore/ChangeLog 2019-11-05 16:58:57 UTC (rev 252056)
+++ trunk/Source/WebCore/ChangeLog 2019-11-05 17:13:00 UTC (rev 252057)
@@ -1,3 +1,23 @@
+2019-11-05 Andy Estes <[email protected]>
+
+ ApplePaySession should never prevent entering the back/forward cache
+ https://bugs.webkit.org/show_bug.cgi?id=203087
+ <rdar://problem/56744401>
+
+ Reviewed by Chris Dumez.
+
+ Rather than prevent entering the back/forward cache when there is an active session, abort
+ the session on suspension and queue a task to the event loop that dispatches the cancel event.
+
+ Tests: http/tests/ssl/applepay/page-cache-active-apple-pay-session.html
+ http/tests/ssl/applepay/page-cache-inactive-apple-pay-session.html
+
+ * Modules/applepay/ApplePaySession.cpp:
+ (WebCore::ApplePaySession::canSuspendWithoutCanceling const):
+ (WebCore::ApplePaySession::suspend):
+ (WebCore::ApplePaySession::shouldPreventEnteringBackForwardCache_DEPRECATED const): Deleted.
+ * Modules/applepay/ApplePaySession.h:
+
2019-11-05 youenn fablet <[email protected]>
MessagePort::close cannot assume that is execution context is not null
Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp (252056 => 252057)
--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp 2019-11-05 16:58:57 UTC (rev 252056)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp 2019-11-05 17:13:00 UTC (rev 252057)
@@ -823,7 +823,7 @@
return "ApplePaySession";
}
-bool ApplePaySession::shouldPreventEnteringBackForwardCache_DEPRECATED() const
+bool ApplePaySession::canSuspendWithoutCanceling() const
{
switch (m_state) {
case State::Idle:
@@ -830,7 +830,7 @@
case State::Aborted:
case State::Completed:
case State::Canceled:
- return false;
+ return true;
case State::Active:
case State::Authorized:
@@ -838,8 +838,7 @@
case State::ShippingContactSelected:
case State::PaymentMethodSelected:
case State::CancelRequested:
- // FIXME: This should never prevent entering the back/forward cache.
- return true;
+ return false;
}
}
@@ -854,6 +853,21 @@
didReachFinalState();
}
+void ApplePaySession::suspend(ReasonForSuspension reason)
+{
+ if (reason != ReasonForSuspension::BackForwardCache)
+ return;
+
+ if (canSuspendWithoutCanceling())
+ return;
+
+ m_state = State::Canceled;
+ paymentCoordinator().abortPaymentSession();
+ queueTaskToDispatchEvent(*this, TaskSource::UserInteraction, ApplePayCancelEvent::create(eventNames().cancelEvent, { }));
+
+ didReachFinalState();
+}
+
PaymentCoordinator& ApplePaySession::paymentCoordinator() const
{
return downcast<Document>(*scriptExecutionContext()).page()->paymentCoordinator();
Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.h (252056 => 252057)
--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.h 2019-11-05 16:58:57 UTC (rev 252056)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.h 2019-11-05 17:13:00 UTC (rev 252057)
@@ -102,8 +102,8 @@
// ActiveDOMObject.
const char* activeDOMObjectName() const override;
- bool shouldPreventEnteringBackForwardCache_DEPRECATED() const override;
void stop() override;
+ void suspend(ReasonForSuspension) override;
// EventTargetWithInlineData.
EventTargetInterface eventTargetInterface() const override { return ApplePaySessionEventTargetInterfaceType; }
@@ -130,6 +130,7 @@
bool canCompleteShippingContactSelection() const;
bool canCompletePaymentMethodSelection() const;
bool canCompletePayment() const;
+ bool canSuspendWithoutCanceling() const;
bool isFinalState() const;
void didReachFinalState();