| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Tests for PaymentRequest::abort(). | 5 // Tests for PaymentRequest::abort(). |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8BindingForTesting.h" | 7 #include "bindings/core/v8/V8BindingForTesting.h" |
| 8 #include "modules/payments/PaymentRequest.h" | 8 #include "modules/payments/PaymentRequest.h" |
| 9 #include "modules/payments/PaymentTestHelper.h" | 9 #include "modules/payments/PaymentTestHelper.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // If request.abort() is called without calling request.show() first, then | 15 // If request.abort() is called without calling request.show() first, then |
| 16 // abort() should reject with exception. | 16 // abort() should reject with exception. |
| 17 TEST(AbortTest, CannotAbortBeforeShow) { | 17 TEST(AbortTest, CannotAbortBeforeShow) { |
| 18 V8TestingScope scope; | 18 V8TestingScope scope; |
| 19 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 19 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 20 makePaymentRequestOriginSecure(scope.document()); | 20 makePaymentRequestOriginSecure(scope.document()); |
| 21 PaymentRequest* request = PaymentRequest::create( | 21 PaymentRequest* request = PaymentRequest::create( |
| 22 scope.document(), buildPaymentMethodDataForTest(), | 22 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 23 buildPaymentDetailsForTest(), scope.getExceptionState()); | 23 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 24 | 24 |
| 25 request->abort(scope.getScriptState()) | 25 request->abort().then(funcs.expectNoCall(), funcs.expectCall()); |
| 26 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 27 } | 26 } |
| 28 | 27 |
| 29 // If request.abort() is called again before the previous abort() resolved, then | 28 // If request.abort() is called again before the previous abort() resolved, then |
| 30 // the second abort() should reject with exception. | 29 // the second abort() should reject with exception. |
| 31 TEST(AbortTest, CannotAbortTwiceConcurrently) { | 30 TEST(AbortTest, CannotAbortTwiceConcurrently) { |
| 32 V8TestingScope scope; | 31 V8TestingScope scope; |
| 33 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 32 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 34 makePaymentRequestOriginSecure(scope.document()); | 33 makePaymentRequestOriginSecure(scope.document()); |
| 35 PaymentRequest* request = PaymentRequest::create( | 34 PaymentRequest* request = PaymentRequest::create( |
| 36 scope.document(), buildPaymentMethodDataForTest(), | 35 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 37 buildPaymentDetailsForTest(), scope.getExceptionState()); | 36 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 38 request->show(scope.getScriptState()); | 37 request->show(); |
| 39 request->abort(scope.getScriptState()); | 38 request->abort(); |
| 40 | 39 |
| 41 request->abort(scope.getScriptState()) | 40 request->abort().then(funcs.expectNoCall(), funcs.expectCall()); |
| 42 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 43 } | 41 } |
| 44 | 42 |
| 45 // If request.abort() is called after calling request.show(), then abort() | 43 // If request.abort() is called after calling request.show(), then abort() |
| 46 // should not reject with exception. | 44 // should not reject with exception. |
| 47 TEST(AbortTest, CanAbortAfterShow) { | 45 TEST(AbortTest, CanAbortAfterShow) { |
| 48 V8TestingScope scope; | 46 V8TestingScope scope; |
| 49 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 47 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 50 makePaymentRequestOriginSecure(scope.document()); | 48 makePaymentRequestOriginSecure(scope.document()); |
| 51 PaymentRequest* request = PaymentRequest::create( | 49 PaymentRequest* request = PaymentRequest::create( |
| 52 scope.document(), buildPaymentMethodDataForTest(), | 50 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 53 buildPaymentDetailsForTest(), scope.getExceptionState()); | 51 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 54 request->show(scope.getScriptState()); | 52 request->show(); |
| 55 | 53 |
| 56 request->abort(scope.getScriptState()) | 54 request->abort().then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 57 .then(funcs.expectNoCall(), funcs.expectNoCall()); | |
| 58 } | 55 } |
| 59 | 56 |
| 60 // If the browser is unable to abort the payment, then the request.abort() | 57 // If the browser is unable to abort the payment, then the request.abort() |
| 61 // promise should be rejected. | 58 // promise should be rejected. |
| 62 TEST(AbortTest, FailedAbortShouldRejectAbortPromise) { | 59 TEST(AbortTest, FailedAbortShouldRejectAbortPromise) { |
| 63 V8TestingScope scope; | 60 V8TestingScope scope; |
| 64 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 61 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 65 makePaymentRequestOriginSecure(scope.document()); | 62 makePaymentRequestOriginSecure(scope.document()); |
| 66 PaymentRequest* request = PaymentRequest::create( | 63 PaymentRequest* request = PaymentRequest::create( |
| 67 scope.document(), buildPaymentMethodDataForTest(), | 64 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 68 buildPaymentDetailsForTest(), scope.getExceptionState()); | 65 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 69 request->show(scope.getScriptState()); | 66 request->show(); |
| 70 | 67 |
| 71 request->abort(scope.getScriptState()) | 68 request->abort().then(funcs.expectNoCall(), funcs.expectCall()); |
| 72 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 73 | 69 |
| 74 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( | 70 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( |
| 75 false); | 71 false); |
| 76 } | 72 } |
| 77 | 73 |
| 78 // After the browser is unable to abort the payment once, the second abort() | 74 // After the browser is unable to abort the payment once, the second abort() |
| 79 // call should not be rejected, as it's not a duplicate request anymore. | 75 // call should not be rejected, as it's not a duplicate request anymore. |
| 80 TEST(AbortTest, CanAbortAgainAfterFirstAbortRejected) { | 76 TEST(AbortTest, CanAbortAgainAfterFirstAbortRejected) { |
| 81 V8TestingScope scope; | 77 V8TestingScope scope; |
| 82 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 78 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 83 makePaymentRequestOriginSecure(scope.document()); | 79 makePaymentRequestOriginSecure(scope.document()); |
| 84 PaymentRequest* request = PaymentRequest::create( | 80 PaymentRequest* request = PaymentRequest::create( |
| 85 scope.document(), buildPaymentMethodDataForTest(), | 81 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 86 buildPaymentDetailsForTest(), scope.getExceptionState()); | 82 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 87 request->show(scope.getScriptState()); | 83 request->show(); |
| 88 request->abort(scope.getScriptState()); | 84 request->abort(); |
| 89 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( | 85 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( |
| 90 false); | 86 false); |
| 91 | 87 |
| 92 request->abort(scope.getScriptState()) | 88 request->abort().then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 93 .then(funcs.expectNoCall(), funcs.expectNoCall()); | |
| 94 } | 89 } |
| 95 | 90 |
| 96 // If the browser successfully aborts the payment, then the request.show() | 91 // If the browser successfully aborts the payment, then the request.show() |
| 97 // promise should be rejected, and request.abort() promise should be resolved. | 92 // promise should be rejected, and request.abort() promise should be resolved. |
| 98 TEST(AbortTest, SuccessfulAbortShouldRejectShowPromiseAndResolveAbortPromise) { | 93 TEST(AbortTest, SuccessfulAbortShouldRejectShowPromiseAndResolveAbortPromise) { |
| 99 V8TestingScope scope; | 94 V8TestingScope scope; |
| 100 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 95 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 101 makePaymentRequestOriginSecure(scope.document()); | 96 makePaymentRequestOriginSecure(scope.document()); |
| 102 PaymentRequest* request = PaymentRequest::create( | 97 PaymentRequest* request = PaymentRequest::create( |
| 103 scope.document(), buildPaymentMethodDataForTest(), | 98 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 104 buildPaymentDetailsForTest(), scope.getExceptionState()); | 99 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 105 | 100 |
| 106 request->show(scope.getScriptState()) | 101 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 107 .then(funcs.expectNoCall(), funcs.expectCall()); | 102 request->abort().then(funcs.expectCall(), funcs.expectNoCall()); |
| 108 request->abort(scope.getScriptState()) | |
| 109 .then(funcs.expectCall(), funcs.expectNoCall()); | |
| 110 | 103 |
| 111 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( | 104 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( |
| 112 true); | 105 true); |
| 113 } | 106 } |
| 114 | 107 |
| 115 } // namespace | 108 } // namespace |
| 116 } // namespace blink | 109 } // namespace blink |
| OLD | NEW |