| 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 21 matching lines...) Expand all Loading... |
| 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(); |
| 40 MockPaymentUpdater* updater = new MockPaymentUpdater; | 40 MockPaymentUpdater* updater = new MockPaymentUpdater; |
| 41 event->setPaymentDetailsUpdater(updater); | 41 event->setPaymentDetailsUpdater(updater); |
| 42 event->setEventPhase(Event::CAPTURING_PHASE); | 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 |
| 50 paymentDetails->resolve("foo"); | 50 paymentDetails->resolve("foo"); |
| 51 } | 51 } |
| 52 | 52 |
| 53 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled) | 53 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled) |
| 54 { | 54 { |
| 55 V8TestingScope scope; | 55 V8TestingScope scope; |
| 56 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); | 56 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
| 57 MockPaymentUpdater* updater = new MockPaymentUpdater; | 57 MockPaymentUpdater* updater = new MockPaymentUpdater; |
| 58 event->setPaymentDetailsUpdater(updater); | 58 event->setPaymentDetailsUpdater(updater); |
| 59 event->setEventPhase(Event::CAPTURING_PHASE); | 59 event->setEventPhase(Event::kCapturingPhase); |
| 60 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope.
getScriptState()); | 60 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope.
getScriptState()); |
| 61 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g
etExceptionState()); | 61 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g
etExceptionState()); |
| 62 EXPECT_FALSE(scope.getExceptionState().hadException()); | 62 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 63 | 63 |
| 64 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); | 64 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); |
| 65 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); | 65 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); |
| 66 | 66 |
| 67 paymentDetails->reject("oops"); | 67 paymentDetails->reject("oops"); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching) | 70 TEST(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching) |
| 71 { | 71 { |
| 72 V8TestingScope scope; | 72 V8TestingScope scope; |
| 73 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); | 73 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
| 74 event->setPaymentDetailsUpdater(new MockPaymentUpdater); | 74 event->setPaymentDetailsUpdater(new MockPaymentUpdater); |
| 75 | 75 |
| 76 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); | 76 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); |
| 77 | 77 |
| 78 EXPECT_TRUE(scope.getExceptionState().hadException()); | 78 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 TEST(PaymentRequestUpdateEventTest, CannotUpdateTwice) | 81 TEST(PaymentRequestUpdateEventTest, CannotUpdateTwice) |
| 82 { | 82 { |
| 83 V8TestingScope scope; | 83 V8TestingScope scope; |
| 84 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); | 84 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
| 85 MockPaymentUpdater* updater = new MockPaymentUpdater; | 85 MockPaymentUpdater* updater = new MockPaymentUpdater; |
| 86 event->setPaymentDetailsUpdater(updater); | 86 event->setPaymentDetailsUpdater(updater); |
| 87 event->setEventPhase(Event::CAPTURING_PHASE); | 87 event->setEventPhase(Event::kCapturingPhase); |
| 88 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); | 88 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); |
| 89 EXPECT_FALSE(scope.getExceptionState().hadException()); | 89 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 90 | 90 |
| 91 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); | 91 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop
e.getScriptState())->promise(), scope.getExceptionState()); |
| 92 | 92 |
| 93 EXPECT_TRUE(scope.getExceptionState().hadException()); | 93 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 TEST(PaymentRequestUpdateEventTest, UpdaterNotRequired) | 96 TEST(PaymentRequestUpdateEventTest, UpdaterNotRequired) |
| 97 { | 97 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 |