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/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 shippingOptions[1].setSelected(true); | 177 shippingOptions[1].setSelected(true); |
178 details.setShippingOptions(shippingOptions); | 178 details.setShippingOptions(shippingOptions); |
179 PaymentOptions options; | 179 PaymentOptions options; |
180 options.setRequestShipping(true); | 180 options.setRequestShipping(true); |
181 | 181 |
182 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); | 182 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
183 | 183 |
184 EXPECT_EQ("express", request->shippingOption()); | 184 EXPECT_EQ("express", request->shippingOption()); |
185 } | 185 } |
186 | 186 |
| 187 TEST(PaymentRequestTest, NullShippingTypeWhenRequestShippingIsFalse) |
| 188 { |
| 189 V8TestingScope scope; |
| 190 makePaymentRequestOriginSecure(scope.document()); |
| 191 PaymentDetails details; |
| 192 details.setTotal(buildPaymentItemForTest()); |
| 193 PaymentOptions options; |
| 194 options.setRequestShipping(false); |
| 195 |
| 196 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 197 |
| 198 EXPECT_TRUE(request->shippingType().isNull()); |
| 199 } |
| 200 |
| 201 TEST(PaymentRequestTest, DefaultShippingTypeWhenRequestShippingIsTrueWithNoSpeci
ficType) |
| 202 { |
| 203 V8TestingScope scope; |
| 204 makePaymentRequestOriginSecure(scope.document()); |
| 205 PaymentDetails details; |
| 206 details.setTotal(buildPaymentItemForTest()); |
| 207 PaymentOptions options; |
| 208 options.setRequestShipping(true); |
| 209 |
| 210 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 211 |
| 212 EXPECT_EQ("shipping", request->shippingType()); |
| 213 } |
| 214 |
| 215 TEST(PaymentRequestTest, DeliveryShippingTypeWhenShippingTypeIsDelivery) |
| 216 { |
| 217 V8TestingScope scope; |
| 218 makePaymentRequestOriginSecure(scope.document()); |
| 219 PaymentDetails details; |
| 220 details.setTotal(buildPaymentItemForTest()); |
| 221 PaymentOptions options; |
| 222 options.setRequestShipping(true); |
| 223 options.setShippingType("delivery"); |
| 224 |
| 225 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 226 |
| 227 EXPECT_EQ("delivery", request->shippingType()); |
| 228 } |
| 229 |
| 230 TEST(PaymentRequestTest, PickupShippingTypeWhenShippingTypeIsPickup) |
| 231 { |
| 232 V8TestingScope scope; |
| 233 makePaymentRequestOriginSecure(scope.document()); |
| 234 PaymentDetails details; |
| 235 details.setTotal(buildPaymentItemForTest()); |
| 236 PaymentOptions options; |
| 237 options.setRequestShipping(true); |
| 238 options.setShippingType("pickup"); |
| 239 |
| 240 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 241 |
| 242 EXPECT_EQ("pickup", request->shippingType()); |
| 243 } |
| 244 |
| 245 TEST(PaymentRequestTest, DefaultShippingTypeWhenShippingTypeIsInvalid) |
| 246 { |
| 247 V8TestingScope scope; |
| 248 makePaymentRequestOriginSecure(scope.document()); |
| 249 PaymentDetails details; |
| 250 details.setTotal(buildPaymentItemForTest()); |
| 251 PaymentOptions options; |
| 252 options.setRequestShipping(true); |
| 253 options.setShippingType("invalid"); |
| 254 |
| 255 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| 256 |
| 257 EXPECT_EQ("shipping", request->shippingType()); |
| 258 } |
| 259 |
187 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) | 260 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) |
188 { | 261 { |
189 V8TestingScope scope; | 262 V8TestingScope scope; |
190 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 263 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
191 makePaymentRequestOriginSecure(scope.document()); | 264 makePaymentRequestOriginSecure(scope.document()); |
192 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); | 265 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui
ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt
ate()); |
193 EXPECT_FALSE(scope.getExceptionState().hadException()); | 266 EXPECT_FALSE(scope.getExceptionState().hadException()); |
194 | 267 |
195 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); | 268 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec
tCall()); |
196 | 269 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 461 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
389 | 462 |
390 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr
omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); | 463 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr
omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); |
391 EXPECT_FALSE(scope.getExceptionState().hadException()); | 464 EXPECT_FALSE(scope.getExceptionState().hadException()); |
392 | 465 |
393 EXPECT_EQ("fast", request->shippingOption()); | 466 EXPECT_EQ("fast", request->shippingOption()); |
394 } | 467 } |
395 | 468 |
396 } // namespace | 469 } // namespace |
397 } // namespace blink | 470 } // namespace blink |
OLD | NEW |