| 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/V8BindingForTesting.h" | 7 #include "bindings/core/v8/V8BindingForTesting.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "modules/payments/PaymentTestHelper.h" | 10 #include "modules/payments/PaymentTestHelper.h" |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 307 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 308 makePaymentRequestOriginSecure(scope.document()); | 308 makePaymentRequestOriginSecure(scope.document()); |
| 309 PaymentRequest* request = PaymentRequest::create( | 309 PaymentRequest* request = PaymentRequest::create( |
| 310 scope.getScriptState(), buildPaymentMethodDataForTest(), | 310 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 311 buildPaymentDetailsForTest(), scope.getExceptionState()); | 311 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 312 EXPECT_FALSE(scope.getExceptionState().hadException()); | 312 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 313 | 313 |
| 314 request->show(scope.getScriptState()) | 314 request->show(scope.getScriptState()) |
| 315 .then(funcs.expectNoCall(), funcs.expectCall()); | 315 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 316 | 316 |
| 317 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 317 static_cast<mojom::blink::PaymentRequestClient*>(request) |
| 318 ->OnShippingAddressChange(payments::mojom::blink::PaymentAddress::New()); | 318 ->OnShippingAddressChange(mojom::blink::PaymentAddress::New()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 TEST(PaymentRequestTest, OnShippingOptionChange) { | 321 TEST(PaymentRequestTest, OnShippingOptionChange) { |
| 322 V8TestingScope scope; | 322 V8TestingScope scope; |
| 323 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 323 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 324 makePaymentRequestOriginSecure(scope.document()); | 324 makePaymentRequestOriginSecure(scope.document()); |
| 325 PaymentRequest* request = PaymentRequest::create( | 325 PaymentRequest* request = PaymentRequest::create( |
| 326 scope.getScriptState(), buildPaymentMethodDataForTest(), | 326 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 327 buildPaymentDetailsForTest(), scope.getExceptionState()); | 327 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 328 EXPECT_FALSE(scope.getExceptionState().hadException()); | 328 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 329 | 329 |
| 330 request->show(scope.getScriptState()) | 330 request->show(scope.getScriptState()) |
| 331 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 331 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 332 | 332 |
| 333 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 333 static_cast<mojom::blink::PaymentRequestClient*>(request) |
| 334 ->OnShippingOptionChange("standardShipping"); | 334 ->OnShippingOptionChange("standardShipping"); |
| 335 } | 335 } |
| 336 | 336 |
| 337 TEST(PaymentRequestTest, CannotCallShowTwice) { | 337 TEST(PaymentRequestTest, CannotCallShowTwice) { |
| 338 V8TestingScope scope; | 338 V8TestingScope scope; |
| 339 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 339 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 340 makePaymentRequestOriginSecure(scope.document()); | 340 makePaymentRequestOriginSecure(scope.document()); |
| 341 PaymentRequest* request = PaymentRequest::create( | 341 PaymentRequest* request = PaymentRequest::create( |
| 342 scope.getScriptState(), buildPaymentMethodDataForTest(), | 342 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 343 buildPaymentDetailsForTest(), scope.getExceptionState()); | 343 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 344 EXPECT_FALSE(scope.getExceptionState().hadException()); | 344 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 345 request->show(scope.getScriptState()); | 345 request->show(scope.getScriptState()); |
| 346 | 346 |
| 347 request->show(scope.getScriptState()) | 347 request->show(scope.getScriptState()) |
| 348 .then(funcs.expectNoCall(), funcs.expectCall()); | 348 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 349 } | 349 } |
| 350 | 350 |
| 351 TEST(PaymentRequestTest, CannotShowAfterAborted) { | 351 TEST(PaymentRequestTest, CannotShowAfterAborted) { |
| 352 V8TestingScope scope; | 352 V8TestingScope scope; |
| 353 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 353 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 354 makePaymentRequestOriginSecure(scope.document()); | 354 makePaymentRequestOriginSecure(scope.document()); |
| 355 PaymentRequest* request = PaymentRequest::create( | 355 PaymentRequest* request = PaymentRequest::create( |
| 356 scope.getScriptState(), buildPaymentMethodDataForTest(), | 356 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 357 buildPaymentDetailsForTest(), scope.getExceptionState()); | 357 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 358 EXPECT_FALSE(scope.getExceptionState().hadException()); | 358 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 359 request->show(scope.getScriptState()); | 359 request->show(scope.getScriptState()); |
| 360 request->abort(scope.getScriptState()); | 360 request->abort(scope.getScriptState()); |
| 361 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( | 361 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(true); |
| 362 true); | |
| 363 | 362 |
| 364 request->show(scope.getScriptState()) | 363 request->show(scope.getScriptState()) |
| 365 .then(funcs.expectNoCall(), funcs.expectCall()); | 364 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 366 } | 365 } |
| 367 | 366 |
| 368 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { | 367 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { |
| 369 V8TestingScope scope; | 368 V8TestingScope scope; |
| 370 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 369 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 371 makePaymentRequestOriginSecure(scope.document()); | 370 makePaymentRequestOriginSecure(scope.document()); |
| 372 PaymentRequest* request = PaymentRequest::create( | 371 PaymentRequest* request = PaymentRequest::create( |
| 373 scope.getScriptState(), buildPaymentMethodDataForTest(), | 372 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 374 buildPaymentDetailsForTest(), scope.getExceptionState()); | 373 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 375 EXPECT_FALSE(scope.getExceptionState().hadException()); | 374 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 376 | 375 |
| 377 String errorMessage; | 376 String errorMessage; |
| 378 request->show(scope.getScriptState()) | 377 request->show(scope.getScriptState()) |
| 379 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 378 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
| 380 | 379 |
| 381 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( | 380 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError( |
| 382 payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED); | 381 mojom::blink::PaymentErrorReason::NOT_SUPPORTED); |
| 383 | 382 |
| 384 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 383 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
| 385 EXPECT_EQ("NotSupportedError: The payment method is not supported", | 384 EXPECT_EQ("NotSupportedError: The payment method is not supported", |
| 386 errorMessage); | 385 errorMessage); |
| 387 } | 386 } |
| 388 | 387 |
| 389 TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { | 388 TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { |
| 390 V8TestingScope scope; | 389 V8TestingScope scope; |
| 391 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 390 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 392 makePaymentRequestOriginSecure(scope.document()); | 391 makePaymentRequestOriginSecure(scope.document()); |
| 393 PaymentRequest* request = PaymentRequest::create( | 392 PaymentRequest* request = PaymentRequest::create( |
| 394 scope.getScriptState(), buildPaymentMethodDataForTest(), | 393 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 395 buildPaymentDetailsForTest(), scope.getExceptionState()); | 394 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 396 EXPECT_FALSE(scope.getExceptionState().hadException()); | 395 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 397 | 396 |
| 398 String errorMessage; | 397 String errorMessage; |
| 399 request->show(scope.getScriptState()) | 398 request->show(scope.getScriptState()) |
| 400 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 399 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
| 401 | 400 |
| 402 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( | 401 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError( |
| 403 payments::mojom::blink::PaymentErrorReason::USER_CANCEL); | 402 mojom::blink::PaymentErrorReason::USER_CANCEL); |
| 404 | 403 |
| 405 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 404 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
| 406 EXPECT_EQ("Request cancelled", errorMessage); | 405 EXPECT_EQ("Request cancelled", errorMessage); |
| 407 } | 406 } |
| 408 | 407 |
| 409 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { | 408 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { |
| 410 V8TestingScope scope; | 409 V8TestingScope scope; |
| 411 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 410 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 412 makePaymentRequestOriginSecure(scope.document()); | 411 makePaymentRequestOriginSecure(scope.document()); |
| 413 PaymentRequest* request = PaymentRequest::create( | 412 PaymentRequest* request = PaymentRequest::create( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 428 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { | 427 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { |
| 429 V8TestingScope scope; | 428 V8TestingScope scope; |
| 430 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 429 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 431 makePaymentRequestOriginSecure(scope.document()); | 430 makePaymentRequestOriginSecure(scope.document()); |
| 432 PaymentRequest* request = PaymentRequest::create( | 431 PaymentRequest* request = PaymentRequest::create( |
| 433 scope.getScriptState(), buildPaymentMethodDataForTest(), | 432 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 434 buildPaymentDetailsForTest(), scope.getExceptionState()); | 433 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 435 EXPECT_FALSE(scope.getExceptionState().hadException()); | 434 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 436 request->show(scope.getScriptState()) | 435 request->show(scope.getScriptState()) |
| 437 .then(funcs.expectCall(), funcs.expectNoCall()); | 436 .then(funcs.expectCall(), funcs.expectNoCall()); |
| 438 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 437 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse( |
| 439 ->OnPaymentResponse(buildPaymentResponseForTest()); | 438 buildPaymentResponseForTest()); |
| 440 | 439 |
| 441 request->onUpdatePaymentDetails( | 440 request->onUpdatePaymentDetails( |
| 442 ScriptValue::from(scope.getScriptState(), "foo")); | 441 ScriptValue::from(scope.getScriptState(), "foo")); |
| 443 } | 442 } |
| 444 | 443 |
| 445 TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { | 444 TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { |
| 446 V8TestingScope scope; | 445 V8TestingScope scope; |
| 447 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 446 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 448 makePaymentRequestOriginSecure(scope.document()); | 447 makePaymentRequestOriginSecure(scope.document()); |
| 449 PaymentRequest* request = PaymentRequest::create( | 448 PaymentRequest* request = PaymentRequest::create( |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 scope.getScriptState(), | 635 scope.getScriptState(), |
| 637 fromJSONString(scope.getScriptState()->isolate(), | 636 fromJSONString(scope.getScriptState()->isolate(), |
| 638 detailWithShippingOptions, scope.getExceptionState()))); | 637 detailWithShippingOptions, scope.getExceptionState()))); |
| 639 | 638 |
| 640 EXPECT_FALSE(scope.getExceptionState().hadException()); | 639 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 641 EXPECT_TRUE(request->shippingOption().isNull()); | 640 EXPECT_TRUE(request->shippingOption().isNull()); |
| 642 } | 641 } |
| 643 | 642 |
| 644 } // namespace | 643 } // namespace |
| 645 } // namespace blink | 644 } // namespace blink |
| OLD | NEW |