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

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

Issue 2823393002: Web payment shipping address/option timeout. (Closed)
Patch Set: Created 3 years, 8 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.cpp ('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 <memory> 7 #include <memory>
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 scope.GetExecutionContext(), 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, AddressChangeUpdateWithTimeout) {
125 V8TestingScope scope; 125 V8TestingScope scope;
126 PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); 126 PaymentRequestMockFunctionScope funcs(scope.GetScriptState());
127 MakePaymentRequestOriginSecure(scope.GetDocument()); 127 MakePaymentRequestOriginSecure(scope.GetDocument());
128 PaymentRequest* request = PaymentRequest::Create( 128 PaymentRequest* request = PaymentRequest::Create(
129 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), 129 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(),
130 BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); 130 BuildPaymentDetailsInitForTest(), scope.GetExceptionState());
131 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::Create( 131 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::Create(
132 scope.GetExecutionContext(), 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 error_message; 136 String error_message;
137 request->show(scope.GetScriptState()) 137 request->show(scope.GetScriptState())
138 .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); 138 .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message));
139 139
140 event->OnUpdateEventTimeoutForTesting(); 140 event->OnUpdateEventTimeoutForTesting();
141 141
142 v8::MicrotasksScope::PerformCheckpoint(scope.GetScriptState()->GetIsolate()); 142 v8::MicrotasksScope::PerformCheckpoint(scope.GetScriptState()->GetIsolate());
143 EXPECT_EQ( 143 EXPECT_EQ(
144 "AbortError: Timed out as the page didn't resolve the promise from " 144 "AbortError: Timed out waiting for a response to a "
145 "change event", 145 "'shippingaddresschange' event",
146 error_message); 146 error_message);
147
148 event->updateWith(
149 scope.GetScriptState(),
150 ScriptPromiseResolver::Create(scope.GetScriptState())->Promise(),
151 scope.GetExceptionState());
152
153 EXPECT_FALSE(scope.GetExceptionState().HadException());
154 }
155
156 TEST(PaymentRequestUpdateEventTest, OptionChangeUpdateWithTimeout) {
157 V8TestingScope scope;
158 PaymentRequestMockFunctionScope funcs(scope.GetScriptState());
159 MakePaymentRequestOriginSecure(scope.GetDocument());
160 PaymentRequest* request = PaymentRequest::Create(
161 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(),
162 BuildPaymentDetailsInitForTest(), scope.GetExceptionState());
163 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::Create(
164 scope.GetExecutionContext(), EventTypeNames::shippingoptionchange);
165 event->SetPaymentDetailsUpdater(request);
166 EXPECT_FALSE(scope.GetExceptionState().HadException());
167
168 String error_message;
169 request->show(scope.GetScriptState())
170 .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message));
171
172 event->OnUpdateEventTimeoutForTesting();
173
174 v8::MicrotasksScope::PerformCheckpoint(scope.GetScriptState()->GetIsolate());
175 EXPECT_EQ(
176 "AbortError: Timed out waiting for a response to a "
177 "'shippingoptionchange' event",
178 error_message);
179
180 event->updateWith(
181 scope.GetScriptState(),
182 ScriptPromiseResolver::Create(scope.GetScriptState())->Promise(),
183 scope.GetExceptionState());
184
185 EXPECT_FALSE(scope.GetExceptionState().HadException());
186 }
187
188 TEST(PaymentRequestUpdateEventTest, AddressChangePromiseTimeout) {
189 V8TestingScope scope;
190 PaymentRequestMockFunctionScope funcs(scope.GetScriptState());
191 MakePaymentRequestOriginSecure(scope.GetDocument());
192 PaymentRequest* request = PaymentRequest::Create(
193 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(),
194 BuildPaymentDetailsInitForTest(), scope.GetExceptionState());
195 EXPECT_FALSE(scope.GetExceptionState().HadException());
196 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::Create(
197 scope.GetExecutionContext(), EventTypeNames::shippingaddresschange);
198 event->SetPaymentDetailsUpdater(request);
199 event->SetEventPhase(Event::kCapturingPhase);
200 ScriptPromiseResolver* payment_details =
201 ScriptPromiseResolver::Create(scope.GetScriptState());
202 String error_message;
203 request->show(scope.GetScriptState())
204 .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message));
205 event->updateWith(scope.GetScriptState(), payment_details->Promise(),
206 scope.GetExceptionState());
207 EXPECT_FALSE(scope.GetExceptionState().HadException());
208
209 event->OnUpdateEventTimeoutForTesting();
210
211 v8::MicrotasksScope::PerformCheckpoint(scope.GetScriptState()->GetIsolate());
212 EXPECT_EQ(
213 "AbortError: Timed out waiting for a response to a "
214 "'shippingaddresschange' event",
215 error_message);
216
217 payment_details->Resolve("foo");
218 }
219
220 TEST(PaymentRequestUpdateEventTest, OptionChangePromiseTimeout) {
221 V8TestingScope scope;
222 PaymentRequestMockFunctionScope funcs(scope.GetScriptState());
223 MakePaymentRequestOriginSecure(scope.GetDocument());
224 PaymentRequest* request = PaymentRequest::Create(
225 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(),
226 BuildPaymentDetailsInitForTest(), scope.GetExceptionState());
227 EXPECT_FALSE(scope.GetExceptionState().HadException());
228 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::Create(
229 scope.GetExecutionContext(), EventTypeNames::shippingoptionchange);
230 event->SetPaymentDetailsUpdater(request);
231 event->SetEventPhase(Event::kCapturingPhase);
232 ScriptPromiseResolver* payment_details =
233 ScriptPromiseResolver::Create(scope.GetScriptState());
234 String error_message;
235 request->show(scope.GetScriptState())
236 .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message));
237 event->updateWith(scope.GetScriptState(), payment_details->Promise(),
238 scope.GetExceptionState());
239 EXPECT_FALSE(scope.GetExceptionState().HadException());
240
241 event->OnUpdateEventTimeoutForTesting();
242
243 v8::MicrotasksScope::PerformCheckpoint(scope.GetScriptState()->GetIsolate());
244 EXPECT_EQ(
245 "AbortError: Timed out waiting for a response to a "
246 "'shippingoptionchange' event",
247 error_message);
248
249 payment_details->Resolve("foo");
147 } 250 }
148 251
149 } // namespace 252 } // namespace
150 } // namespace blink 253 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698