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

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

Issue 2056803002: Rename remaining types so that all begin Payment* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename remaining types so that all begin Payment* 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 "bindings/modules/v8/V8PaymentResponse.h" 10 #include "bindings/modules/v8/V8PaymentResponse.h"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/testing/DummyPageHolder.h" 12 #include "core/testing/DummyPageHolder.h"
13 #include "modules/payments/CurrencyAmount.h"
14 #include "modules/payments/PaymentAddress.h" 13 #include "modules/payments/PaymentAddress.h"
14 #include "modules/payments/PaymentCurrencyAmount.h"
15 #include "modules/payments/PaymentItem.h" 15 #include "modules/payments/PaymentItem.h"
16 #include "modules/payments/PaymentShippingOption.h"
16 #include "modules/payments/PaymentTestHelper.h" 17 #include "modules/payments/PaymentTestHelper.h"
17 #include "modules/payments/ShippingOption.h"
18 #include "platform/heap/HeapAllocator.h" 18 #include "platform/heap/HeapAllocator.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "wtf/OwnPtr.h" 21 #include "wtf/OwnPtr.h"
22 #include <utility> 22 #include <utility>
23 23
24 namespace blink { 24 namespace blink {
25 namespace { 25 namespace {
26 26
27 class PaymentRequestTest : public testing::Test { 27 class PaymentRequestTest : public testing::Test {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState()); 90 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState());
91 91
92 EXPECT_TRUE(request->shippingOption().isNull()); 92 EXPECT_TRUE(request->shippingOption().isNull());
93 } 93 }
94 94
95 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) 95 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable)
96 { 96 {
97 PaymentDetails details; 97 PaymentDetails details;
98 details.setTotal(buildPaymentItemForTest()); 98 details.setTotal(buildPaymentItemForTest());
99 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest())); 99 details.setShippingOptions(HeapVector<PaymentShippingOption>(2, buildShippin gOptionForTest()));
100 PaymentOptions options; 100 PaymentOptions options;
101 options.setRequestShipping(true); 101 options.setRequestShipping(true);
102 102
103 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState()); 103 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState());
104 104
105 EXPECT_TRUE(request->shippingOption().isNull()); 105 EXPECT_TRUE(request->shippingOption().isNull());
106 } 106 }
107 107
108 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) 108 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault)
109 { 109 {
110 PaymentDetails details; 110 PaymentDetails details;
111 details.setTotal(buildPaymentItemForTest()); 111 details.setTotal(buildPaymentItemForTest());
112 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); 112 details.setShippingOptions(HeapVector<PaymentShippingOption>(1, buildShippin gOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard")));
113 113
114 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, getExceptionState()); 114 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, getExceptionState());
115 115
116 EXPECT_TRUE(request->shippingOption().isNull()); 116 EXPECT_TRUE(request->shippingOption().isNull());
117 } 117 }
118 118
119 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo tRequested) 119 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo tRequested)
120 { 120 {
121 PaymentDetails details; 121 PaymentDetails details;
122 details.setTotal(buildPaymentItemForTest()); 122 details.setTotal(buildPaymentItemForTest());
123 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest())); 123 details.setShippingOptions(HeapVector<PaymentShippingOption>(1, buildShippin gOptionForTest()));
124 PaymentOptions options; 124 PaymentOptions options;
125 options.setRequestShipping(false); 125 options.setRequestShipping(false);
126 126
127 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState()); 127 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState());
128 128
129 EXPECT_TRUE(request->shippingOption().isNull()); 129 EXPECT_TRUE(request->shippingOption().isNull());
130 } 130 }
131 131
132 TEST_F(PaymentRequestTest, DontSelectSingleUnselectedShippingOptionWhenShippingR equested) 132 TEST_F(PaymentRequestTest, DontSelectSingleUnselectedShippingOptionWhenShippingR equested)
133 { 133 {
134 PaymentDetails details; 134 PaymentDetails details;
135 details.setTotal(buildPaymentItemForTest()); 135 details.setTotal(buildPaymentItemForTest());
136 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest())); 136 details.setShippingOptions(HeapVector<PaymentShippingOption>(1, buildShippin gOptionForTest()));
137 PaymentOptions options; 137 PaymentOptions options;
138 options.setRequestShipping(true); 138 options.setRequestShipping(true);
139 139
140 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState()); 140 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState());
141 141
142 EXPECT_TRUE(request->shippingOption().isNull()); 142 EXPECT_TRUE(request->shippingOption().isNull());
143 } 143 }
144 144
145 TEST_F(PaymentRequestTest, SelectSingleSelectedShippingOptionWhenShippingRequest ed) 145 TEST_F(PaymentRequestTest, SelectSingleSelectedShippingOptionWhenShippingRequest ed)
146 { 146 {
147 PaymentDetails details; 147 PaymentDetails details;
148 details.setTotal(buildPaymentItemForTest()); 148 details.setTotal(buildPaymentItemForTest());
149 HeapVector<ShippingOption> shippingOptions(1, buildShippingOptionForTest(Pay mentTestDataId, PaymentTestOverwriteValue, "standard")); 149 HeapVector<PaymentShippingOption> shippingOptions(1, buildShippingOptionForT est(PaymentTestDataId, PaymentTestOverwriteValue, "standard"));
150 shippingOptions[0].setSelected(true); 150 shippingOptions[0].setSelected(true);
151 details.setShippingOptions(shippingOptions); 151 details.setShippingOptions(shippingOptions);
152 PaymentOptions options; 152 PaymentOptions options;
153 options.setRequestShipping(true); 153 options.setRequestShipping(true);
154 154
155 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState()); 155 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState());
156 156
157 EXPECT_EQ("standard", request->shippingOption()); 157 EXPECT_EQ("standard", request->shippingOption());
158 } 158 }
159 159
160 TEST_F(PaymentRequestTest, SelectOnlySelectedShippingOptionWhenShippingRequested ) 160 TEST_F(PaymentRequestTest, SelectOnlySelectedShippingOptionWhenShippingRequested )
161 { 161 {
162 PaymentDetails details; 162 PaymentDetails details;
163 details.setTotal(buildPaymentItemForTest()); 163 details.setTotal(buildPaymentItemForTest());
164 HeapVector<ShippingOption> shippingOptions(2); 164 HeapVector<PaymentShippingOption> shippingOptions(2);
165 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe stOverwriteValue, "standard"); 165 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe stOverwriteValue, "standard");
166 shippingOptions[0].setSelected(true); 166 shippingOptions[0].setSelected(true);
167 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe stOverwriteValue, "express"); 167 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe stOverwriteValue, "express");
168 details.setShippingOptions(shippingOptions); 168 details.setShippingOptions(shippingOptions);
169 PaymentOptions options; 169 PaymentOptions options;
170 options.setRequestShipping(true); 170 options.setRequestShipping(true);
171 171
172 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState()); 172 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState());
173 173
174 EXPECT_EQ("standard", request->shippingOption()); 174 EXPECT_EQ("standard", request->shippingOption());
175 } 175 }
176 176
177 TEST_F(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested ) 177 TEST_F(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested )
178 { 178 {
179 PaymentDetails details; 179 PaymentDetails details;
180 details.setTotal(buildPaymentItemForTest()); 180 details.setTotal(buildPaymentItemForTest());
181 HeapVector<ShippingOption> shippingOptions(2); 181 HeapVector<PaymentShippingOption> shippingOptions(2);
182 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe stOverwriteValue, "standard"); 182 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe stOverwriteValue, "standard");
183 shippingOptions[0].setSelected(true); 183 shippingOptions[0].setSelected(true);
184 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe stOverwriteValue, "express"); 184 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe stOverwriteValue, "express");
185 shippingOptions[1].setSelected(true); 185 shippingOptions[1].setSelected(true);
186 details.setShippingOptions(shippingOptions); 186 details.setShippingOptions(shippingOptions);
187 PaymentOptions options; 187 PaymentOptions options;
188 options.setRequestShipping(true); 188 options.setRequestShipping(true);
189 189
190 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState()); 190 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), details, options, getExceptionState());
191 191
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; 553 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}";
554 554
555 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); 555 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState())));
556 EXPECT_FALSE(getExceptionState().hadException()); 556 EXPECT_FALSE(getExceptionState().hadException());
557 557
558 EXPECT_EQ("fast", request->shippingOption()); 558 EXPECT_EQ("fast", request->shippingOption());
559 } 559 }
560 560
561 } // namespace 561 } // namespace
562 } // namespace blink 562 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698