| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 DEFINE_INLINE_TRACE() {} | 31 DEFINE_INLINE_TRACE() {} |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) | 34 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) |
| 35 { | 35 { |
| 36 V8TestingScope scope; | 36 V8TestingScope scope; |
| 37 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); | 37 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); |
| 38 MockPaymentUpdater* updater = new MockPaymentUpdater; | 38 MockPaymentUpdater* updater = new MockPaymentUpdater; |
| 39 event->setPaymentDetailsUpdater(updater); | 39 event->setPaymentDetailsUpdater(updater); |
| 40 event->setEventPhase(Event::CAPTURING_PHASE); | 40 event->setEventPhase(Event::kCapturingPhase); |
| 41 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope.
getScriptState()); | 41 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope.
getScriptState()); |
| 42 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g
etExceptionState()); | 42 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g
etExceptionState()); |
| 43 EXPECT_FALSE(scope.getExceptionState().hadException()); | 43 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 44 | 44 |
| 45 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)); | 45 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)); |
| 46 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0); | 46 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0); |
| 47 | 47 |
| 48 paymentDetails->resolve("foo"); | 48 paymentDetails->resolve("foo"); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled) | 51 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled) |
| 52 { | 52 { |
| 53 V8TestingScope scope; | 53 V8TestingScope scope; |
| 54 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); | 54 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
| 55 MockPaymentUpdater* updater = new MockPaymentUpdater; | 55 MockPaymentUpdater* updater = new MockPaymentUpdater; |
| 56 event->setPaymentDetailsUpdater(updater); | 56 event->setPaymentDetailsUpdater(updater); |
| 57 event->setEventPhase(Event::CAPTURING_PHASE); | 57 event->setEventPhase(Event::kCapturingPhase); |
| 58 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope.
getScriptState()); | 58 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope.
getScriptState()); |
| 59 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g
etExceptionState()); | 59 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g
etExceptionState()); |
| 60 EXPECT_FALSE(scope.getExceptionState().hadException()); | 60 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 61 | 61 |
| 62 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); | 62 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); |
| 63 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); | 63 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); |
| 64 | 64 |
| 65 paymentDetails->reject("oops"); | 65 paymentDetails->reject("oops"); |
| 66 } | 66 } |
| 67 | 67 |
| 68 TEST(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching) | 68 TEST(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching) |
| 69 { | 69 { |
| 70 V8TestingScope scope; | 70 V8TestingScope scope; |
| 71 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); | 71 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
| 72 event->setPaymentDetailsUpdater(new MockPaymentUpdater); | 72 event->setPaymentDetailsUpdater(new MockPaymentUpdater); |
| 73 | 73 |
| 74 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); | 74 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); |
| 75 | 75 |
| 76 EXPECT_TRUE(scope.getExceptionState().hadException()); | 76 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST(PaymentRequestUpdateEventTest, CannotUpdateTwice) | 79 TEST(PaymentRequestUpdateEventTest, CannotUpdateTwice) |
| 80 { | 80 { |
| 81 V8TestingScope scope; | 81 V8TestingScope scope; |
| 82 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); | 82 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
| 83 MockPaymentUpdater* updater = new MockPaymentUpdater; | 83 MockPaymentUpdater* updater = new MockPaymentUpdater; |
| 84 event->setPaymentDetailsUpdater(updater); | 84 event->setPaymentDetailsUpdater(updater); |
| 85 event->setEventPhase(Event::CAPTURING_PHASE); | 85 event->setEventPhase(Event::kCapturingPhase); |
| 86 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); | 86 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); |
| 87 EXPECT_FALSE(scope.getExceptionState().hadException()); | 87 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 88 | 88 |
| 89 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); | 89 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); |
| 90 | 90 |
| 91 EXPECT_TRUE(scope.getExceptionState().hadException()); | 91 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST(PaymentRequestUpdateEventTest, UpdaterNotRequired) | 94 TEST(PaymentRequestUpdateEventTest, UpdaterNotRequired) |
| 95 { | 95 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 109 event->setPaymentDetailsUpdater(updater); | 109 event->setPaymentDetailsUpdater(updater); |
| 110 | 110 |
| 111 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); | 111 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); |
| 112 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); | 112 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); |
| 113 | 113 |
| 114 event->onTimerFired(0); | 114 event->onTimerFired(0); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace | 117 } // namespace |
| 118 } // namespace blink | 118 } // namespace blink |
| OLD | NEW |