[Payment Request] Implement PaymentResponse.retry()
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Oct 2018 19:07:40 +0000 (19:07 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Oct 2018 19:07:40 +0000 (19:07 +0000)
commit98611f6b588a52f0a0d552d8c8e83428c15e7cf8
tree2984f798566704ed5d29abc21d89da6dec0ede1e
parentb577a6272c6ebc18632ce0255be70d495b758178
[Payment Request] Implement PaymentResponse.retry()
https://bugs.webkit.org/show_bug.cgi?id=190985

Source/WebCore:

Reviewed by Daniel Bates.

Implemented the retry() method on PaymentResponse as specified in the Payment Request API
W3C Editor's Draft of 24 October 2018.

See https://w3c.github.io/payment-request/#retry-method for details.

Tests: http/tests/paymentrequest/payment-response-rejects-if-not-active.https.html
       http/tests/paymentrequest/payment-response-retry-method.https.html

* Modules/applepay/PaymentCoordinator.h:
(WebCore::PaymentCoordinator::client): Added. Returns m_client.
* Modules/applepay/PaymentCoordinatorClient.h:
(WebCore::PaymentCoordinatorClient::isMockPaymentCoordinator const): Added. Used to downcast
a PaymentCoordinatorClient to a MockPaymentCoordinator.
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::ApplePayPaymentHandler::computeTotalAndLineItems const): Made const.
(WebCore::ApplePayPaymentHandler::computeErrors const): Broke this function into
computeAddressErrors, computePayerErrors, and computePaymentMethodErrors, then modified this
function to call those functions. Exceptions thrown by computePaymentMethodErrors are ignored.
(WebCore::ApplePayPaymentHandler::computeAddressErrors const): Added.
(WebCore::ApplePayPaymentHandler::computePayerErrors const): Added.
(WebCore::ApplePayPaymentHandler::computePaymentMethodErrors const): Added.
(WebCore::ApplePayPaymentHandler::complete): Added ASSERTs to verify whether result is a
final result.
(WebCore::ApplePayPaymentHandler::retry): Computed PaymentErrors from PaymentValidationErrors,
ensured the PaymentAuthorizationResult was non-final by adding an unknown error if necessary,
and called PaymentCoordinator::completePaymentSession.
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
* Modules/paymentrequest/PaymentHandler.h:
* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::show): Changed to call settleShowPromise.
(WebCore::PaymentRequest::abortWithException): Changed to abort PaymentResponse's retry
promise, if present, instead of PaymentResponse's show promise.
(WebCore::PaymentRequest::settleShowPromise): Added. Settles m_showPromise then sets it to
std::nullopt.
(WebCore::PaymentRequest::closeActivePaymentHandler): Added. Hides the active payment
handler then sets it to std::nullopt.
(WebCore::PaymentRequest::stop): Stopped calling abortWithException, since that function
might settle PaymentResponse's retry promise. PaymentResponse is now an ActiveDOMObject and
will settle its own promise in its implementation of stop.
(WebCore::PaymentRequest::abort): Changed to throw an InvalidStateError if there is a
pending retry promise and to call abortWithException instead of stop.
(WebCore::PaymentRequest::completeMerchantValidation): Changed to call abortWithException
instead of stop.
(WebCore::PaymentRequest::settleDetailsPromise): Ditto.
(WebCore::PaymentRequest::accept): Updated the existing PaymentResponse, if present, rather
than creating a new one. Settled the existing PaymentResponse's retry promise, if present,
rather than the show promise.
(WebCore::PaymentRequest::complete): Changed to throw an AbortError if there is no longer an
active payment handler.
(WebCore::PaymentRequest::retry): Changed to throw an AbortError if there is no longer an
active payment handler, and to call PaymentHandler::retry if there is.
(WebCore::PaymentRequest::cancel): Changed to call abortWithException instead of stop.
* Modules/paymentrequest/PaymentRequest.h:
* Modules/paymentrequest/PaymentRequest.idl:
* Modules/paymentrequest/PaymentResponse.cpp:
(WebCore::PaymentResponse::PaymentResponse):
(WebCore::PaymentResponse::finishConstruction): Pending activities create strong references
to |this|, so they cannot be created in constructors without relaxing adoption requirements.
Added this function so that the pending activity can be created after the PaymentResponse is
created and adopted.
(WebCore::PaymentResponse::~PaymentResponse):
(WebCore::PaymentResponse::complete): Updated to throw an AbortError or InvalidStateError
when necessary.
(WebCore::PaymentResponse::retry): Implemented. Throws an AbortError or InvalidStateError
when necessary, otherwise calls PaymentRequest::retry and stores the retry promise in
m_retryPromise.
(WebCore::PaymentResponse::abortWithException): Added. Rejects the retry promise with
|exception|, clears the pending activity, and sets m_state to Completed.
(WebCore::PaymentResponse::settleRetryPromise): Added. Settles the retry promise and sets it
to std::nullopt.
(WebCore::PaymentResponse::canSuspendForDocumentSuspension const): Added. Returns true if
there is no pending activity.
(WebCore::PaymentResponse::stop): Added. Rejects the retry promise with AbortError, clears
the pending activity, and sets m_state to Stopped.
* Modules/paymentrequest/PaymentResponse.h: Changed create to call finishConstruction and
made PaymentResponse an ActiveDOMObject instead of a ContextDestructionObserver.
* testing/Internals.cpp:
(WebCore::Internals::Internals): Changed to only create a MockPaymentCoordinator for main frames.
(WebCore::Internals::mockPaymentCoordinator): Changed to get the MockPaymentCoordinator by
downcasting the page's payment coordinator client.
* testing/Internals.h:
* testing/Internals.idl:
* testing/MockPaymentCoordinator.cpp:
(WebCore::MockPaymentCoordinator::completePaymentSession): Changed to only increment
hideCount for final results.
* testing/MockPaymentCoordinator.h:
(isType): Added so that PaymentCoordinatorClients can be downcasted to MockPaymentCoordinators.

