OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "bindings/core/v8/ScriptState.h" |
| 6 #include "modules/payments/MockFunction.h" |
| 7 #include "modules/payments/PaymentDetailsTestHelper.h" |
| 8 #include "modules/payments/PaymentRequest.h" |
| 9 #include "modules/payments/PaymentRequestTestBase.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace blink { |
| 13 namespace { |
| 14 |
| 15 // Tests for PaymentRequest::abort(). |
| 16 class AbortTest : public PaymentRequestTestBase { |
| 17 }; |
| 18 |
| 19 // If request.abort() is called without calling request.show() first, |
| 20 // then abort() should reject with exception. |
| 21 TEST_F(AbortTest, CannotAbortBeforeShow) |
| 22 { |
| 23 ScriptState::Scope scope(getScriptState()); |
| 24 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
| 25 EXPECT_FALSE(getExceptionState().hadException()); |
| 26 |
| 27 request->abort(getScriptState()).then(MockFunction::expectNoCall(getScriptSt
ate()), MockFunction::expectCall(getScriptState())); |
| 28 } |
| 29 |
| 30 // If request.abort() is called after calling request.show(), |
| 31 // then abort() should not reject with exception. |
| 32 TEST_F(AbortTest, CanAbortAfterShow) |
| 33 { |
| 34 ScriptState::Scope scope(getScriptState()); |
| 35 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
| 36 EXPECT_FALSE(getExceptionState().hadException()); |
| 37 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 38 |
| 39 request->abort(getScriptState()).then(MockFunction::expectNoCall(getScriptSt
ate()), MockFunction::expectNoCall(getScriptState())); |
| 40 } |
| 41 |
| 42 // If the browser is unable to abort the payment, |
| 43 // then the request.abort() promise should be rejected. |
| 44 TEST_F(AbortTest, FailedAbortShouldRejectAbortPromise) |
| 45 { |
| 46 ScriptState::Scope scope(getScriptState()); |
| 47 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
| 48 EXPECT_FALSE(getExceptionState().hadException()); |
| 49 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 50 |
| 51 request->abort(getScriptState()).then(MockFunction::expectNoCall(getScriptSt
ate()), MockFunction::expectCall(getScriptState())); |
| 52 |
| 53 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(false); |
| 54 } |
| 55 |
| 56 // If the browser successfully aborts the payment, |
| 57 // then the request.show() promise should be rejected, |
| 58 // and request.abort() promise should be resolved. |
| 59 TEST_F(AbortTest, SuccessfulAbortShouldRejectShowPromiseAndResolveAbortPromise) |
| 60 { |
| 61 ScriptState::Scope scope(getScriptState()); |
| 62 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
| 63 EXPECT_FALSE(getExceptionState().hadException()); |
| 64 |
| 65 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 66 request->abort(getScriptState()).then(MockFunction::expectCall(getScriptStat
e()), MockFunction::expectNoCall(getScriptState())); |
| 67 |
| 68 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(true); |
| 69 } |
| 70 |
| 71 } // namespace |
| 72 } // namespace blink |
OLD | NEW |