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 // Tests for PaymentRequest::OnPaymentResponse(). | 5 // Tests for PaymentRequest::OnPaymentResponse(). |
6 | 6 |
7 #include "bindings/core/v8/ScriptFunction.h" | 7 #include "bindings/core/v8/ScriptFunction.h" |
8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
9 #include "bindings/modules/v8/V8PaymentResponse.h" | 9 #include "bindings/modules/v8/V8PaymentResponse.h" |
10 #include "modules/payments/PaymentAddress.h" | 10 #include "modules/payments/PaymentAddress.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 50 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
51 ASSERT_FALSE(scope.getExceptionState().hadException()); | 51 ASSERT_FALSE(scope.getExceptionState().hadException()); |
52 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); | 52 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); |
53 response->shipping_option = "standardShipping"; | 53 response->shipping_option = "standardShipping"; |
54 | 54 |
55 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 55 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
56 | 56 |
57 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 57 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
58 } | 58 } |
59 | 59 |
| 60 // If the merchant requests a payer name, but the browser does not provide it, |
| 61 // reject the show() promise. |
| 62 TEST(OnPaymentResponseTest, RejectMissingName) |
| 63 { |
| 64 V8TestingScope scope; |
| 65 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 66 makePaymentRequestOriginSecure(scope.document()); |
| 67 PaymentOptions options; |
| 68 options.setRequestPayerName(true); |
| 69 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 70 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 71 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 72 |
| 73 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 74 |
| 75 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 76 } |
| 77 |
60 // If the merchant requests an email address, but the browser does not provide | 78 // If the merchant requests an email address, but the browser does not provide |
61 // it, reject the show() promise. | 79 // it, reject the show() promise. |
62 TEST(OnPaymentResponseTest, RejectMissingEmail) | 80 TEST(OnPaymentResponseTest, RejectMissingEmail) |
63 { | 81 { |
64 V8TestingScope scope; | 82 V8TestingScope scope; |
65 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 83 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
66 makePaymentRequestOriginSecure(scope.document()); | 84 makePaymentRequestOriginSecure(scope.document()); |
67 PaymentOptions options; | 85 PaymentOptions options; |
68 options.setRequestPayerEmail(true); | 86 options.setRequestPayerEmail(true); |
69 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 87 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 ASSERT_FALSE(scope.getExceptionState().hadException()); | 147 ASSERT_FALSE(scope.getExceptionState().hadException()); |
130 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); | 148 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); |
131 response->shipping_option = "standardShipping"; | 149 response->shipping_option = "standardShipping"; |
132 response->shipping_address = mojom::blink::PaymentAddress::New(); | 150 response->shipping_address = mojom::blink::PaymentAddress::New(); |
133 | 151 |
134 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 152 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
135 | 153 |
136 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 154 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
137 } | 155 } |
138 | 156 |
| 157 // If the merchant requests a payer name, but the browser provides an empty |
| 158 // string for name, reject the show() promise. |
| 159 TEST(OnPaymentResponseTest, RejectEmptyName) |
| 160 { |
| 161 V8TestingScope scope; |
| 162 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 163 makePaymentRequestOriginSecure(scope.document()); |
| 164 PaymentOptions options; |
| 165 options.setRequestPayerName(true); |
| 166 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 167 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 168 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 169 response->payer_name = ""; |
| 170 |
| 171 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 172 |
| 173 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 174 } |
| 175 |
139 // If the merchant requests an email, but the browser provides an empty string | 176 // If the merchant requests an email, but the browser provides an empty string |
140 // for email, reject the show() promise. | 177 // for email, reject the show() promise. |
141 TEST(OnPaymentResponseTest, RejectEmptyEmail) | 178 TEST(OnPaymentResponseTest, RejectEmptyEmail) |
142 { | 179 { |
143 V8TestingScope scope; | 180 V8TestingScope scope; |
144 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 181 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
145 makePaymentRequestOriginSecure(scope.document()); | 182 makePaymentRequestOriginSecure(scope.document()); |
146 PaymentOptions options; | 183 PaymentOptions options; |
147 options.setRequestPayerEmail(true); | 184 options.setRequestPayerEmail(true); |
148 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 185 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 245 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
209 ASSERT_FALSE(scope.getExceptionState().hadException()); | 246 ASSERT_FALSE(scope.getExceptionState().hadException()); |
210 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 247 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
211 response->shipping_option = ""; | 248 response->shipping_option = ""; |
212 | 249 |
213 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 250 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
214 | 251 |
215 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 252 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
216 } | 253 } |
217 | 254 |
| 255 // If the merchant does not request a payer name, but the browser provides it, |
| 256 // reject the show() promise. |
| 257 TEST(OnPaymentResponseTest, RejectNotRequestedName) |
| 258 { |
| 259 V8TestingScope scope; |
| 260 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 261 makePaymentRequestOriginSecure(scope.document()); |
| 262 PaymentOptions options; |
| 263 options.setRequestPayerName(false); |
| 264 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 265 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 266 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 267 response->payer_name = ""; |
| 268 |
| 269 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
| 270 |
| 271 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 272 } |
| 273 |
218 // If the merchant does not request an email, but the browser provides it, | 274 // If the merchant does not request an email, but the browser provides it, |
219 // reject the show() promise. | 275 // reject the show() promise. |
220 TEST(OnPaymentResponseTest, RejectNotRequestedEmail) | 276 TEST(OnPaymentResponseTest, RejectNotRequestedEmail) |
221 { | 277 { |
222 V8TestingScope scope; | 278 V8TestingScope scope; |
223 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 279 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
224 makePaymentRequestOriginSecure(scope.document()); | 280 makePaymentRequestOriginSecure(scope.document()); |
225 PaymentOptions options; | 281 PaymentOptions options; |
226 options.setRequestPayerEmail(false); | 282 options.setRequestPayerEmail(false); |
227 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 283 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 378 |
323 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 379 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
324 | 380 |
325 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 381 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
326 PaymentResponse* resp = V8PaymentResponse::toImplWithTypeCheck(scope.isolate
(), outValue.v8Value()); | 382 PaymentResponse* resp = V8PaymentResponse::toImplWithTypeCheck(scope.isolate
(), outValue.v8Value()); |
327 EXPECT_EQ("standardShipping", resp->shippingOption()); | 383 EXPECT_EQ("standardShipping", resp->shippingOption()); |
328 EXPECT_EQ("US", resp->shippingAddress()->country()); | 384 EXPECT_EQ("US", resp->shippingAddress()->country()); |
329 EXPECT_EQ("en-Latn", resp->shippingAddress()->languageCode()); | 385 EXPECT_EQ("en-Latn", resp->shippingAddress()->languageCode()); |
330 } | 386 } |
331 | 387 |
| 388 // If the merchant requests a payer name, the resolved show() promise should |
| 389 // contain a payer name. |
| 390 TEST(OnPaymentResponseTest, CanRequestName) |
| 391 { |
| 392 V8TestingScope scope; |
| 393 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 394 makePaymentRequestOriginSecure(scope.document()); |
| 395 PaymentOptions options; |
| 396 options.setRequestPayerName(true); |
| 397 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 398 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 399 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 400 response->payer_name = "Jon Doe"; |
| 401 ScriptValue outValue; |
| 402 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); |
| 403 |
| 404 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 405 |
| 406 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 407 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
| 408 EXPECT_EQ("Jon Doe", pr->payerName()); |
| 409 } |
| 410 |
332 // If the merchant requests an email address, the resolved show() promise should | 411 // If the merchant requests an email address, the resolved show() promise should |
333 // contain an email address. | 412 // contain an email address. |
334 TEST(OnPaymentResponseTest, CanRequestEmail) | 413 TEST(OnPaymentResponseTest, CanRequestEmail) |
335 { | 414 { |
336 V8TestingScope scope; | 415 V8TestingScope scope; |
337 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 416 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
338 makePaymentRequestOriginSecure(scope.document()); | 417 makePaymentRequestOriginSecure(scope.document()); |
339 PaymentOptions options; | 418 PaymentOptions options; |
340 options.setRequestPayerEmail(true); | 419 options.setRequestPayerEmail(true); |
341 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 420 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 ScriptValue outValue; | 493 ScriptValue outValue; |
415 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | 494 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); |
416 | 495 |
417 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 496 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
418 | 497 |
419 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 498 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
420 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | 499 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
421 EXPECT_TRUE(pr->payerPhone().isNull()); | 500 EXPECT_TRUE(pr->payerPhone().isNull()); |
422 } | 501 } |
423 | 502 |
| 503 // If the merchant does not request a payer name, the resolved show() promise |
| 504 // should contain null payer name. |
| 505 TEST(OnPaymentResponseTest, NameNotRequired) |
| 506 { |
| 507 V8TestingScope scope; |
| 508 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 509 makePaymentRequestOriginSecure(scope.document()); |
| 510 PaymentOptions options; |
| 511 options.setRequestPayerName(false); |
| 512 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
| 513 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 514 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 515 response->payer_name = String(); |
| 516 ScriptValue outValue; |
| 517 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); |
| 518 |
| 519 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 520 |
| 521 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 522 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
| 523 EXPECT_TRUE(pr->payerName().isNull()); |
| 524 } |
| 525 |
424 // If the merchant does not request an email address, the resolved show() | 526 // If the merchant does not request an email address, the resolved show() |
425 // promise should contain null email address. | 527 // promise should contain null email address. |
426 TEST(OnPaymentResponseTest, EmailNotRequired) | 528 TEST(OnPaymentResponseTest, EmailNotRequired) |
427 { | 529 { |
428 V8TestingScope scope; | 530 V8TestingScope scope; |
429 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 531 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
430 makePaymentRequestOriginSecure(scope.document()); | 532 makePaymentRequestOriginSecure(scope.document()); |
431 PaymentOptions options; | 533 PaymentOptions options; |
432 options.setRequestPayerEmail(false); | 534 options.setRequestPayerEmail(false); |
433 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); | 535 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getEx
ceptionState()); |
434 EXPECT_FALSE(scope.getExceptionState().hadException()); | 536 EXPECT_FALSE(scope.getExceptionState().hadException()); |
435 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 537 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
436 response->payer_email = String(); | 538 response->payer_email = String(); |
437 ScriptValue outValue; | 539 ScriptValue outValue; |
438 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); | 540 request->show(scope.getScriptState()).then(PaymentResponseFunction::create(s
cope.getScriptState(), &outValue), funcs.expectNoCall()); |
439 | 541 |
440 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 542 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
441 | 543 |
442 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 544 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
443 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); | 545 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate()
, outValue.v8Value()); |
444 EXPECT_TRUE(pr->payerEmail().isNull()); | 546 EXPECT_TRUE(pr->payerEmail().isNull()); |
445 } | 547 } |
446 | 548 |
447 } // namespace | 549 } // namespace |
448 } // namespace blink | 550 } // namespace blink |
OLD | NEW |