[Web Payments] Reject abort when required

Bug: 722427
Change-Id: I262b166944cad827524b3828e0df53a500d99336
Reviewed-on: https://chromium-review.googlesource.com/506232
Commit-Queue: Anthony Vallee-Dubois <[email protected]>
Reviewed-by: Sebastien Seguin-Gagnon <[email protected]>
Reviewed-by: Mathieu Perreault <[email protected]>
Cr-Commit-Position: refs/heads/master@{#472567}
diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc
index af2ca0d..94474c7 100644
--- a/components/payments/content/payment_request.cc
+++ b/components/payments/content/payment_request.cc
@@ -148,13 +148,23 @@
 }
 
 void PaymentRequest::Abort() {
-  // The API user has decided to abort. We return a successful abort message to
-  // the renderer, which closes the Mojo message pipe, which triggers
+  // The API user has decided to abort. If a successful abort message is
+  // returned to the renderer, the Mojo message pipe is closed, which triggers
   // PaymentRequest::OnConnectionTerminated, which destroys this object.
-  // TODO(crbug.com/716546): Add a merchant abort metric,
-  RecordFirstCompletionStatus(JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
+  // Otherwise, the abort promise is rejected and the pipe is not closed.
+  // The abort is only successful if the payment app wasn't yet invoked.
+  // TODO(crbug.com/716546): Add a merchant abort metric
+
+  bool accepting_abort = !state_->IsPaymentAppInvoked();
+  if (accepting_abort) {
+    RecordFirstCompletionStatus(JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
+  }
+
   if (client_.is_bound())
-    client_->OnAbort(true /* aborted_successfully */);
+    client_->OnAbort(accepting_abort);
+
+  if (observer_for_testing_)
+    observer_for_testing_->OnAbortCalled();
 }
 
 void PaymentRequest::Complete(mojom::PaymentComplete result) {