Source/WebCore:
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2018 18:22:14 +0000 (18:22 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2018 18:22:14 +0000 (18:22 +0000)
[Payment Request] PaymentResponse.details should be updated when the user accepts a retried payment
https://bugs.webkit.org/show_bug.cgi?id=191440

Reviewed by Dean Jackson.

PaymentResponse.details was being initialized in the PaymentResponse constructor and never
updated when the user accepts a retried payment. We need to update it.

Added a test case to http/tests/paymentrequest/payment-response-retry-method.https.html.

* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::accept):
* Modules/paymentrequest/PaymentResponse.cpp:
(WebCore::PaymentResponse::PaymentResponse):
(WebCore::PaymentResponse::setDetailsFunction):
* Modules/paymentrequest/PaymentResponse.h:

LayoutTests:
[Payment Request] PaymentResponse.details should be updated when the user accepts a rpayment retry
https://bugs.webkit.org/show_bug.cgi?id=191440

Reviewed by Dean Jackson.

* http/tests/paymentrequest/payment-response-retry-method.https-expected.txt:
* http/tests/paymentrequest/payment-response-retry-method.https.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238041 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/paymentrequest/payment-response-retry-method.https-expected.txt
LayoutTests/http/tests/paymentrequest/payment-response-retry-method.https.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp
Source/WebCore/Modules/paymentrequest/PaymentResponse.cpp
Source/WebCore/Modules/paymentrequest/PaymentResponse.h

index 2809fa3..99b381e 100644 (file)
@@ -1,3 +1,13 @@
+2018-11-09  Andy Estes  <aestes@apple.com>
+
+        [Payment Request] PaymentResponse.details should be updated when the user accepts a rpayment retry
+        https://bugs.webkit.org/show_bug.cgi?id=191440
+
+        Reviewed by Dean Jackson.
+
+        * http/tests/paymentrequest/payment-response-retry-method.https-expected.txt:
+        * http/tests/paymentrequest/payment-response-retry-method.https.html:
+
 2018-11-09  Chris Dumez  <cdumez@apple.com>
 
         HTML form validation bubble disappears
index dffb760..dc2d3ad 100644 (file)
@@ -11,4 +11,5 @@ PASS When retrying, the user is shown error fields to fix.
 PASS When "abort the update" occurs because of an update error, the `retryPromise` is rejected and response.[[complete]] becomes true. 
 PASS Calling retry() multiple times is always a new object. 
 PASS When retrying without errors, the user is shown an `unknown` error. 
+PASS response.details should be updated after the user accepts a retry. 
 
index 77ba264..64a411a 100644 (file)
@@ -199,4 +199,14 @@ promise_test(async t => {
   await response.complete("success");
 }, "When retrying without errors, the user is shown an `unknown` error.");
 
+promise_test(async t => {
+  const { response, request } = await getPaymentRequestResponse({ requestShipping: true });
+  var originalDetails = response.details;
+  const retryPromise = response.retry();
+  internals.mockPaymentCoordinator.acceptPayment();
+  await retryPromise;
+  assert_not_equals(response.details, originalDetails, "response.details should be a new object after the user accepts a retry");
+  await response.complete("success");
+}, "response.details should be updated after the user accepts a retry.");
+
 </script>
index 00d9473..c10117d 100644 (file)
@@ -1,3 +1,22 @@
+2018-11-09  Andy Estes  <aestes@apple.com>
+
+        [Payment Request] PaymentResponse.details should be updated when the user accepts a retried payment
+        https://bugs.webkit.org/show_bug.cgi?id=191440
+
+        Reviewed by Dean Jackson.
+
+        PaymentResponse.details was being initialized in the PaymentResponse constructor and never
+        updated when the user accepts a retried payment. We need to update it.
+
+        Added a test case to http/tests/paymentrequest/payment-response-retry-method.https.html.
+
+        * Modules/paymentrequest/PaymentRequest.cpp:
+        (WebCore::PaymentRequest::accept):
+        * Modules/paymentrequest/PaymentResponse.cpp:
+        (WebCore::PaymentResponse::PaymentResponse):
+        (WebCore::PaymentResponse::setDetailsFunction):
+        * Modules/paymentrequest/PaymentResponse.h:
+
 2018-11-09  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         MediaPlayerPrivateMediaFoundation.h: warning: 'GetService' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
