Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: third_party/WebKit/Source/modules/payments/AbortTest.cpp

Issue 2048823004: PaymentRequest.abort() should return a promise. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove DummyPageHolder and TrackExceptionState for haraken@ comment. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/AbortTest.cpp
diff --git a/third_party/WebKit/Source/modules/payments/AbortTest.cpp b/third_party/WebKit/Source/modules/payments/AbortTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6ddb4d6bdd8a93271106cec0d00785b53f57d605
--- /dev/null
+++ b/third_party/WebKit/Source/modules/payments/AbortTest.cpp
@@ -0,0 +1,91 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "bindings/core/v8/ScriptState.h"
+#include "modules/payments/PaymentRequest.h"
+#include "modules/payments/PaymentRequestTestBase.h"
+#include "modules/payments/PaymentTestHelper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+namespace {
+
+// Tests for PaymentRequest::abort().
+class AbortTest : public PaymentRequestTestBase {
+};
+
+// If request.abort() is called without calling request.show() first, then
+// abort() should reject with exception.
+TEST_F(AbortTest, CannotAbortBeforeShow)
+{
+ ScriptState::Scope scope(getScriptState());
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
+
+ request->abort(getScriptState()).then(expectNoCall(), expectCall());
+}
+
+// If request.abort() is called again before the previous abort() resolved, then
+// the second abort() should reject with exception.
+TEST_F(AbortTest, CannotAbortTwiceConcurrently)
+{
+ ScriptState::Scope scope(getScriptState());
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
+ request->show(getScriptState());
+ request->abort(getScriptState());
+
+ request->abort(getScriptState()).then(expectNoCall(), expectCall());
+}
+
+// If request.abort() is called after calling request.show(), then abort()
+// should not reject with exception.
+TEST_F(AbortTest, CanAbortAfterShow)
+{
+ ScriptState::Scope scope(getScriptState());
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
+ request->show(getScriptState());
+
+ request->abort(getScriptState()).then(expectNoCall(), expectNoCall());
+}
+
+// If the browser is unable to abort the payment, then the request.abort()
+// promise should be rejected.
+TEST_F(AbortTest, FailedAbortShouldRejectAbortPromise)
+{
+ ScriptState::Scope scope(getScriptState());
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
+ request->show(getScriptState());
+
+ request->abort(getScriptState()).then(expectNoCall(), expectCall());
+
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(false);
+}
+
+// After the browser is unable to abort the payment once, the second abort()
+// call should not be rejected, as it's not a duplicate request anymore.
+TEST_F(AbortTest, CanAbortAgainAfterFirstAbortRejected)
+{
+ ScriptState::Scope scope(getScriptState());
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
+ request->show(getScriptState());
+ request->abort(getScriptState());
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(false);
+
+ request->abort(getScriptState()).then(expectNoCall(), expectNoCall());
+}
+
+// If the browser successfully aborts the payment, then the request.show()
+// promise should be rejected, and request.abort() promise should be resolved.
+TEST_F(AbortTest, SuccessfulAbortShouldRejectShowPromiseAndResolveAbortPromise)
+{
+ ScriptState::Scope scope(getScriptState());
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
+
+ request->show(getScriptState()).then(expectNoCall(), expectCall());
+ request->abort(getScriptState()).then(expectCall(), expectNoCall());
+
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(true);
+}
+
+} // namespace
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/modules.gypi ('k') | third_party/WebKit/Source/modules/payments/PaymentRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698