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

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

Issue 2030193002: Add 'total' field to 'PaymentDetails'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, address comments, and add more tests Created 4 years, 6 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/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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 TEST_F(PaymentRequestTest, SupportedMethodListRequired) 65 TEST_F(PaymentRequestTest, SupportedMethodListRequired)
66 { 66 {
67 PaymentRequest::create(getScriptState(), Vector<String>(), buildPaymentDetai lsForTest(), getExceptionState()); 67 PaymentRequest::create(getScriptState(), Vector<String>(), buildPaymentDetai lsForTest(), getExceptionState());
68 68
69 EXPECT_TRUE(getExceptionState().hadException()); 69 EXPECT_TRUE(getExceptionState().hadException());
70 EXPECT_EQ(V8TypeError, getExceptionState().code()); 70 EXPECT_EQ(V8TypeError, getExceptionState().code());
71 } 71 }
72 72
73 TEST_F(PaymentRequestTest, ItemListRequired) 73 TEST_F(PaymentRequestTest, TotalRequired)
74 { 74 {
75 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe tails(), getExceptionState()); 75 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe tails(), getExceptionState());
76 76
77 EXPECT_TRUE(getExceptionState().hadException()); 77 EXPECT_TRUE(getExceptionState().hadException());
78 EXPECT_EQ(V8TypeError, getExceptionState().code()); 78 EXPECT_EQ(V8TypeError, getExceptionState().code());
79 } 79 }
80 80
81 TEST_F(PaymentRequestTest, ItemListIsNotEmpty)
82 {
83 PaymentDetails details;
84 details.setDisplayItems(HeapVector<PaymentItem>());
85
86 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState());
87
88 EXPECT_TRUE(getExceptionState().hadException());
89 EXPECT_EQ(V8TypeError, getExceptionState().code());
90 }
91
92 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired)
93 {
94 PaymentDetails details;
95 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest()));
96
97 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState());
98
99 EXPECT_TRUE(getExceptionState().hadException());
100 EXPECT_EQ(V8TypeError, getExceptionState().code());
101 }
102
103 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) 81 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable)
104 { 82 {
105 PaymentDetails details; 83 PaymentDetails details;
106 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() )); 84 details.setTotal(buildPaymentItemForTest());
107 PaymentOptions options; 85 PaymentOptions options;
108 options.setRequestShipping(true); 86 options.setRequestShipping(true);
109 87
110 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 88 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
111 89
112 EXPECT_TRUE(request->shippingOption().isNull()); 90 EXPECT_TRUE(request->shippingOption().isNull());
113 } 91 }
114 92
115 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) 93 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable)
116 { 94 {
117 PaymentDetails details; 95 PaymentDetails details;
118 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() )); 96 details.setTotal(buildPaymentItemForTest());
119 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest())); 97 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest()));
120 PaymentOptions options; 98 PaymentOptions options;
121 options.setRequestShipping(true); 99 options.setRequestShipping(true);
122 100
123 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());
124 102
125 EXPECT_TRUE(request->shippingOption().isNull()); 103 EXPECT_TRUE(request->shippingOption().isNull());
126 } 104 }
127 105
128 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques ted) 106 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques ted)
129 { 107 {
130 PaymentDetails details; 108 PaymentDetails details;
131 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() )); 109 details.setTotal(buildPaymentItemForTest());
132 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); 110 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard")));
133 PaymentOptions options; 111 PaymentOptions options;
134 options.setRequestShipping(true); 112 options.setRequestShipping(true);
135 113
136 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 114 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
137 115
138 EXPECT_EQ("standard", request->shippingOption()); 116 EXPECT_EQ("standard", request->shippingOption());
139 } 117 }
140 118
141 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) 119 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault)
142 { 120 {
143 PaymentDetails details; 121 PaymentDetails details;
144 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() )); 122 details.setTotal(buildPaymentItemForTest());
145 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); 123 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard")));
146 124
147 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState()); 125 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState());
148 126
149 EXPECT_TRUE(request->shippingOption().isNull()); 127 EXPECT_TRUE(request->shippingOption().isNull());
150 } 128 }
151 129
152 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo tRequested) 130 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo tRequested)
153 { 131 {
154 PaymentDetails details; 132 PaymentDetails details;
155 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() )); 133 details.setTotal(buildPaymentItemForTest());
156 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest())); 134 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest()));
157 PaymentOptions options; 135 PaymentOptions options;
158 options.setRequestShipping(false); 136 options.setRequestShipping(false);
159 137
160 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 138 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
161 139
162 EXPECT_TRUE(request->shippingOption().isNull()); 140 EXPECT_TRUE(request->shippingOption().isNull());
163 } 141 }
164 142
165 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) 143 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow)
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState())); 384 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
407 385
408 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), "{}", getExceptionState()))); 386 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), "{}", getExceptionState())));
409 EXPECT_FALSE(getExceptionState().hadException()); 387 EXPECT_FALSE(getExceptionState().hadException());
410 } 388 }
411 389
412 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp ingOptions) 390 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp ingOptions)
413 { 391 {
414 ScriptState::Scope scope(getScriptState()); 392 ScriptState::Scope scope(getScriptState());
415 PaymentDetails details; 393 PaymentDetails details;
416 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() )); 394 details.setTotal(buildPaymentItemForTest());
417 PaymentOptions options; 395 PaymentOptions options;
418 options.setRequestShipping(true); 396 options.setRequestShipping(true);
419 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 397 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
420 EXPECT_FALSE(getExceptionState().hadException()); 398 EXPECT_FALSE(getExceptionState().hadException());
421 EXPECT_TRUE(request->shippingOption().isNull()); 399 EXPECT_TRUE(request->shippingOption().isNull());
422 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState())); 400 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState()));
423 String detailWithShippingOptions = "{\"displayItems\": [{\"id\": \"total\", \"label\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] ," 401 String detailWithShippingOptions = "{\"total\": {\"label\": \"Total\", \"amo unt\": {\"currency\": \"USD\", \"value\": \"5.00\"}},"
424 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }"; 402 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }";
425 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detailWithShippingOptions, getExceptionState()))); 403 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detailWithShippingOptions, getExceptionState())));
426 EXPECT_FALSE(getExceptionState().hadException()); 404 EXPECT_FALSE(getExceptionState().hadException());
427 EXPECT_EQ("standardShippingOption", request->shippingOption()); 405 EXPECT_EQ("standardShippingOption", request->shippingOption());
428 String detailWithoutShippingOptions = "{\"displayItems\": [{\"id\": \"total\ ", \"label\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\" }}]}"; 406 String detailWithoutShippingOptions = "{\"total\": {\"label\": \"Total\", \" amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}}";
429 407
430 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); 408 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detailWithoutShippingOptions, getExceptionState())));
431 409
432 EXPECT_FALSE(getExceptionState().hadException()); 410 EXPECT_FALSE(getExceptionState().hadException());
433 EXPECT_TRUE(request->shippingOption().isNull()); 411 EXPECT_TRUE(request->shippingOption().isNull());
434 } 412 }
435 413
436 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple ShippingOptions) 414 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple ShippingOptions)
437 { 415 {
438 ScriptState::Scope scope(getScriptState()); 416 ScriptState::Scope scope(getScriptState());
439 PaymentOptions options; 417 PaymentOptions options;
440 options.setRequestShipping(true); 418 options.setRequestShipping(true);
441 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); 419 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
442 EXPECT_FALSE(getExceptionState().hadException()); 420 EXPECT_FALSE(getExceptionState().hadException());
443 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState())); 421 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState()));
444 String detail = "{\"displayItems\": [{\"id\": \"total\", \"label\": \"Total\ ", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," 422 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}},"
445 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," 423 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}},"
446 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}}]}"; 424 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}}]}";
447 425
448 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); 426 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState())));
449 EXPECT_FALSE(getExceptionState().hadException()); 427 EXPECT_FALSE(getExceptionState().hadException());
450 428
451 EXPECT_TRUE(request->shippingOption().isNull()); 429 EXPECT_TRUE(request->shippingOption().isNull());
452 } 430 }
453 431
454 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate) 432 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate)
455 { 433 {
456 ScriptState::Scope scope(getScriptState()); 434 ScriptState::Scope scope(getScriptState());
457 PaymentOptions options; 435 PaymentOptions options;
458 options.setRequestShipping(true); 436 options.setRequestShipping(true);
459 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); 437 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
460 EXPECT_FALSE(getExceptionState().hadException()); 438 EXPECT_FALSE(getExceptionState().hadException());
461 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState())); 439 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState()));
462 String detail = "{\"displayItems\": [{\"id\": \"total\", \"label\": \"Total\ ", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," 440 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\ ": \"USD\", \"value\": \"5.00\"}},"
463 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }"; 441 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }";
464 442
465 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); 443 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState())));
466 EXPECT_FALSE(getExceptionState().hadException()); 444 EXPECT_FALSE(getExceptionState().hadException());
467 445
468 EXPECT_EQ("standardShippingOption", request->shippingOption()); 446 EXPECT_EQ("standardShippingOption", request->shippingOption());
469 } 447 }
470 448
471 } // namespace 449 } // namespace
472 } // namespace blink 450 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698