index 4f51aa4..3fecdea 100644 (file)
@@ -703,11 +703,12 @@ void PaymentRequest::accept(const String& methodName, PaymentResponse::DetailsFu
 
     bool isRetry = m_response;
     if (!isRetry) {
-        m_response = PaymentResponse::create(scriptExecutionContext(), *this, WTFMove(detailsFunction));
+        m_response = PaymentResponse::create(scriptExecutionContext(), *this);
         m_response->setRequestId(m_details.id);
     }
 
     m_response->setMethodName(methodName);
+    m_response->setDetailsFunction(WTFMove(detailsFunction));
     m_response->setShippingAddress(m_options.requestShipping ? shippingAddress.ptr() : nullptr);
     m_response->setShippingOption(m_options.requestShipping ? m_shippingOption : String { });
     m_response->setPayerName(m_options.requestPayerName ? payerName : String { });
index 5643fa4..dde78ef 100644 (file)
 
 namespace WebCore {
 
-PaymentResponse::PaymentResponse(ScriptExecutionContext* context, PaymentRequest& request, DetailsFunction&& detailsFunction)
+PaymentResponse::PaymentResponse(ScriptExecutionContext* context, PaymentRequest& request)
     : ActiveDOMObject { context }
     , m_request { makeWeakPtr(request) }
-    , m_detailsFunction { WTFMove(detailsFunction) }
 {
-    ASSERT(m_detailsFunction);
     suspendIfNeeded();
 }
 
@@ -55,6 +53,12 @@ PaymentResponse::~PaymentResponse()
     ASSERT(!hasRetryPromise());
 }
 
+void PaymentResponse::setDetailsFunction(DetailsFunction&& detailsFunction)
+{
+    m_detailsFunction = WTFMove(detailsFunction);
+    m_cachedDetails = { };
+}
+
 void PaymentResponse::complete(std::optional<PaymentComplete>&& result, DOMPromiseDeferred<void>&& promise)
 {
     if (m_state == State::Stopped || !m_request) {
index f7f0f57..97eac7f 100644 (file)
@@ -46,9 +46,9 @@ class PaymentResponse final : public ActiveDOMObject, public EventTargetWithInli
 public:
     using DetailsFunction = Function<JSC::Strong<JSC::JSObject>(JSC::ExecState&)>;
 
-    static Ref<PaymentResponse> create(ScriptExecutionContext* context, PaymentRequest& request, DetailsFunction&& detailsFunction)
+    static Ref<PaymentResponse> create(ScriptExecutionContext* context, PaymentRequest& request)
     {
-        auto response = adoptRef(*new PaymentResponse(context, request, WTFMove(detailsFunction)));
+        auto response = adoptRef(*new PaymentResponse(context, request));
         response->finishConstruction();
         return response;
     }
@@ -62,6 +62,8 @@ public:
     void setMethodName(const String& methodName) { m_methodName = methodName; }
 
     const DetailsFunction& detailsFunction() const { return m_detailsFunction; }
+    void setDetailsFunction(DetailsFunction&&);
+
     JSValueInWrappedObject& cachedDetails() { return m_cachedDetails; }
 
     PaymentAddress* shippingAddress() const { return m_shippingAddress.get(); }
@@ -89,7 +91,7 @@ public:
     using RefCounted<PaymentResponse>::deref;
 
 private:
-    PaymentResponse(ScriptExecutionContext*, PaymentRequest&, DetailsFunction&&);
+    PaymentResponse(ScriptExecutionContext*, PaymentRequest&);
     void finishConstruction();
 
     // ActiveDOMObject