| 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 30 matching lines...) Expand all Loading... |
| 41 V8TestingScope scope; | 41 V8TestingScope scope; |
| 42 MakePaymentRequestOriginSecure(scope.GetDocument()); | 42 MakePaymentRequestOriginSecure(scope.GetDocument()); |
| 43 PaymentRequest::Create( | 43 PaymentRequest::Create( |
| 44 scope.GetExecutionContext(), HeapVector<PaymentMethodData>(), | 44 scope.GetExecutionContext(), HeapVector<PaymentMethodData>(), |
| 45 BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); | 45 BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); |
| 46 | 46 |
| 47 EXPECT_TRUE(scope.GetExceptionState().HadException()); | 47 EXPECT_TRUE(scope.GetExceptionState().HadException()); |
| 48 EXPECT_EQ(kV8TypeError, scope.GetExceptionState().Code()); | 48 EXPECT_EQ(kV8TypeError, scope.GetExceptionState().Code()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST(PaymentRequestTest, TotalRequired) { | |
| 52 V8TestingScope scope; | |
| 53 MakePaymentRequestOriginSecure(scope.GetDocument()); | |
| 54 PaymentRequest::Create(scope.GetExecutionContext(), | |
| 55 BuildPaymentMethodDataForTest(), PaymentDetailsInit(), | |
| 56 scope.GetExceptionState()); | |
| 57 | |
| 58 EXPECT_TRUE(scope.GetExceptionState().HadException()); | |
| 59 EXPECT_EQ(kV8TypeError, scope.GetExceptionState().Code()); | |
| 60 } | |
| 61 | |
| 62 TEST(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) { | 51 TEST(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) { |
| 63 V8TestingScope scope; | 52 V8TestingScope scope; |
| 64 MakePaymentRequestOriginSecure(scope.GetDocument()); | 53 MakePaymentRequestOriginSecure(scope.GetDocument()); |
| 65 PaymentDetailsInit details; | 54 PaymentDetailsInit details; |
| 66 details.setTotal(BuildPaymentItemForTest()); | 55 details.setTotal(BuildPaymentItemForTest()); |
| 67 PaymentOptions options; | 56 PaymentOptions options; |
| 68 options.setRequestShipping(true); | 57 options.setRequestShipping(true); |
| 69 | 58 |
| 70 PaymentRequest* request = PaymentRequest::Create( | 59 PaymentRequest* request = PaymentRequest::Create( |
| 71 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details, | 60 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 options.setRequestShipping(true); | 256 options.setRequestShipping(true); |
| 268 options.setShippingType("pickup"); | 257 options.setShippingType("pickup"); |
| 269 | 258 |
| 270 PaymentRequest* request = PaymentRequest::Create( | 259 PaymentRequest* request = PaymentRequest::Create( |
| 271 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details, | 260 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details, |
| 272 options, scope.GetExceptionState()); | 261 options, scope.GetExceptionState()); |
| 273 | 262 |
| 274 EXPECT_EQ("pickup", request->shippingType()); | 263 EXPECT_EQ("pickup", request->shippingType()); |
| 275 } | 264 } |
| 276 | 265 |
| 277 TEST(PaymentRequestTest, DefaultShippingTypeWhenShippingTypeIsInvalid) { | |
| 278 V8TestingScope scope; | |
| 279 MakePaymentRequestOriginSecure(scope.GetDocument()); | |
| 280 PaymentDetailsInit details; | |
| 281 details.setTotal(BuildPaymentItemForTest()); | |
| 282 PaymentOptions options; | |
| 283 options.setRequestShipping(true); | |
| 284 options.setShippingType("invalid"); | |
| 285 | |
| 286 PaymentRequest* request = PaymentRequest::Create( | |
| 287 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details, | |
| 288 options, scope.GetExceptionState()); | |
| 289 | |
| 290 EXPECT_EQ("shipping", request->shippingType()); | |
| 291 } | |
| 292 | |
| 293 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) { | 266 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) { |
| 294 V8TestingScope scope; | 267 V8TestingScope scope; |
| 295 PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); | 268 PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); |
| 296 MakePaymentRequestOriginSecure(scope.GetDocument()); | 269 MakePaymentRequestOriginSecure(scope.GetDocument()); |
| 297 PaymentRequest* request = PaymentRequest::Create( | 270 PaymentRequest* request = PaymentRequest::Create( |
| 298 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), | 271 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), |
| 299 BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); | 272 BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); |
| 300 EXPECT_FALSE(scope.GetExceptionState().HadException()); | 273 EXPECT_FALSE(scope.GetExceptionState().HadException()); |
| 301 | 274 |
| 302 request->show(scope.GetScriptState()) | 275 request->show(scope.GetScriptState()) |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 613 |
| 641 PaymentRequest* request = PaymentRequest::Create( | 614 PaymentRequest* request = PaymentRequest::Create( |
| 642 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details, | 615 scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details, |
| 643 scope.GetExceptionState()); | 616 scope.GetExceptionState()); |
| 644 | 617 |
| 645 EXPECT_EQ("my_payment_id", request->id()); | 618 EXPECT_EQ("my_payment_id", request->id()); |
| 646 } | 619 } |
| 647 | 620 |
| 648 } // namespace | 621 } // namespace |
| 649 } // namespace blink | 622 } // namespace blink |
| OLD | NEW |