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/PaymentRequest.h" | 5 #include "modules/payments/PaymentRequest.h" |
6 | 6 |
7 #include "bindings/core/v8/JSONValuesForV8.h" | 7 #include "bindings/core/v8/JSONValuesForV8.h" |
8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 makePaymentRequestOriginSecure(scope.document()); | 230 makePaymentRequestOriginSecure(scope.document()); |
231 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); | 231 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); |
232 EXPECT_FALSE(scope.getExceptionState().hadException()); | 232 EXPECT_FALSE(scope.getExceptionState().hadException()); |
233 request->show(scope.getScriptState()); | 233 request->show(scope.getScriptState()); |
234 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); | 234 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); |
235 request->complete(scope.getScriptState(), Fail); | 235 request->complete(scope.getScriptState(), Fail); |
236 | 236 |
237 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); | 237 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); |
238 } | 238 } |
239 | 239 |
240 TEST(PaymentRequestTest, RejectShowPromiseOnError) | 240 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) |
241 { | 241 { |
242 V8TestingScope scope; | 242 V8TestingScope scope; |
243 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 243 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
244 makePaymentRequestOriginSecure(scope.document()); | 244 makePaymentRequestOriginSecure(scope.document()); |
245 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); | 245 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); |
246 EXPECT_FALSE(scope.getExceptionState().hadException()); | 246 EXPECT_FALSE(scope.getExceptionState().hadException()); |
247 | 247 |
248 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); | 248 String onRejected; |
please use gerrit instead
2016/07/13 15:55:26
Let's use the variable name "errorMessage".
pals
2016/07/14 08:37:38
Done.
| |
249 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall(&onRejected)); | |
249 | 250 |
250 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 251 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::NOT_SUPPORTED); |
252 | |
253 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | |
254 EXPECT_EQ("NotSupportedError: The payment method is not supported", onReject ed); | |
255 } | |
256 | |
257 TEST(PaymentRequestTest, RejectShowPromiseOnErrorUserCancelled) | |
258 { | |
259 V8TestingScope scope; | |
260 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
261 makePaymentRequestOriginSecure(scope.document()); | |
262 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); | |
263 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
264 | |
265 String onRejected; | |
please use gerrit instead
2016/07/13 15:55:26
errorMessage
pals
2016/07/14 08:37:38
Done.
| |
266 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall(&onRejected)); | |
267 | |
268 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::USER_CANCEL); | |
269 | |
270 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | |
271 EXPECT_EQ("SyntaxError: User cancelled the payment request", onRejected); | |
251 } | 272 } |
252 | 273 |
253 TEST(PaymentRequestTest, RejectCompletePromiseOnError) | 274 TEST(PaymentRequestTest, RejectCompletePromiseOnError) |
254 { | 275 { |
255 V8TestingScope scope; | 276 V8TestingScope scope; |
256 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 277 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
257 makePaymentRequestOriginSecure(scope.document()); | 278 makePaymentRequestOriginSecure(scope.document()); |
258 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); | 279 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); |
259 EXPECT_FALSE(scope.getExceptionState().hadException()); | 280 EXPECT_FALSE(scope.getExceptionState().hadException()); |
260 request->show(scope.getScriptState()); | 281 request->show(scope.getScriptState()); |
261 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); | 282 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); |
262 | 283 |
263 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); | 284 String onRejected; |
please use gerrit instead
2016/07/13 15:55:26
errorMessage
pals
2016/07/14 08:37:38
Done.
| |
285 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall(&onRejected)); | |
264 | 286 |
265 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 287 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::UNKNOWN); |
288 | |
289 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | |
290 EXPECT_EQ("SyntaxError: The payment request is cancelled due to unknown reas ons", onRejected); | |
266 } | 291 } |
267 | 292 |
268 // If user cancels the transaction during processing, the complete() promise | 293 // If user cancels the transaction during processing, the complete() promise |
269 // should be rejected. | 294 // should be rejected. |
270 TEST(PaymentRequestTest, RejectCompletePromiseAfterError) | 295 TEST(PaymentRequestTest, RejectCompletePromiseAfterError) |
271 { | 296 { |
272 V8TestingScope scope; | 297 V8TestingScope scope; |
273 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 298 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
274 makePaymentRequestOriginSecure(scope.document()); | 299 makePaymentRequestOriginSecure(scope.document()); |
275 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); | 300 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); |
276 EXPECT_FALSE(scope.getExceptionState().hadException()); | 301 EXPECT_FALSE(scope.getExceptionState().hadException()); |
277 request->show(scope.getScriptState()); | 302 request->show(scope.getScriptState()); |
278 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); | 303 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); |
279 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 304 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::USER_CANCEL); |
280 | 305 |
281 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); | 306 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); |
282 } | 307 } |
283 | 308 |
284 TEST(PaymentRequestTest, ResolvePromiseOnComplete) | 309 TEST(PaymentRequestTest, ResolvePromiseOnComplete) |
285 { | 310 { |
286 V8TestingScope scope; | 311 V8TestingScope scope; |
287 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 312 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
288 makePaymentRequestOriginSecure(scope.document()); | 313 makePaymentRequestOriginSecure(scope.document()); |
289 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); | 314 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 450 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
426 | 451 |
427 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); | 452 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); |
428 EXPECT_FALSE(scope.getExceptionState().hadException()); | 453 EXPECT_FALSE(scope.getExceptionState().hadException()); |
429 | 454 |
430 EXPECT_EQ("fast", request->shippingOption()); | 455 EXPECT_EQ("fast", request->shippingOption()); |
431 } | 456 } |
432 | 457 |
433 } // namespace | 458 } // namespace |
434 } // namespace blink | 459 } // namespace blink |
OLD | NEW |