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" |
11 #include "core/EventTypeNames.h" | 11 #include "core/EventTypeNames.h" |
12 #include "modules/payments/PaymentUpdater.h" | 12 #include "modules/payments/PaymentUpdater.h" |
13 #include "platform/testing/UnitTestHelpers.h" | |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include <memory> | 16 #include <memory> |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 namespace { | 19 namespace { |
19 | 20 |
20 class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater { | 21 class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater { |
21 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater); | 22 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater); |
22 WTF_MAKE_NONCOPYABLE(MockPaymentUpdater); | 23 WTF_MAKE_NONCOPYABLE(MockPaymentUpdater); |
23 | 24 |
24 public: | 25 public: |
25 MockPaymentUpdater() {} | 26 MockPaymentUpdater() {} |
26 ~MockPaymentUpdater() override {} | 27 ~MockPaymentUpdater() override {} |
27 | 28 |
28 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue)); | 29 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue)); |
29 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error)); | 30 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error)); |
30 | 31 |
31 DEFINE_INLINE_TRACE() {} | 32 DEFINE_INLINE_TRACE() {} |
32 }; | 33 }; |
33 | 34 |
35 ACTION(exitLoop) | |
36 { | |
37 testing::exitRunLoop(); | |
38 } | |
39 | |
40 class MockPaymentUpdaterForTimeout : public GarbageCollectedFinalized<MockPaymen tUpdater>, public PaymentUpdater { | |
41 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdaterForTimeout); | |
42 WTF_MAKE_NONCOPYABLE(MockPaymentUpdaterForTimeout); | |
43 | |
44 public: | |
45 MockPaymentUpdaterForTimeout() | |
46 { | |
47 ON_CALL(*this, onUpdatePaymentDetailsFailure(::testing::_)).WillByDefaul t( | |
48 ::testing::DoAll(exitLoop(), ::testing::Return())); | |
49 } | |
50 ~MockPaymentUpdaterForTimeout() override {} | |
51 | |
52 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue)); | |
53 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error)); | |
54 | |
55 DEFINE_INLINE_TRACE() {} | |
56 }; | |
57 | |
58 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout) | |
59 { | |
60 V8TestingScope scope; | |
61 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); | |
62 String errorMessage; | |
63 MockPaymentUpdaterForTimeout* updater = new MockPaymentUpdaterForTimeout; | |
64 event->setPaymentDetailsUpdater(updater); | |
65 event->setEventPhase(Event::CAPTURING_PHASE); | |
66 | |
67 EXPECT_CALL(*updater, onUpdatePaymentDetails(::testing::_)).Times(0); | |
68 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(::testing::_)); | |
69 | |
70 testing::enterRunLoop(); | |
please use gerrit instead
2016/07/21 16:35:24
This test will run 5 seconds. If I want to change
pals
2016/07/22 04:06:19
Done.
| |
71 } | |
72 | |
34 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) | 73 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) |
35 { | 74 { |
36 V8TestingScope scope; | 75 V8TestingScope scope; |
37 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); | 76 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); |
38 MockPaymentUpdater* updater = new MockPaymentUpdater; | 77 MockPaymentUpdater* updater = new MockPaymentUpdater; |
39 event->setPaymentDetailsUpdater(updater); | 78 event->setPaymentDetailsUpdater(updater); |
40 event->setEventPhase(Event::CAPTURING_PHASE); | 79 event->setEventPhase(Event::CAPTURING_PHASE); |
41 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope. getScriptState()); | 80 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope. getScriptState()); |
42 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g etExceptionState()); | 81 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g etExceptionState()); |
43 EXPECT_FALSE(scope.getExceptionState().hadException()); | 82 EXPECT_FALSE(scope.getExceptionState().hadException()); |
44 | 83 |
45 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)); | 84 EXPECT_CALL(*updater, onUpdatePaymentDetails(::testing::_)); |
46 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0); | 85 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(::testing::_)).Times(0); |
47 | 86 |
48 paymentDetails->resolve("foo"); | 87 paymentDetails->resolve("foo"); |
49 } | 88 } |
50 | 89 |
51 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled) | 90 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled) |
52 { | 91 { |
53 V8TestingScope scope; | 92 V8TestingScope scope; |
54 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); | 93 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); |
55 MockPaymentUpdater* updater = new MockPaymentUpdater; | 94 MockPaymentUpdater* updater = new MockPaymentUpdater; |
56 event->setPaymentDetailsUpdater(updater); | 95 event->setPaymentDetailsUpdater(updater); |
57 event->setEventPhase(Event::CAPTURING_PHASE); | 96 event->setEventPhase(Event::CAPTURING_PHASE); |
58 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope. getScriptState()); | 97 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(scope. getScriptState()); |
59 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g etExceptionState()); | 98 event->updateWith(scope.getScriptState(), paymentDetails->promise(), scope.g etExceptionState()); |
60 EXPECT_FALSE(scope.getExceptionState().hadException()); | 99 EXPECT_FALSE(scope.getExceptionState().hadException()); |
61 | 100 |
62 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); | 101 EXPECT_CALL(*updater, onUpdatePaymentDetails(::testing::_)).Times(0); |
63 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); | 102 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(::testing::_)); |
64 | 103 |
65 paymentDetails->reject("oops"); | 104 paymentDetails->reject("oops"); |
66 } | 105 } |
67 | 106 |
68 TEST(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching) | 107 TEST(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching) |
69 { | 108 { |
70 V8TestingScope scope; | 109 V8TestingScope scope; |
71 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); | 110 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); |
72 event->setPaymentDetailsUpdater(new MockPaymentUpdater); | 111 event->setPaymentDetailsUpdater(new MockPaymentUpdater); |
73 | 112 |
(...skipping 22 matching lines...) Expand all Loading... | |
96 V8TestingScope scope; | 135 V8TestingScope scope; |
97 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); | 136 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); |
98 | 137 |
99 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop e.getScriptState())->promise(), scope.getExceptionState()); | 138 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop e.getScriptState())->promise(), scope.getExceptionState()); |
100 | 139 |
101 EXPECT_FALSE(scope.getExceptionState().hadException()); | 140 EXPECT_FALSE(scope.getExceptionState().hadException()); |
102 } | 141 } |
103 | 142 |
104 } // namespace | 143 } // namespace |
105 } // namespace blink | 144 } // namespace blink |
OLD | NEW |