Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 TEST(PaymentRequestTest, NoExceptionWithValidData) | 29 TEST(PaymentRequestTest, NoExceptionWithValidData) |
| 30 { | 30 { |
| 31 V8TestingScope scope; | 31 V8TestingScope scope; |
| 32 makePaymentRequestOriginSecure(scope.document()); | 32 makePaymentRequestOriginSecure(scope.document()); |
| 33 PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest (), buildPaymentDetailsForTest(), scope.getExceptionState()); | 33 PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest (), buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 34 | 34 |
| 35 EXPECT_FALSE(scope.getExceptionState().hadException()); | 35 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 | |
| 39 TEST(PaymentRequestTest, SupportedMethodListRequired) | 38 TEST(PaymentRequestTest, SupportedMethodListRequired) |
| 40 { | 39 { |
| 41 V8TestingScope scope; | 40 V8TestingScope scope; |
| 42 makePaymentRequestOriginSecure(scope.document()); | 41 makePaymentRequestOriginSecure(scope.document()); |
| 43 PaymentRequest::create(scope.getScriptState(), HeapVector<PaymentMethodData> (), buildPaymentDetailsForTest(), scope.getExceptionState()); | 42 PaymentRequest::create(scope.getScriptState(), HeapVector<PaymentMethodData> (), buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 44 | 43 |
| 45 EXPECT_TRUE(scope.getExceptionState().hadException()); | 44 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 46 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 45 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
| 47 } | 46 } |
| 48 | 47 |
| 49 TEST(PaymentRequestTest, TotalRequired) | 48 TEST(PaymentRequestTest, TotalRequired) |
| 50 { | 49 { |
| 51 V8TestingScope scope; | 50 V8TestingScope scope; |
| 52 makePaymentRequestOriginSecure(scope.document()); | 51 makePaymentRequestOriginSecure(scope.document()); |
| 53 PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest (), PaymentDetails(), scope.getExceptionState()); | 52 PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest (), PaymentDetails(), scope.getExceptionState()); |
| 54 | 53 |
| 55 EXPECT_TRUE(scope.getExceptionState().hadException()); | 54 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 56 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 55 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
| 57 } | 56 } |
| 58 | 57 |
| 58 TEST(PaymentRequestTest, ErrorMsgMustBeEmptyInConstrctor) | |
| 59 { | |
| 60 V8TestingScope scope; | |
| 61 makePaymentRequestOriginSecure(scope.document()); | |
| 62 PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest (), buildPaymentDetailsErrorMsgForTest("Error message is not empty."), scope.get ExceptionState()); | |
|
please use gerrit instead
2016/09/20 15:40:50
"This is an error message."
Hwanseung Lee
2016/09/20 16:01:09
Done.
| |
| 63 | |
| 64 EXPECT_TRUE(scope.getExceptionState().hadException()); | |
| 65 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | |
| 66 } | |
| 67 | |
| 59 TEST(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) | 68 TEST(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) |
| 60 { | 69 { |
| 61 V8TestingScope scope; | 70 V8TestingScope scope; |
| 62 makePaymentRequestOriginSecure(scope.document()); | 71 makePaymentRequestOriginSecure(scope.document()); |
| 63 PaymentDetails details; | 72 PaymentDetails details; |
| 64 details.setTotal(buildPaymentItemForTest()); | 73 details.setTotal(buildPaymentItemForTest()); |
| 65 PaymentOptions options; | 74 PaymentOptions options; |
| 66 options.setRequestShipping(true); | 75 options.setRequestShipping(true); |
| 67 | 76 |
| 68 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); | 77 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), details, options, scope.getExceptionState()); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}}," | 395 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}}," |
| 387 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 396 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 388 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 397 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 389 | 398 |
| 390 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); | 399 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); |
| 391 EXPECT_FALSE(scope.getExceptionState().hadException()); | 400 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 392 | 401 |
| 393 EXPECT_EQ("fast", request->shippingOption()); | 402 EXPECT_EQ("fast", request->shippingOption()); |
| 394 } | 403 } |
| 395 | 404 |
| 405 TEST(PaymentRequestTest, havingErrorMsgFromPaymentDetailsUpdate) | |
|
please use gerrit instead
2016/09/20 15:40:50
Better name for the test is "NoExceptionWithErrorM
Hwanseung Lee
2016/09/20 16:01:09
Done.
| |
| 406 { | |
| 407 V8TestingScope scope; | |
| 408 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | |
| 409 makePaymentRequestOriginSecure(scope.document()); | |
| 410 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); | |
| 411 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 412 | |
| 413 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); | |
| 414 String detailWithErrorMsg = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | |
| 415 "\"error\": \"havingErrorMsg\"}"; | |
| 416 | |
| 417 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), "{}", scope.getExceptionState()))); | |
|
please use gerrit instead
2016/09/20 15:40:50
Replace "{}" with detailWithErrorMsg.
Hwanseung Lee
2016/09/20 16:01:09
Done.
| |
| 418 EXPECT_FALSE(scope.getExceptionState().hadException()); | |
| 419 } | |
| 420 | |
| 396 } // namespace | 421 } // namespace |
| 397 } // namespace blink | 422 } // namespace blink |
| OLD | NEW |