Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp

Issue 2355463002: [PaymentReqeust] Add error message in PaymentDetails. (in blink side) (Closed)
Patch Set: rebase from origin Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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("This is an error message."), scope.getEx ceptionState());
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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}}," 468 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}},"
460 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," 469 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}},"
461 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; 470 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}";
462 471
463 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); 472 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState())));
464 EXPECT_FALSE(scope.getExceptionState().hadException()); 473 EXPECT_FALSE(scope.getExceptionState().hadException());
465 474
466 EXPECT_EQ("fast", request->shippingOption()); 475 EXPECT_EQ("fast", request->shippingOption());
467 } 476 }
468 477
478 TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate)
479 {
480 V8TestingScope scope;
481 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
482 makePaymentRequestOriginSecure(scope.document());
483 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
484 EXPECT_FALSE(scope.getExceptionState().hadException());
485
486 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tNoCall());
487 String detailWithErrorMsg = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}},"
488 "\"error\": \"This is an error message.\"}";
489
490 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detailWithErrorMsg, scope.getExceptionState ())));
491 EXPECT_FALSE(scope.getExceptionState().hadException());
492 }
493
469 } // namespace 494 } // namespace
470 } // namespace blink 495 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698