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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 { | 325 { |
326 V8TestingScope scope; | 326 V8TestingScope scope; |
327 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 327 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
328 makePaymentRequestOriginSecure(scope.document()); | 328 makePaymentRequestOriginSecure(scope.document()); |
329 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 329 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
330 EXPECT_FALSE(scope.getExceptionState().hadException()); | 330 EXPECT_FALSE(scope.getExceptionState().hadException()); |
331 | 331 |
332 String errorMessage; | 332 String errorMessage; |
333 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall(&errorMessage)); | 333 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall(&errorMessage)); |
334 | 334 |
335 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat
e(), "oops")); | 335 request->onUpdatePaymentDetailsFailure("oops"); |
336 | 336 |
337 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 337 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
338 EXPECT_EQ("AbortError: oops", errorMessage); | 338 EXPECT_EQ("AbortError: oops", errorMessage); |
339 } | 339 } |
340 | 340 |
341 TEST(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) | 341 TEST(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) |
342 { | 342 { |
343 V8TestingScope scope; | 343 V8TestingScope scope; |
344 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 344 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
345 makePaymentRequestOriginSecure(scope.document()); | 345 makePaymentRequestOriginSecure(scope.document()); |
346 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 346 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
347 EXPECT_FALSE(scope.getExceptionState().hadException()); | 347 EXPECT_FALSE(scope.getExceptionState().hadException()); |
348 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN
oCall()); | 348 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN
oCall()); |
349 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 349 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
350 | 350 |
351 String errorMessage; | 351 String errorMessage; |
352 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall()
, funcs.expectCall(&errorMessage)); | 352 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall()
, funcs.expectCall(&errorMessage)); |
353 | 353 |
354 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat
e(), "oops")); | 354 request->onUpdatePaymentDetailsFailure("oops"); |
355 | 355 |
356 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 356 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
357 EXPECT_EQ("AbortError: oops", errorMessage); | 357 EXPECT_EQ("AbortError: oops", errorMessage); |
358 } | 358 } |
359 | 359 |
360 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) | 360 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) |
361 { | 361 { |
362 V8TestingScope scope; | 362 V8TestingScope scope; |
363 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 363 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
364 makePaymentRequestOriginSecure(scope.document()); | 364 makePaymentRequestOriginSecure(scope.document()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 458 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
459 | 459 |
460 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr
omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); | 460 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr
omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); |
461 EXPECT_FALSE(scope.getExceptionState().hadException()); | 461 EXPECT_FALSE(scope.getExceptionState().hadException()); |
462 | 462 |
463 EXPECT_EQ("fast", request->shippingOption()); | 463 EXPECT_EQ("fast", request->shippingOption()); |
464 } | 464 } |
465 | 465 |
466 } // namespace | 466 } // namespace |
467 } // namespace blink | 467 } // namespace blink |
OLD | NEW |