| 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/ScriptFunction.h" | 8 #include "bindings/core/v8/ScriptFunction.h" |
| 9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
| 10 #include "bindings/modules/v8/V8PaymentResponse.h" | 10 #include "bindings/modules/v8/V8PaymentResponse.h" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 354 |
| 355 TEST(PaymentRequestTest, CannotCallCompleteTwice) | 355 TEST(PaymentRequestTest, CannotCallCompleteTwice) |
| 356 { | 356 { |
| 357 V8TestingScope scope; | 357 V8TestingScope scope; |
| 358 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 358 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 359 makePaymentRequestOriginSecure(scope.document()); | 359 makePaymentRequestOriginSecure(scope.document()); |
| 360 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 360 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| 361 EXPECT_FALSE(scope.getExceptionState().hadException()); | 361 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 362 request->show(scope.getScriptState()); | 362 request->show(scope.getScriptState()); |
| 363 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 363 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 364 request->complete(scope.getScriptState(), false); | 364 request->complete(scope.getScriptState(), Fail); |
| 365 | 365 |
| 366 request->complete(scope.getScriptState(), true).then(funcs.expectNoCall(), f
uncs.expectCall()); | 366 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall()
, funcs.expectCall()); |
| 367 } | 367 } |
| 368 | 368 |
| 369 TEST(PaymentRequestTest, RejectShowPromiseOnError) | 369 TEST(PaymentRequestTest, RejectShowPromiseOnError) |
| 370 { | 370 { |
| 371 V8TestingScope scope; | 371 V8TestingScope scope; |
| 372 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 372 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 373 makePaymentRequestOriginSecure(scope.document()); | 373 makePaymentRequestOriginSecure(scope.document()); |
| 374 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 374 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| 375 EXPECT_FALSE(scope.getExceptionState().hadException()); | 375 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 376 | 376 |
| 377 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 377 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 378 | 378 |
| 379 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 379 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 TEST(PaymentRequestTest, RejectCompletePromiseOnError) | 382 TEST(PaymentRequestTest, RejectCompletePromiseOnError) |
| 383 { | 383 { |
| 384 V8TestingScope scope; | 384 V8TestingScope scope; |
| 385 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 385 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 386 makePaymentRequestOriginSecure(scope.document()); | 386 makePaymentRequestOriginSecure(scope.document()); |
| 387 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 387 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| 388 EXPECT_FALSE(scope.getExceptionState().hadException()); | 388 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 389 request->show(scope.getScriptState()); | 389 request->show(scope.getScriptState()); |
| 390 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 390 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 391 | 391 |
| 392 request->complete(scope.getScriptState(), true).then(funcs.expectNoCall(), f
uncs.expectCall()); | 392 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall()
, funcs.expectCall()); |
| 393 | 393 |
| 394 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 394 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 TEST(PaymentRequestTest, ResolvePromiseOnComplete) | 397 TEST(PaymentRequestTest, ResolvePromiseOnComplete) |
| 398 { | 398 { |
| 399 V8TestingScope scope; | 399 V8TestingScope scope; |
| 400 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 400 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 401 makePaymentRequestOriginSecure(scope.document()); | 401 makePaymentRequestOriginSecure(scope.document()); |
| 402 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 402 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| 403 EXPECT_FALSE(scope.getExceptionState().hadException()); | 403 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 404 request->show(scope.getScriptState()); | 404 request->show(scope.getScriptState()); |
| 405 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 405 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 406 | 406 |
| 407 request->complete(scope.getScriptState(), true).then(funcs.expectCall(), fun
cs.expectNoCall()); | 407 request->complete(scope.getScriptState(), Success).then(funcs.expectCall(),
funcs.expectNoCall()); |
| 408 | 408 |
| 409 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); | 409 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) | 412 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) |
| 413 { | 413 { |
| 414 V8TestingScope scope; | 414 V8TestingScope scope; |
| 415 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 415 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 416 makePaymentRequestOriginSecure(scope.document()); | 416 makePaymentRequestOriginSecure(scope.document()); |
| 417 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 417 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| 418 EXPECT_FALSE(scope.getExceptionState().hadException()); | 418 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 419 | 419 |
| 420 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 420 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 421 | 421 |
| 422 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat
e(), "oops")); | 422 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat
e(), "oops")); |
| 423 } | 423 } |
| 424 | 424 |
| 425 TEST(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) | 425 TEST(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) |
| 426 { | 426 { |
| 427 V8TestingScope scope; | 427 V8TestingScope scope; |
| 428 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 428 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 429 makePaymentRequestOriginSecure(scope.document()); | 429 makePaymentRequestOriginSecure(scope.document()); |
| 430 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 430 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| 431 EXPECT_FALSE(scope.getExceptionState().hadException()); | 431 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 432 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN
oCall()); | 432 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN
oCall()); |
| 433 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 433 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 434 | 434 |
| 435 request->complete(scope.getScriptState(), true).then(funcs.expectNoCall(), f
uncs.expectCall()); | 435 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall()
, funcs.expectCall()); |
| 436 | 436 |
| 437 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat
e(), "oops")); | 437 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat
e(), "oops")); |
| 438 } | 438 } |
| 439 | 439 |
| 440 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) | 440 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) |
| 441 { | 441 { |
| 442 V8TestingScope scope; | 442 V8TestingScope scope; |
| 443 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 443 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 444 makePaymentRequestOriginSecure(scope.document()); | 444 makePaymentRequestOriginSecure(scope.document()); |
| 445 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 445 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 738 |
| 739 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 739 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 740 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 740 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 741 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | 741 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
| 742 | 742 |
| 743 EXPECT_TRUE(pr->payerPhone().isNull()); | 743 EXPECT_TRUE(pr->payerPhone().isNull()); |
| 744 } | 744 } |
| 745 | 745 |
| 746 } // namespace | 746 } // namespace |
| 747 } // namespace blink | 747 } // namespace blink |
| OLD | NEW |