| 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/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/JSONValuesForV8.h" | 8 #include "bindings/core/v8/JSONValuesForV8.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 details.setTotal(buildPaymentItemForTest()); | 96 details.setTotal(buildPaymentItemForTest()); |
| 97 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); | 97 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); |
| 98 PaymentOptions options; | 98 PaymentOptions options; |
| 99 options.setRequestShipping(true); | 99 options.setRequestShipping(true); |
| 100 | 100 |
| 101 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 101 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); |
| 102 | 102 |
| 103 EXPECT_TRUE(request->shippingOption().isNull()); | 103 EXPECT_TRUE(request->shippingOption().isNull()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques
ted) | 106 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) |
| 107 { | 107 { |
| 108 PaymentDetails details; | 108 PaymentDetails details; |
| 109 details.setTotal(buildPaymentItemForTest()); | 109 details.setTotal(buildPaymentItemForTest()); |
| 110 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); | 110 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); |
| 111 |
| 112 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); |
| 113 |
| 114 EXPECT_TRUE(request->shippingOption().isNull()); |
| 115 } |
| 116 |
| 117 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo
tRequested) |
| 118 { |
| 119 PaymentDetails details; |
| 120 details.setTotal(buildPaymentItemForTest()); |
| 121 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); |
| 122 PaymentOptions options; |
| 123 options.setRequestShipping(false); |
| 124 |
| 125 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); |
| 126 |
| 127 EXPECT_TRUE(request->shippingOption().isNull()); |
| 128 } |
| 129 |
| 130 TEST_F(PaymentRequestTest, DontSelectSingleUnselectedShippingOptionWhenShippingR
equested) |
| 131 { |
| 132 PaymentDetails details; |
| 133 details.setTotal(buildPaymentItemForTest()); |
| 134 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); |
| 111 PaymentOptions options; | 135 PaymentOptions options; |
| 112 options.setRequestShipping(true); | 136 options.setRequestShipping(true); |
| 113 | 137 |
| 138 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); |
| 139 |
| 140 EXPECT_TRUE(request->shippingOption().isNull()); |
| 141 } |
| 142 |
| 143 TEST_F(PaymentRequestTest, SelectSingleSelectedShippingOptionWhenShippingRequest
ed) |
| 144 { |
| 145 PaymentDetails details; |
| 146 details.setTotal(buildPaymentItemForTest()); |
| 147 HeapVector<ShippingOption> shippingOptions(1, buildShippingOptionForTest(Pay
mentTestDataId, PaymentTestOverwriteValue, "standard")); |
| 148 shippingOptions[0].setSelected(true); |
| 149 details.setShippingOptions(shippingOptions); |
| 150 PaymentOptions options; |
| 151 options.setRequestShipping(true); |
| 152 |
| 114 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 153 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); |
| 115 | 154 |
| 116 EXPECT_EQ("standard", request->shippingOption()); | 155 EXPECT_EQ("standard", request->shippingOption()); |
| 117 } | 156 } |
| 118 | 157 |
| 119 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) | 158 TEST_F(PaymentRequestTest, SelectOnlySelectedShippingOptionWhenShippingRequested
) |
| 120 { | 159 { |
| 121 PaymentDetails details; | 160 PaymentDetails details; |
| 122 details.setTotal(buildPaymentItemForTest()); | 161 details.setTotal(buildPaymentItemForTest()); |
| 123 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); | 162 HeapVector<ShippingOption> shippingOptions(2); |
| 163 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); |
| 164 shippingOptions[0].setSelected(true); |
| 165 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); |
| 166 details.setShippingOptions(shippingOptions); |
| 167 PaymentOptions options; |
| 168 options.setRequestShipping(true); |
| 124 | 169 |
| 125 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); | 170 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); |
| 126 | 171 |
| 127 EXPECT_TRUE(request->shippingOption().isNull()); | 172 EXPECT_EQ("standard", request->shippingOption()); |
| 128 } | 173 } |
| 129 | 174 |
| 130 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo
tRequested) | 175 TEST_F(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested
) |
| 131 { | 176 { |
| 132 PaymentDetails details; | 177 PaymentDetails details; |
| 133 details.setTotal(buildPaymentItemForTest()); | 178 details.setTotal(buildPaymentItemForTest()); |
| 134 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); | 179 HeapVector<ShippingOption> shippingOptions(2); |
| 180 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); |
| 181 shippingOptions[0].setSelected(true); |
| 182 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); |
| 183 shippingOptions[1].setSelected(true); |
| 184 details.setShippingOptions(shippingOptions); |
| 135 PaymentOptions options; | 185 PaymentOptions options; |
| 136 options.setRequestShipping(false); | 186 options.setRequestShipping(true); |
| 137 | 187 |
| 138 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 188 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); |
| 139 | 189 |
| 140 EXPECT_TRUE(request->shippingOption().isNull()); | 190 EXPECT_EQ("express", request->shippingOption()); |
| 141 } | 191 } |
| 142 | 192 |
| 143 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) | 193 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) |
| 144 { | 194 { |
| 145 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 195 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
| 146 EXPECT_FALSE(getExceptionState().hadException()); | 196 EXPECT_FALSE(getExceptionState().hadException()); |
| 147 | 197 |
| 148 request->abort(getExceptionState()); | 198 request->abort(getExceptionState()); |
| 149 EXPECT_TRUE(getExceptionState().hadException()); | 199 EXPECT_TRUE(getExceptionState().hadException()); |
| 150 } | 200 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 ScriptState::Scope scope(getScriptState()); | 442 ScriptState::Scope scope(getScriptState()); |
| 393 PaymentDetails details; | 443 PaymentDetails details; |
| 394 details.setTotal(buildPaymentItemForTest()); | 444 details.setTotal(buildPaymentItemForTest()); |
| 395 PaymentOptions options; | 445 PaymentOptions options; |
| 396 options.setRequestShipping(true); | 446 options.setRequestShipping(true); |
| 397 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 447 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); |
| 398 EXPECT_FALSE(getExceptionState().hadException()); | 448 EXPECT_FALSE(getExceptionState().hadException()); |
| 399 EXPECT_TRUE(request->shippingOption().isNull()); | 449 EXPECT_TRUE(request->shippingOption().isNull()); |
| 400 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 450 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 401 String detailWithShippingOptions = "{\"total\": {\"label\": \"Total\", \"amo
unt\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 451 String detailWithShippingOptions = "{\"total\": {\"label\": \"Total\", \"amo
unt\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 402 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; | 452 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"},
\"selected\": true}]}"; |
| 403 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); | 453 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); |
| 404 EXPECT_FALSE(getExceptionState().hadException()); | 454 EXPECT_FALSE(getExceptionState().hadException()); |
| 405 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 455 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| 406 String detailWithoutShippingOptions = "{\"total\": {\"label\": \"Total\", \"
amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}}"; | 456 String detailWithoutShippingOptions = "{\"total\": {\"label\": \"Total\", \"
amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}}"; |
| 407 | 457 |
| 408 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); | 458 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); |
| 409 | 459 |
| 410 EXPECT_FALSE(getExceptionState().hadException()); | 460 EXPECT_FALSE(getExceptionState().hadException()); |
| 411 EXPECT_TRUE(request->shippingOption().isNull()); | 461 EXPECT_TRUE(request->shippingOption().isNull()); |
| 412 } | 462 } |
| 413 | 463 |
| 414 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
ShippingOptions) | 464 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
UnselectedShippingOptions) |
| 415 { | 465 { |
| 416 ScriptState::Scope scope(getScriptState()); | 466 ScriptState::Scope scope(getScriptState()); |
| 417 PaymentOptions options; | 467 PaymentOptions options; |
| 418 options.setRequestShipping(true); | 468 options.setRequestShipping(true); |
| 419 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 469 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| 420 EXPECT_FALSE(getExceptionState().hadException()); | 470 EXPECT_FALSE(getExceptionState().hadException()); |
| 421 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 471 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 422 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," | 472 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," |
| 423 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 473 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 424 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; | 474 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; |
| 425 | 475 |
| 426 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 476 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 427 EXPECT_FALSE(getExceptionState().hadException()); | 477 EXPECT_FALSE(getExceptionState().hadException()); |
| 428 | 478 |
| 429 EXPECT_TRUE(request->shippingOption().isNull()); | 479 EXPECT_TRUE(request->shippingOption().isNull()); |
| 430 } | 480 } |
| 431 | 481 |
| 432 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate) | 482 TEST_F(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) |
| 433 { | 483 { |
| 434 ScriptState::Scope scope(getScriptState()); | 484 ScriptState::Scope scope(getScriptState()); |
| 435 PaymentOptions options; | 485 PaymentOptions options; |
| 436 options.setRequestShipping(true); | 486 options.setRequestShipping(true); |
| 437 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 487 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| 438 EXPECT_FALSE(getExceptionState().hadException()); | 488 EXPECT_FALSE(getExceptionState().hadException()); |
| 439 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 489 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 440 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," | 490 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," |
| 441 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; | 491 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 492 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 442 | 493 |
| 443 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 494 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 444 EXPECT_FALSE(getExceptionState().hadException()); | 495 EXPECT_FALSE(getExceptionState().hadException()); |
| 445 | 496 |
| 446 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 497 EXPECT_EQ("fast", request->shippingOption()); |
| 447 } | 498 } |
| 448 | 499 |
| 449 } // namespace | 500 } // namespace |
| 450 } // namespace blink | 501 } // namespace blink |
| OLD | NEW |