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..33fe482fac1afd0b31d39a10b7539f978d261fc7 |
--- /dev/null |
+++ b/third_party/WebKit/Source/modules/payments/AbortTest.cpp |
@@ -0,0 +1,72 @@ |
+// 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/MockFunction.h" |
+#include "modules/payments/PaymentDetailsTestHelper.h" |
+#include "modules/payments/PaymentRequest.h" |
+#include "modules/payments/PaymentRequestTestBase.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(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
+ EXPECT_FALSE(getExceptionState().hadException()); |
+ |
+ request->abort(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
+} |
+ |
+// 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(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
+ EXPECT_FALSE(getExceptionState().hadException()); |
+ request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectNoCall(getScriptState())); |
+ |
+ request->abort(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectNoCall(getScriptState())); |
+} |
+ |
+// 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(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
+ EXPECT_FALSE(getExceptionState().hadException()); |
+ request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectNoCall(getScriptState())); |
+ |
+ request->abort(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
+ |
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(false); |
+} |
+ |
+// 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(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
+ EXPECT_FALSE(getExceptionState().hadException()); |
+ |
+ request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
+ request->abort(getScriptState()).then(MockFunction::expectCall(getScriptState()), MockFunction::expectNoCall(getScriptState())); |
+ |
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(true); |
+} |
+ |
+} // namespace |
+} // namespace blink |