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/PaymentRequest.h" | |
13 #include "modules/payments/PaymentTestHelper.h" | |
12 #include "modules/payments/PaymentUpdater.h" | 14 #include "modules/payments/PaymentUpdater.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 #include <memory> | 17 #include <memory> |
16 | 18 |
17 namespace blink { | 19 namespace blink { |
18 namespace { | 20 namespace { |
19 | 21 |
20 class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater { | 22 class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater { |
21 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater); | 23 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater); |
22 WTF_MAKE_NONCOPYABLE(MockPaymentUpdater); | 24 WTF_MAKE_NONCOPYABLE(MockPaymentUpdater); |
23 | 25 |
24 public: | 26 public: |
25 MockPaymentUpdater() {} | 27 MockPaymentUpdater() {} |
26 ~MockPaymentUpdater() override {} | 28 ~MockPaymentUpdater() override {} |
27 | 29 |
28 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue)); | 30 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue)); |
29 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error)); | 31 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error)); |
please use gerrit instead
2016/07/29 15:40:50
Change ScriptValue to String
pals
2016/08/01 11:18:23
Done.
| |
32 MOCK_METHOD1(abortPaymentRequest, void(const String& message)); | |
please use gerrit instead
2016/07/29 15:40:50
No need for the extra method.
pals
2016/08/01 11:18:23
Done.
| |
30 | 33 |
31 DEFINE_INLINE_TRACE() {} | 34 DEFINE_INLINE_TRACE() {} |
32 }; | 35 }; |
33 | 36 |
34 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) | 37 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) |
35 { | 38 { |
36 V8TestingScope scope; | 39 V8TestingScope scope; |
37 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); | 40 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); |
38 MockPaymentUpdater* updater = new MockPaymentUpdater; | 41 MockPaymentUpdater* updater = new MockPaymentUpdater; |
39 event->setPaymentDetailsUpdater(updater); | 42 event->setPaymentDetailsUpdater(updater); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); | 100 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); |
98 | 101 |
99 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop e.getScriptState())->promise(), scope.getExceptionState()); | 102 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop e.getScriptState())->promise(), scope.getExceptionState()); |
100 | 103 |
101 EXPECT_FALSE(scope.getExceptionState().hadException()); | 104 EXPECT_FALSE(scope.getExceptionState().hadException()); |
102 } | 105 } |
103 | 106 |
104 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout) | 107 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout) |
105 { | 108 { |
106 V8TestingScope scope; | 109 V8TestingScope scope; |
110 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
111 makePaymentRequestOriginSecure(scope.document()); | |
112 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); | |
107 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); | 113 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); |
108 MockPaymentUpdater* updater = new MockPaymentUpdater; | 114 event->setPaymentDetailsUpdater(request); |
109 event->setPaymentDetailsUpdater(updater); | 115 EXPECT_FALSE(scope.getExceptionState().hadException()); |
110 | 116 |
111 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); | 117 String errorMessage; |
112 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); | 118 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall(&errorMessage)); |
113 | 119 |
114 event->onTimerFired(0); | 120 event->onTimerFired(0); |
121 | |
122 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | |
123 EXPECT_EQ("AbortError: Timed out as the page didn't resolve the promise from change event", errorMessage); | |
please use gerrit instead
2016/07/29 15:40:50
Great test!
pals
2016/08/01 11:18:23
Thanks.
| |
115 } | 124 } |
116 | 125 |
117 } // namespace | 126 } // namespace |
118 } // namespace blink | 127 } // namespace blink |
OLD | NEW |