| 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<mojom::blink::PaymentRequestClient*>(request) | 317 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 318 ->OnShippingAddressChange(mojom::blink::PaymentAddress::New()); | 318 ->OnShippingAddressChange(payments::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<mojom::blink::PaymentRequestClient*>(request) | 333 static_cast<payments::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<mojom::blink::PaymentRequestClient*>(request)->OnAbort(true); | 361 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( |
| 362 true); |
| 362 | 363 |
| 363 request->show(scope.getScriptState()) | 364 request->show(scope.getScriptState()) |
| 364 .then(funcs.expectNoCall(), funcs.expectCall()); | 365 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 365 } | 366 } |
| 366 | 367 |
| 367 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { | 368 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { |
| 368 V8TestingScope scope; | 369 V8TestingScope scope; |
| 369 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 370 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 370 makePaymentRequestOriginSecure(scope.document()); | 371 makePaymentRequestOriginSecure(scope.document()); |
| 371 PaymentRequest* request = PaymentRequest::create( | 372 PaymentRequest* request = PaymentRequest::create( |
| 372 scope.getScriptState(), buildPaymentMethodDataForTest(), | 373 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 373 buildPaymentDetailsForTest(), scope.getExceptionState()); | 374 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 374 EXPECT_FALSE(scope.getExceptionState().hadException()); | 375 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 375 | 376 |
| 376 String errorMessage; | 377 String errorMessage; |
| 377 request->show(scope.getScriptState()) | 378 request->show(scope.getScriptState()) |
| 378 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 379 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
| 379 | 380 |
| 380 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError( | 381 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( |
| 381 mojom::blink::PaymentErrorReason::NOT_SUPPORTED); | 382 payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED); |
| 382 | 383 |
| 383 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 384 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
| 384 EXPECT_EQ("NotSupportedError: The payment method is not supported", | 385 EXPECT_EQ("NotSupportedError: The payment method is not supported", |
| 385 errorMessage); | 386 errorMessage); |
| 386 } | 387 } |
| 387 | 388 |
| 388 TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { | 389 TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { |
| 389 V8TestingScope scope; | 390 V8TestingScope scope; |
| 390 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 391 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 391 makePaymentRequestOriginSecure(scope.document()); | 392 makePaymentRequestOriginSecure(scope.document()); |
| 392 PaymentRequest* request = PaymentRequest::create( | 393 PaymentRequest* request = PaymentRequest::create( |
| 393 scope.getScriptState(), buildPaymentMethodDataForTest(), | 394 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 394 buildPaymentDetailsForTest(), scope.getExceptionState()); | 395 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 395 EXPECT_FALSE(scope.getExceptionState().hadException()); | 396 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 396 | 397 |
| 397 String errorMessage; | 398 String errorMessage; |
| 398 request->show(scope.getScriptState()) | 399 request->show(scope.getScriptState()) |
| 399 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 400 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
| 400 | 401 |
| 401 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError( | 402 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( |
| 402 mojom::blink::PaymentErrorReason::USER_CANCEL); | 403 payments::mojom::blink::PaymentErrorReason::USER_CANCEL); |
| 403 | 404 |
| 404 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 405 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
| 405 EXPECT_EQ("Request cancelled", errorMessage); | 406 EXPECT_EQ("Request cancelled", errorMessage); |
| 406 } | 407 } |
| 407 | 408 |
| 408 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { | 409 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { |
| 409 V8TestingScope scope; | 410 V8TestingScope scope; |
| 410 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 411 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 411 makePaymentRequestOriginSecure(scope.document()); | 412 makePaymentRequestOriginSecure(scope.document()); |
| 412 PaymentRequest* request = PaymentRequest::create( | 413 PaymentRequest* request = PaymentRequest::create( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 427 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { | 428 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { |
| 428 V8TestingScope scope; | 429 V8TestingScope scope; |
| 429 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 430 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 430 makePaymentRequestOriginSecure(scope.document()); | 431 makePaymentRequestOriginSecure(scope.document()); |
| 431 PaymentRequest* request = PaymentRequest::create( | 432 PaymentRequest* request = PaymentRequest::create( |
| 432 scope.getScriptState(), buildPaymentMethodDataForTest(), | 433 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 433 buildPaymentDetailsForTest(), scope.getExceptionState()); | 434 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 434 EXPECT_FALSE(scope.getExceptionState().hadException()); | 435 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 435 request->show(scope.getScriptState()) | 436 request->show(scope.getScriptState()) |
| 436 .then(funcs.expectCall(), funcs.expectNoCall()); | 437 .then(funcs.expectCall(), funcs.expectNoCall()); |
| 437 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse( | 438 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 438 buildPaymentResponseForTest()); | 439 ->OnPaymentResponse(buildPaymentResponseForTest()); |
| 439 | 440 |
| 440 request->onUpdatePaymentDetails( | 441 request->onUpdatePaymentDetails( |
| 441 ScriptValue::from(scope.getScriptState(), "foo")); | 442 ScriptValue::from(scope.getScriptState(), "foo")); |
| 442 } | 443 } |
| 443 | 444 |
| 444 TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { | 445 TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { |
| 445 V8TestingScope scope; | 446 V8TestingScope scope; |
| 446 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 447 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 447 makePaymentRequestOriginSecure(scope.document()); | 448 makePaymentRequestOriginSecure(scope.document()); |
| 448 PaymentRequest* request = PaymentRequest::create( | 449 PaymentRequest* request = PaymentRequest::create( |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 scope.getScriptState(), | 636 scope.getScriptState(), |
| 636 fromJSONString(scope.getScriptState()->isolate(), | 637 fromJSONString(scope.getScriptState()->isolate(), |
| 637 detailWithShippingOptions, scope.getExceptionState()))); | 638 detailWithShippingOptions, scope.getExceptionState()))); |
| 638 | 639 |
| 639 EXPECT_FALSE(scope.getExceptionState().hadException()); | 640 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 640 EXPECT_TRUE(request->shippingOption().isNull()); | 641 EXPECT_TRUE(request->shippingOption().isNull()); |
| 641 } | 642 } |
| 642 | 643 |
| 643 } // namespace | 644 } // namespace |
| 644 } // namespace blink | 645 } // namespace blink |
| OLD | NEW |