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

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

Issue 2028603004: Rename 'items' into 'displayItems' in PaymentDetails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) 81 TEST_F(PaymentRequestTest, ItemListIsNotEmpty)
82 { 82 {
83 PaymentDetails details; 83 PaymentDetails details;
84 details.setItems(HeapVector<PaymentItem>()); 84 details.setDisplayItems(HeapVector<PaymentItem>());
85 85
86 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState()); 86 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState());
87 87
88 EXPECT_TRUE(getExceptionState().hadException()); 88 EXPECT_TRUE(getExceptionState().hadException());
89 EXPECT_EQ(V8TypeError, getExceptionState().code()); 89 EXPECT_EQ(V8TypeError, getExceptionState().code());
90 } 90 }
91 91
92 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired) 92 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired)
93 { 93 {
94 PaymentDetails details; 94 PaymentDetails details;
95 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest())); 95 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest()));
96 96
97 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState()); 97 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState());
98 98
99 EXPECT_TRUE(getExceptionState().hadException()); 99 EXPECT_TRUE(getExceptionState().hadException());
100 EXPECT_EQ(V8TypeError, getExceptionState().code()); 100 EXPECT_EQ(V8TypeError, getExceptionState().code());
101 } 101 }
102 102
103 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) 103 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable)
104 { 104 {
105 PaymentDetails details; 105 PaymentDetails details;
106 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); 106 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() ));
107 PaymentOptions options; 107 PaymentOptions options;
108 options.setRequestShipping(true); 108 options.setRequestShipping(true);
109 109
110 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 110 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
111 111
112 EXPECT_TRUE(request->shippingOption().isNull()); 112 EXPECT_TRUE(request->shippingOption().isNull());
113 } 113 }
114 114
115 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) 115 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable)
116 { 116 {
117 PaymentDetails details; 117 PaymentDetails details;
118 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); 118 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() ));
119 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest())); 119 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest()));
120 PaymentOptions options; 120 PaymentOptions options;
121 options.setRequestShipping(true); 121 options.setRequestShipping(true);
122 122
123 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 123 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
124 124
125 EXPECT_TRUE(request->shippingOption().isNull()); 125 EXPECT_TRUE(request->shippingOption().isNull());
126 } 126 }
127 127
128 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques ted) 128 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques ted)
129 { 129 {
130 PaymentDetails details; 130 PaymentDetails details;
131 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); 131 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() ));
132 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); 132 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard")));
133 PaymentOptions options; 133 PaymentOptions options;
134 options.setRequestShipping(true); 134 options.setRequestShipping(true);
135 135
136 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 136 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
137 137
138 EXPECT_EQ("standard", request->shippingOption()); 138 EXPECT_EQ("standard", request->shippingOption());
139 } 139 }
140 140
141 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) 141 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault)
142 { 142 {
143 PaymentDetails details; 143 PaymentDetails details;
144 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); 144 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() ));
145 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); 145 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard")));
146 146
147 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState()); 147 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState());
148 148
149 EXPECT_TRUE(request->shippingOption().isNull()); 149 EXPECT_TRUE(request->shippingOption().isNull());
150 } 150 }
151 151
152 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo tRequested) 152 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo tRequested)
153 { 153 {
154 PaymentDetails details; 154 PaymentDetails details;
155 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); 155 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() ));
156 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest())); 156 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest()));
157 PaymentOptions options; 157 PaymentOptions options;
158 options.setRequestShipping(false); 158 options.setRequestShipping(false);
159 159
160 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 160 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
161 161
162 EXPECT_TRUE(request->shippingOption().isNull()); 162 EXPECT_TRUE(request->shippingOption().isNull());
163 } 163 }
164 164
165 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) 165 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())); 406 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
407 407
408 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), "{}", getExceptionState()))); 408 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), "{}", getExceptionState())));
409 EXPECT_FALSE(getExceptionState().hadException()); 409 EXPECT_FALSE(getExceptionState().hadException());
410 } 410 }
411 411
412 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp ingOptions) 412 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp ingOptions)
413 { 413 {
414 ScriptState::Scope scope(getScriptState()); 414 ScriptState::Scope scope(getScriptState());
415 PaymentDetails details; 415 PaymentDetails details;
416 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); 416 details.setDisplayItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest() ));
417 PaymentOptions options; 417 PaymentOptions options;
418 options.setRequestShipping(true); 418 options.setRequestShipping(true);
419 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState()); 419 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, options, getExceptionState());
420 EXPECT_FALSE(getExceptionState().hadException()); 420 EXPECT_FALSE(getExceptionState().hadException());
421 EXPECT_TRUE(request->shippingOption().isNull()); 421 EXPECT_TRUE(request->shippingOption().isNull());
422 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState())); 422 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState()));
423 String detailWithShippingOptions = "{\"items\": [{\"id\": \"total\", \"label \": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," 423 String detailWithShippingOptions = "{\"displayItems\": [{\"id\": \"total\", \"label\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] ,"
424 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }"; 424 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }";
425 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detailWithShippingOptions, getExceptionState()))); 425 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detailWithShippingOptions, getExceptionState())));
426 EXPECT_FALSE(getExceptionState().hadException()); 426 EXPECT_FALSE(getExceptionState().hadException());
427 EXPECT_EQ("standardShippingOption", request->shippingOption()); 427 EXPECT_EQ("standardShippingOption", request->shippingOption());
428 String detailWithoutShippingOptions = "{\"items\": [{\"id\": \"total\", \"la bel\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]}"; 428 String detailWithoutShippingOptions = "{\"displayItems\": [{\"id\": \"total\ ", \"label\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\" }}]}";
429 429
430 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); 430 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detailWithoutShippingOptions, getExceptionState())));
431 431
432 EXPECT_FALSE(getExceptionState().hadException()); 432 EXPECT_FALSE(getExceptionState().hadException());
433 EXPECT_TRUE(request->shippingOption().isNull()); 433 EXPECT_TRUE(request->shippingOption().isNull());
434 } 434 }
435 435
436 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple ShippingOptions) 436 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple ShippingOptions)
437 { 437 {
438 ScriptState::Scope scope(getScriptState()); 438 ScriptState::Scope scope(getScriptState());
439 PaymentOptions options; 439 PaymentOptions options;
440 options.setRequestShipping(true); 440 options.setRequestShipping(true);
441 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); 441 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
442 EXPECT_FALSE(getExceptionState().hadException()); 442 EXPECT_FALSE(getExceptionState().hadException());
443 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState())); 443 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState()));
444 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," 444 String detail = "{\"displayItems\": [{\"id\": \"total\", \"label\": \"Total\ ", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}],"
445 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}}," 445 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\ ": {\"currency\": \"USD\", \"value\": \"5.00\"}},"
446 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}}]}"; 446 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}}]}";
447 447
448 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); 448 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState())));
449 EXPECT_FALSE(getExceptionState().hadException()); 449 EXPECT_FALSE(getExceptionState().hadException());
450 450
451 EXPECT_TRUE(request->shippingOption().isNull()); 451 EXPECT_TRUE(request->shippingOption().isNull());
452 } 452 }
453 453
454 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate) 454 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate)
455 { 455 {
456 ScriptState::Scope scope(getScriptState()); 456 ScriptState::Scope scope(getScriptState());
457 PaymentOptions options; 457 PaymentOptions options;
458 options.setRequestShipping(true); 458 options.setRequestShipping(true);
459 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); 459 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
460 EXPECT_FALSE(getExceptionState().hadException()); 460 EXPECT_FALSE(getExceptionState().hadException());
461 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState())); 461 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectNoCall(getScriptState()));
462 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," 462 String detail = "{\"displayItems\": [{\"id\": \"total\", \"label\": \"Total\ ", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}],"
463 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }"; 463 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }";
464 464
465 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); 465 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState())));
466 EXPECT_FALSE(getExceptionState().hadException()); 466 EXPECT_FALSE(getExceptionState().hadException());
467 467
468 EXPECT_EQ("standardShippingOption", request->shippingOption()); 468 EXPECT_EQ("standardShippingOption", request->shippingOption());
469 } 469 }
470 470
471 } // namespace 471 } // namespace
472 } // namespace blink 472 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698