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 #include "modules/payments/PaymentRequestUpdateEvent.h" | 5 #include "modules/payments/PaymentRequestUpdateEvent.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/V8BindingForTesting.h" | 10 #include "bindings/core/v8/V8BindingForTesting.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa
lue)); | 30 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa
lue)); |
31 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const String& error)); | 31 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const String& error)); |
32 | 32 |
33 DEFINE_INLINE_TRACE() {} | 33 DEFINE_INLINE_TRACE() {} |
34 }; | 34 }; |
35 | 35 |
36 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) | 36 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) |
37 { | 37 { |
38 V8TestingScope scope; | 38 V8TestingScope scope; |
39 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); | 39 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
40 MockPaymentUpdater* updater = new MockPaymentUpdater; | 40 MockPaymentUpdater* updater = new MockPaymentUpdater; |
41 event->setPaymentDetailsUpdater(updater); | 41 event->setPaymentDetailsUpdater(updater); |
42 event->setEventPhase(Event::kCapturingPhase); | 42 event->setEventPhase(Event::kCapturingPhase); |
43 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope.
getScriptState()); | 43 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope.
getScriptState()); |
44 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g
etExceptionState()); | 44 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g
etExceptionState()); |
45 EXPECT_FALSE(scope.getExceptionState().hadException()); | 45 EXPECT_FALSE(scope.getExceptionState().hadException()); |
46 | 46 |
47 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)); | 47 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)); |
48 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0); | 48 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0); |
49 | 49 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 102 |
103 EXPECT_FALSE(scope.getExceptionState().hadException()); | 103 EXPECT_FALSE(scope.getExceptionState().hadException()); |
104 } | 104 } |
105 | 105 |
106 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout) | 106 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout) |
107 { | 107 { |
108 V8TestingScope scope; | 108 V8TestingScope scope; |
109 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 109 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
110 makePaymentRequestOriginSecure(scope.document()); | 110 makePaymentRequestOriginSecure(scope.document()); |
111 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 111 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
112 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); | 112 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
113 event->setPaymentDetailsUpdater(request); | 113 event->setPaymentDetailsUpdater(request); |
114 EXPECT_FALSE(scope.getExceptionState().hadException()); | 114 EXPECT_FALSE(scope.getExceptionState().hadException()); |
115 | 115 |
116 String errorMessage; | 116 String errorMessage; |
117 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall(&errorMessage)); | 117 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall(&errorMessage)); |
118 | 118 |
119 event->onTimerFired(0); | 119 event->onTimerFired(0); |
120 | 120 |
121 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 121 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
122 EXPECT_EQ("AbortError: Timed out as the page didn't resolve the promise from
change event", errorMessage); | 122 EXPECT_EQ("AbortError: Timed out as the page didn't resolve the promise from
change event", errorMessage); |
123 } | 123 } |
124 | 124 |
125 } // namespace | 125 } // namespace |
126 } // namespace blink | 126 } // namespace blink |
OLD | NEW |