LayoutTests:

Reviewed by Daniel Bates

* http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https.html:
* http/tests/paymentrequest/payment-response-complete-method.https.html:
* http/tests/paymentrequest/payment-response-methodName-attribute.https.html:
* http/tests/paymentrequest/payment-response-payerEmail-attribute.https.html:
* http/tests/paymentrequest/payment-response-payerName-attribute.https.html:
* http/tests/paymentrequest/payment-response-payerPhone-attribute.https.html:
* http/tests/paymentrequest/payment-response-rejects-if-not-active.https-expected.txt: Added.
* http/tests/paymentrequest/payment-response-rejects-if-not-active.https.html: Copied from
imported/w3c/web-platform-tests/payment-request/payment-response/rejects_if_not_active-manual.https.html
and automated using internals.mockPaymentCoordinator.
* http/tests/paymentrequest/payment-response-retry-method.https-expected.txt: Added.
* http/tests/paymentrequest/payment-response-retry-method.https.html: Copied from
imported/w3c/web-platform-tests/payment-request/payment-response/retry-method-manual.https.html
and automated using internals.mockPaymentCoordinator.
* http/tests/paymentrequest/resources/helpers.js:
(setUpAndSmokeTest):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237597 268f45cc-cd09-0410-ab3c-d52691b4dbfc
28 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https.html
LayoutTests/http/tests/paymentrequest/payment-response-complete-method.https.html
LayoutTests/http/tests/paymentrequest/payment-response-methodName-attribute.https.html
LayoutTests/http/tests/paymentrequest/payment-response-payerEmail-attribute.https.html
LayoutTests/http/tests/paymentrequest/payment-response-payerName-attribute.https.html
LayoutTests/http/tests/paymentrequest/payment-response-payerPhone-attribute.https.html
LayoutTests/http/tests/paymentrequest/payment-response-rejects-if-not-active.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/paymentrequest/payment-response-rejects-if-not-active.https.html [new file with mode: 0644]
LayoutTests/http/tests/paymentrequest/payment-response-retry-method.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/paymentrequest/payment-response-retry-method.https.html [new file with mode: 0644]
LayoutTests/http/tests/paymentrequest/resources/helpers.js
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/PaymentCoordinator.h
Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h
Source/WebCore/Modules/paymentrequest/PaymentHandler.h
Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp
Source/WebCore/Modules/paymentrequest/PaymentRequest.h
Source/WebCore/Modules/paymentrequest/PaymentRequest.idl
Source/WebCore/Modules/paymentrequest/PaymentResponse.cpp
Source/WebCore/Modules/paymentrequest/PaymentResponse.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebCore/testing/MockPaymentCoordinator.cpp
Source/WebCore/testing/MockPaymentCoordinator.h