Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEventTest.cpp

Issue 2640293002: PaymentRequest: Move m_abortTimer to frame-specific TaskRunnerTimer. (Closed)
Patch Set: MiscPlatformAPI Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.idl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
30 30
31 MOCK_METHOD1(onUpdatePaymentDetails, 31 MOCK_METHOD1(onUpdatePaymentDetails,
32 void(const ScriptValue& detailsScriptValue)); 32 void(const ScriptValue& detailsScriptValue));
33 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const String& error)); 33 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const String& error));
34 34
35 DEFINE_INLINE_TRACE() {} 35 DEFINE_INLINE_TRACE() {}
36 }; 36 };
37 37
38 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) { 38 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) {
39 V8TestingScope scope; 39 V8TestingScope scope;
40 PaymentRequestUpdateEvent* event = 40 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(
41 PaymentRequestUpdateEvent::create(EventTypeNames::shippingaddresschange); 41 scope.getExecutionContext(), EventTypeNames::shippingaddresschange);
42 MockPaymentUpdater* updater = new MockPaymentUpdater; 42 MockPaymentUpdater* updater = new MockPaymentUpdater;
43 event->setPaymentDetailsUpdater(updater); 43 event->setPaymentDetailsUpdater(updater);
44 event->setEventPhase(Event::kCapturingPhase); 44 event->setEventPhase(Event::kCapturingPhase);
45 ScriptPromiseResolver* paymentDetails = 45 ScriptPromiseResolver* paymentDetails =
46 ScriptPromiseResolver::create(scope.getScriptState()); 46 ScriptPromiseResolver::create(scope.getScriptState());
47 event->updateWith(scope.getScriptState(), paymentDetails->promise(), 47 event->updateWith(scope.getScriptState(), paymentDetails->promise(),
48 scope.getExceptionState()); 48 scope.getExceptionState());
49 EXPECT_FALSE(scope.getExceptionState().hadException()); 49 EXPECT_FALSE(scope.getExceptionState().hadException());
50 50
51 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)); 51 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_));
52 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0); 52 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0);
53 53
54 paymentDetails->resolve("foo"); 54 paymentDetails->resolve("foo");
55 } 55 }
56 56
57 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled) { 57 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled) {
58 V8TestingScope scope; 58 V8TestingScope scope;
59 PaymentRequestUpdateEvent* event = 59 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(
60 PaymentRequestUpdateEvent::create(EventTypeNames::shippingaddresschange); 60 scope.getExecutionContext(), EventTypeNames::shippingaddresschange);
61 MockPaymentUpdater* updater = new MockPaymentUpdater; 61 MockPaymentUpdater* updater = new MockPaymentUpdater;
62 event->setPaymentDetailsUpdater(updater); 62 event->setPaymentDetailsUpdater(updater);
63 event->setEventPhase(Event::kCapturingPhase); 63 event->setEventPhase(Event::kCapturingPhase);
64 ScriptPromiseResolver* paymentDetails = 64 ScriptPromiseResolver* paymentDetails =
65 ScriptPromiseResolver::create(scope.getScriptState()); 65 ScriptPromiseResolver::create(scope.getScriptState());
66 event->updateWith(scope.getScriptState(), paymentDetails->promise(), 66 event->updateWith(scope.getScriptState(), paymentDetails->promise(),
67 scope.getExceptionState()); 67 scope.getExceptionState());
68 EXPECT_FALSE(scope.getExceptionState().hadException()); 68 EXPECT_FALSE(scope.getExceptionState().hadException());
69 69
70 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); 70 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0);
71 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); 71 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_));
72 72
73 paymentDetails->reject("oops"); 73 paymentDetails->reject("oops");
74 } 74 }
75 75
76 TEST(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching) { 76 TEST(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching) {
77 V8TestingScope scope; 77 V8TestingScope scope;
78 PaymentRequestUpdateEvent* event = 78 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(
79 PaymentRequestUpdateEvent::create(EventTypeNames::shippingaddresschange); 79 scope.getExecutionContext(), EventTypeNames::shippingaddresschange);
80 event->setPaymentDetailsUpdater(new MockPaymentUpdater); 80 event->setPaymentDetailsUpdater(new MockPaymentUpdater);
81 81
82 event->updateWith( 82 event->updateWith(
83 scope.getScriptState(), 83 scope.getScriptState(),
84 ScriptPromiseResolver::create(scope.getScriptState())->promise(), 84 ScriptPromiseResolver::create(scope.getScriptState())->promise(),
85 scope.getExceptionState()); 85 scope.getExceptionState());
86 86
87 EXPECT_TRUE(scope.getExceptionState().hadException()); 87 EXPECT_TRUE(scope.getExceptionState().hadException());
88 } 88 }
89 89
90 TEST(PaymentRequestUpdateEventTest, CannotUpdateTwice) { 90 TEST(PaymentRequestUpdateEventTest, CannotUpdateTwice) {
91 V8TestingScope scope; 91 V8TestingScope scope;
92 PaymentRequestUpdateEvent* event = 92 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(
93 PaymentRequestUpdateEvent::create(EventTypeNames::shippingaddresschange); 93 scope.getExecutionContext(), EventTypeNames::shippingaddresschange);
94 MockPaymentUpdater* updater = new MockPaymentUpdater; 94 MockPaymentUpdater* updater = new MockPaymentUpdater;
95 event->setPaymentDetailsUpdater(updater); 95 event->setPaymentDetailsUpdater(updater);
96 event->setEventPhase(Event::kCapturingPhase); 96 event->setEventPhase(Event::kCapturingPhase);
97 event->updateWith( 97 event->updateWith(
98 scope.getScriptState(), 98 scope.getScriptState(),
99 ScriptPromiseResolver::create(scope.getScriptState())->promise(), 99 ScriptPromiseResolver::create(scope.getScriptState())->promise(),
100 scope.getExceptionState()); 100 scope.getExceptionState());
101 EXPECT_FALSE(scope.getExceptionState().hadException()); 101 EXPECT_FALSE(scope.getExceptionState().hadException());
102 102
103 event->updateWith( 103 event->updateWith(
104 scope.getScriptState(), 104 scope.getScriptState(),
105 ScriptPromiseResolver::create(scope.getScriptState())->promise(), 105 ScriptPromiseResolver::create(scope.getScriptState())->promise(),
106 scope.getExceptionState()); 106 scope.getExceptionState());
107 107
108 EXPECT_TRUE(scope.getExceptionState().hadException()); 108 EXPECT_TRUE(scope.getExceptionState().hadException());
109 } 109 }
110 110
111 TEST(PaymentRequestUpdateEventTest, UpdaterNotRequired) { 111 TEST(PaymentRequestUpdateEventTest, UpdaterNotRequired) {
112 V8TestingScope scope; 112 V8TestingScope scope;
113 PaymentRequestUpdateEvent* event = 113 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(
114 PaymentRequestUpdateEvent::create(EventTypeNames::shippingaddresschange); 114 scope.getExecutionContext(), EventTypeNames::shippingaddresschange);
115 115
116 event->updateWith( 116 event->updateWith(
117 scope.getScriptState(), 117 scope.getScriptState(),
118 ScriptPromiseResolver::create(scope.getScriptState())->promise(), 118 ScriptPromiseResolver::create(scope.getScriptState())->promise(),
119 scope.getExceptionState()); 119 scope.getExceptionState());
120 120
121 EXPECT_FALSE(scope.getExceptionState().hadException()); 121 EXPECT_FALSE(scope.getExceptionState().hadException());
122 } 122 }
123 123
124 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout) { 124 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout) {
125 V8TestingScope scope; 125 V8TestingScope scope;
126 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 126 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
127 makePaymentRequestOriginSecure(scope.document()); 127 makePaymentRequestOriginSecure(scope.document());
128 PaymentRequest* request = PaymentRequest::create( 128 PaymentRequest* request = PaymentRequest::create(
129 scope.document(), buildPaymentMethodDataForTest(), 129 scope.document(), buildPaymentMethodDataForTest(),
130 buildPaymentDetailsForTest(), scope.getExceptionState()); 130 buildPaymentDetailsForTest(), scope.getExceptionState());
131 PaymentRequestUpdateEvent* event = 131 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(
132 PaymentRequestUpdateEvent::create(EventTypeNames::shippingaddresschange); 132 scope.getExecutionContext(), EventTypeNames::shippingaddresschange);
133 event->setPaymentDetailsUpdater(request); 133 event->setPaymentDetailsUpdater(request);
134 EXPECT_FALSE(scope.getExceptionState().hadException()); 134 EXPECT_FALSE(scope.getExceptionState().hadException());
135 135
136 String errorMessage; 136 String errorMessage;
137 request->show(scope.getScriptState()) 137 request->show(scope.getScriptState())
138 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); 138 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage));
139 139
140 event->onUpdateEventTimeoutForTesting(); 140 event->onUpdateEventTimeoutForTesting();
141 141
142 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); 142 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
143 EXPECT_EQ( 143 EXPECT_EQ(
144 "AbortError: Timed out as the page didn't resolve the promise from " 144 "AbortError: Timed out as the page didn't resolve the promise from "
145 "change event", 145 "change event",
146 errorMessage); 146 errorMessage);
147 } 147 }
148 148
149 } // namespace 149 } // namespace
150 } // namespace blink 150 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698