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/V8BindingForTesting.h" | 7 #include "bindings/core/v8/V8BindingForTesting.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
10 #include "modules/payments/PaymentTestHelper.h" | 10 #include "modules/payments/PaymentTestHelper.h" |
11 #include "platform/heap/HeapAllocator.h" | 11 #include "platform/heap/HeapAllocator.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 namespace { | 15 namespace { |
16 | 16 |
17 TEST(PaymentRequestTest, SecureContextRequired) { | 17 TEST(PaymentRequestTest, SecureContextRequired) { |
18 V8TestingScope scope; | 18 V8TestingScope scope; |
19 scope.document().setSecurityOrigin( | 19 scope.document().setSecurityOrigin( |
20 SecurityOrigin::create(KURL(KURL(), "http://www.example.com/"))); | 20 SecurityOrigin::create(KURL(KURL(), "http://www.example.com/"))); |
21 | 21 |
22 PaymentRequest::create( | 22 PaymentRequest::create( |
23 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 23 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
24 buildPaymentDetailsForTest(), scope.getExceptionState()); | 24 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
25 | 25 |
26 EXPECT_TRUE(scope.getExceptionState().hadException()); | 26 EXPECT_TRUE(scope.getExceptionState().hadException()); |
27 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); | 27 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); |
28 } | 28 } |
29 | 29 |
30 TEST(PaymentRequestTest, NoExceptionWithValidData) { | 30 TEST(PaymentRequestTest, NoExceptionWithValidData) { |
31 V8TestingScope scope; | 31 V8TestingScope scope; |
32 makePaymentRequestOriginSecure(scope.document()); | 32 makePaymentRequestOriginSecure(scope.document()); |
33 PaymentRequest::create( | 33 PaymentRequest::create( |
34 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 34 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
35 buildPaymentDetailsForTest(), scope.getExceptionState()); | 35 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
36 | 36 |
37 EXPECT_FALSE(scope.getExceptionState().hadException()); | 37 EXPECT_FALSE(scope.getExceptionState().hadException()); |
38 } | 38 } |
39 | 39 |
40 TEST(PaymentRequestTest, SupportedMethodListRequired) { | 40 TEST(PaymentRequestTest, SupportedMethodListRequired) { |
41 V8TestingScope scope; | 41 V8TestingScope scope; |
42 makePaymentRequestOriginSecure(scope.document()); | 42 makePaymentRequestOriginSecure(scope.document()); |
43 PaymentRequest::create( | 43 PaymentRequest::create( |
44 scope.getExecutionContext(), HeapVector<PaymentMethodData>(), | 44 scope.getExecutionContext(), HeapVector<PaymentMethodData>(), |
45 buildPaymentDetailsForTest(), scope.getExceptionState()); | 45 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
46 | 46 |
47 EXPECT_TRUE(scope.getExceptionState().hadException()); | 47 EXPECT_TRUE(scope.getExceptionState().hadException()); |
48 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 48 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
49 } | 49 } |
50 | 50 |
51 TEST(PaymentRequestTest, TotalRequired) { | 51 TEST(PaymentRequestTest, TotalRequired) { |
52 V8TestingScope scope; | 52 V8TestingScope scope; |
53 makePaymentRequestOriginSecure(scope.document()); | 53 makePaymentRequestOriginSecure(scope.document()); |
54 PaymentRequest::create(scope.getExecutionContext(), | 54 PaymentRequest::create(scope.getExecutionContext(), |
55 buildPaymentMethodDataForTest(), PaymentDetails(), | 55 buildPaymentMethodDataForTest(), PaymentDetailsInit(), |
56 scope.getExceptionState()); | 56 scope.getExceptionState()); |
57 | 57 |
58 EXPECT_TRUE(scope.getExceptionState().hadException()); | 58 EXPECT_TRUE(scope.getExceptionState().hadException()); |
59 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 59 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
60 } | 60 } |
61 | 61 |
62 TEST(PaymentRequestTest, ErrorMsgMustBeEmptyInConstrctor) { | |
63 V8TestingScope scope; | |
64 makePaymentRequestOriginSecure(scope.document()); | |
65 PaymentRequest::create( | |
66 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | |
67 buildPaymentDetailsErrorMsgForTest("This is an error message."), | |
68 scope.getExceptionState()); | |
69 | |
70 EXPECT_TRUE(scope.getExceptionState().hadException()); | |
71 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | |
72 } | |
73 | |
74 TEST(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) { | 62 TEST(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) { |
75 V8TestingScope scope; | 63 V8TestingScope scope; |
76 makePaymentRequestOriginSecure(scope.document()); | 64 makePaymentRequestOriginSecure(scope.document()); |
77 PaymentDetails details; | 65 PaymentDetailsInit details; |
78 details.setTotal(buildPaymentItemForTest()); | 66 details.setTotal(buildPaymentItemForTest()); |
79 PaymentOptions options; | 67 PaymentOptions options; |
80 options.setRequestShipping(true); | 68 options.setRequestShipping(true); |
81 | 69 |
82 PaymentRequest* request = PaymentRequest::create( | 70 PaymentRequest* request = PaymentRequest::create( |
83 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 71 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
84 options, scope.getExceptionState()); | 72 options, scope.getExceptionState()); |
85 | 73 |
86 EXPECT_TRUE(request->shippingOption().isNull()); | 74 EXPECT_TRUE(request->shippingOption().isNull()); |
87 } | 75 } |
88 | 76 |
89 TEST(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) { | 77 TEST(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) { |
90 V8TestingScope scope; | 78 V8TestingScope scope; |
91 makePaymentRequestOriginSecure(scope.document()); | 79 makePaymentRequestOriginSecure(scope.document()); |
92 PaymentDetails details; | 80 PaymentDetailsInit details; |
93 details.setTotal(buildPaymentItemForTest()); | 81 details.setTotal(buildPaymentItemForTest()); |
94 details.setShippingOptions( | 82 details.setShippingOptions( |
95 HeapVector<PaymentShippingOption>(2, buildShippingOptionForTest())); | 83 HeapVector<PaymentShippingOption>(2, buildShippingOptionForTest())); |
96 PaymentOptions options; | 84 PaymentOptions options; |
97 options.setRequestShipping(true); | 85 options.setRequestShipping(true); |
98 | 86 |
99 PaymentRequest* request = PaymentRequest::create( | 87 PaymentRequest* request = PaymentRequest::create( |
100 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 88 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
101 options, scope.getExceptionState()); | 89 options, scope.getExceptionState()); |
102 | 90 |
103 EXPECT_TRUE(request->shippingOption().isNull()); | 91 EXPECT_TRUE(request->shippingOption().isNull()); |
104 } | 92 } |
105 | 93 |
106 TEST(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) { | 94 TEST(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) { |
107 V8TestingScope scope; | 95 V8TestingScope scope; |
108 makePaymentRequestOriginSecure(scope.document()); | 96 makePaymentRequestOriginSecure(scope.document()); |
109 PaymentDetails details; | 97 PaymentDetailsInit details; |
110 details.setTotal(buildPaymentItemForTest()); | 98 details.setTotal(buildPaymentItemForTest()); |
111 details.setShippingOptions(HeapVector<PaymentShippingOption>( | 99 details.setShippingOptions(HeapVector<PaymentShippingOption>( |
112 1, | 100 1, |
113 buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, | 101 buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, |
114 "standard"))); | 102 "standard"))); |
115 | 103 |
116 PaymentRequest* request = PaymentRequest::create( | 104 PaymentRequest* request = PaymentRequest::create( |
117 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 105 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
118 scope.getExceptionState()); | 106 scope.getExceptionState()); |
119 | 107 |
120 EXPECT_TRUE(request->shippingOption().isNull()); | 108 EXPECT_TRUE(request->shippingOption().isNull()); |
121 } | 109 } |
122 | 110 |
123 TEST(PaymentRequestTest, | 111 TEST(PaymentRequestTest, |
124 DontSelectSingleAvailableShippingOptionWhenShippingNotRequested) { | 112 DontSelectSingleAvailableShippingOptionWhenShippingNotRequested) { |
125 V8TestingScope scope; | 113 V8TestingScope scope; |
126 makePaymentRequestOriginSecure(scope.document()); | 114 makePaymentRequestOriginSecure(scope.document()); |
127 PaymentDetails details; | 115 PaymentDetailsInit details; |
128 details.setTotal(buildPaymentItemForTest()); | 116 details.setTotal(buildPaymentItemForTest()); |
129 details.setShippingOptions( | 117 details.setShippingOptions( |
130 HeapVector<PaymentShippingOption>(1, buildShippingOptionForTest())); | 118 HeapVector<PaymentShippingOption>(1, buildShippingOptionForTest())); |
131 PaymentOptions options; | 119 PaymentOptions options; |
132 options.setRequestShipping(false); | 120 options.setRequestShipping(false); |
133 | 121 |
134 PaymentRequest* request = PaymentRequest::create( | 122 PaymentRequest* request = PaymentRequest::create( |
135 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 123 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
136 options, scope.getExceptionState()); | 124 options, scope.getExceptionState()); |
137 | 125 |
138 EXPECT_TRUE(request->shippingOption().isNull()); | 126 EXPECT_TRUE(request->shippingOption().isNull()); |
139 } | 127 } |
140 | 128 |
141 TEST(PaymentRequestTest, | 129 TEST(PaymentRequestTest, |
142 DontSelectSingleUnselectedShippingOptionWhenShippingRequested) { | 130 DontSelectSingleUnselectedShippingOptionWhenShippingRequested) { |
143 V8TestingScope scope; | 131 V8TestingScope scope; |
144 makePaymentRequestOriginSecure(scope.document()); | 132 makePaymentRequestOriginSecure(scope.document()); |
145 PaymentDetails details; | 133 PaymentDetailsInit details; |
146 details.setTotal(buildPaymentItemForTest()); | 134 details.setTotal(buildPaymentItemForTest()); |
147 details.setShippingOptions( | 135 details.setShippingOptions( |
148 HeapVector<PaymentShippingOption>(1, buildShippingOptionForTest())); | 136 HeapVector<PaymentShippingOption>(1, buildShippingOptionForTest())); |
149 PaymentOptions options; | 137 PaymentOptions options; |
150 options.setRequestShipping(true); | 138 options.setRequestShipping(true); |
151 | 139 |
152 PaymentRequest* request = PaymentRequest::create( | 140 PaymentRequest* request = PaymentRequest::create( |
153 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 141 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
154 options, scope.getExceptionState()); | 142 options, scope.getExceptionState()); |
155 | 143 |
156 EXPECT_TRUE(request->shippingOption().isNull()); | 144 EXPECT_TRUE(request->shippingOption().isNull()); |
157 } | 145 } |
158 | 146 |
159 TEST(PaymentRequestTest, | 147 TEST(PaymentRequestTest, |
160 SelectSingleSelectedShippingOptionWhenShippingRequested) { | 148 SelectSingleSelectedShippingOptionWhenShippingRequested) { |
161 V8TestingScope scope; | 149 V8TestingScope scope; |
162 makePaymentRequestOriginSecure(scope.document()); | 150 makePaymentRequestOriginSecure(scope.document()); |
163 PaymentDetails details; | 151 PaymentDetailsInit details; |
164 details.setTotal(buildPaymentItemForTest()); | 152 details.setTotal(buildPaymentItemForTest()); |
165 HeapVector<PaymentShippingOption> shippingOptions( | 153 HeapVector<PaymentShippingOption> shippingOptions( |
166 1, | 154 1, |
167 buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, | 155 buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, |
168 "standard")); | 156 "standard")); |
169 shippingOptions[0].setSelected(true); | 157 shippingOptions[0].setSelected(true); |
170 details.setShippingOptions(shippingOptions); | 158 details.setShippingOptions(shippingOptions); |
171 PaymentOptions options; | 159 PaymentOptions options; |
172 options.setRequestShipping(true); | 160 options.setRequestShipping(true); |
173 | 161 |
174 PaymentRequest* request = PaymentRequest::create( | 162 PaymentRequest* request = PaymentRequest::create( |
175 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 163 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
176 options, scope.getExceptionState()); | 164 options, scope.getExceptionState()); |
177 | 165 |
178 EXPECT_EQ("standard", request->shippingOption()); | 166 EXPECT_EQ("standard", request->shippingOption()); |
179 } | 167 } |
180 | 168 |
181 TEST(PaymentRequestTest, | 169 TEST(PaymentRequestTest, |
182 SelectOnlySelectedShippingOptionWhenShippingRequested) { | 170 SelectOnlySelectedShippingOptionWhenShippingRequested) { |
183 V8TestingScope scope; | 171 V8TestingScope scope; |
184 makePaymentRequestOriginSecure(scope.document()); | 172 makePaymentRequestOriginSecure(scope.document()); |
185 PaymentDetails details; | 173 PaymentDetailsInit details; |
186 details.setTotal(buildPaymentItemForTest()); | 174 details.setTotal(buildPaymentItemForTest()); |
187 HeapVector<PaymentShippingOption> shippingOptions(2); | 175 HeapVector<PaymentShippingOption> shippingOptions(2); |
188 shippingOptions[0] = buildShippingOptionForTest( | 176 shippingOptions[0] = buildShippingOptionForTest( |
189 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); | 177 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); |
190 shippingOptions[0].setSelected(true); | 178 shippingOptions[0].setSelected(true); |
191 shippingOptions[1] = buildShippingOptionForTest( | 179 shippingOptions[1] = buildShippingOptionForTest( |
192 PaymentTestDataId, PaymentTestOverwriteValue, "express"); | 180 PaymentTestDataId, PaymentTestOverwriteValue, "express"); |
193 details.setShippingOptions(shippingOptions); | 181 details.setShippingOptions(shippingOptions); |
194 PaymentOptions options; | 182 PaymentOptions options; |
195 options.setRequestShipping(true); | 183 options.setRequestShipping(true); |
196 | 184 |
197 PaymentRequest* request = PaymentRequest::create( | 185 PaymentRequest* request = PaymentRequest::create( |
198 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 186 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
199 options, scope.getExceptionState()); | 187 options, scope.getExceptionState()); |
200 | 188 |
201 EXPECT_EQ("standard", request->shippingOption()); | 189 EXPECT_EQ("standard", request->shippingOption()); |
202 } | 190 } |
203 | 191 |
204 TEST(PaymentRequestTest, | 192 TEST(PaymentRequestTest, |
205 SelectLastSelectedShippingOptionWhenShippingRequested) { | 193 SelectLastSelectedShippingOptionWhenShippingRequested) { |
206 V8TestingScope scope; | 194 V8TestingScope scope; |
207 makePaymentRequestOriginSecure(scope.document()); | 195 makePaymentRequestOriginSecure(scope.document()); |
208 PaymentDetails details; | 196 PaymentDetailsInit details; |
209 details.setTotal(buildPaymentItemForTest()); | 197 details.setTotal(buildPaymentItemForTest()); |
210 HeapVector<PaymentShippingOption> shippingOptions(2); | 198 HeapVector<PaymentShippingOption> shippingOptions(2); |
211 shippingOptions[0] = buildShippingOptionForTest( | 199 shippingOptions[0] = buildShippingOptionForTest( |
212 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); | 200 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); |
213 shippingOptions[0].setSelected(true); | 201 shippingOptions[0].setSelected(true); |
214 shippingOptions[1] = buildShippingOptionForTest( | 202 shippingOptions[1] = buildShippingOptionForTest( |
215 PaymentTestDataId, PaymentTestOverwriteValue, "express"); | 203 PaymentTestDataId, PaymentTestOverwriteValue, "express"); |
216 shippingOptions[1].setSelected(true); | 204 shippingOptions[1].setSelected(true); |
217 details.setShippingOptions(shippingOptions); | 205 details.setShippingOptions(shippingOptions); |
218 PaymentOptions options; | 206 PaymentOptions options; |
219 options.setRequestShipping(true); | 207 options.setRequestShipping(true); |
220 | 208 |
221 PaymentRequest* request = PaymentRequest::create( | 209 PaymentRequest* request = PaymentRequest::create( |
222 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 210 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
223 options, scope.getExceptionState()); | 211 options, scope.getExceptionState()); |
224 | 212 |
225 EXPECT_EQ("express", request->shippingOption()); | 213 EXPECT_EQ("express", request->shippingOption()); |
226 } | 214 } |
227 | 215 |
228 TEST(PaymentRequestTest, NullShippingTypeWhenRequestShippingIsFalse) { | 216 TEST(PaymentRequestTest, NullShippingTypeWhenRequestShippingIsFalse) { |
229 V8TestingScope scope; | 217 V8TestingScope scope; |
230 makePaymentRequestOriginSecure(scope.document()); | 218 makePaymentRequestOriginSecure(scope.document()); |
231 PaymentDetails details; | 219 PaymentDetailsInit details; |
232 details.setTotal(buildPaymentItemForTest()); | 220 details.setTotal(buildPaymentItemForTest()); |
233 PaymentOptions options; | 221 PaymentOptions options; |
234 options.setRequestShipping(false); | 222 options.setRequestShipping(false); |
235 | 223 |
236 PaymentRequest* request = PaymentRequest::create( | 224 PaymentRequest* request = PaymentRequest::create( |
237 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 225 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
238 options, scope.getExceptionState()); | 226 options, scope.getExceptionState()); |
239 | 227 |
240 EXPECT_TRUE(request->shippingType().isNull()); | 228 EXPECT_TRUE(request->shippingType().isNull()); |
241 } | 229 } |
242 | 230 |
243 TEST(PaymentRequestTest, | 231 TEST(PaymentRequestTest, |
244 DefaultShippingTypeWhenRequestShippingIsTrueWithNoSpecificType) { | 232 DefaultShippingTypeWhenRequestShippingIsTrueWithNoSpecificType) { |
245 V8TestingScope scope; | 233 V8TestingScope scope; |
246 makePaymentRequestOriginSecure(scope.document()); | 234 makePaymentRequestOriginSecure(scope.document()); |
247 PaymentDetails details; | 235 PaymentDetailsInit details; |
248 details.setTotal(buildPaymentItemForTest()); | 236 details.setTotal(buildPaymentItemForTest()); |
249 PaymentOptions options; | 237 PaymentOptions options; |
250 options.setRequestShipping(true); | 238 options.setRequestShipping(true); |
251 | 239 |
252 PaymentRequest* request = PaymentRequest::create( | 240 PaymentRequest* request = PaymentRequest::create( |
253 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 241 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
254 options, scope.getExceptionState()); | 242 options, scope.getExceptionState()); |
255 | 243 |
256 EXPECT_EQ("shipping", request->shippingType()); | 244 EXPECT_EQ("shipping", request->shippingType()); |
257 } | 245 } |
258 | 246 |
259 TEST(PaymentRequestTest, DeliveryShippingTypeWhenShippingTypeIsDelivery) { | 247 TEST(PaymentRequestTest, DeliveryShippingTypeWhenShippingTypeIsDelivery) { |
260 V8TestingScope scope; | 248 V8TestingScope scope; |
261 makePaymentRequestOriginSecure(scope.document()); | 249 makePaymentRequestOriginSecure(scope.document()); |
262 PaymentDetails details; | 250 PaymentDetailsInit details; |
263 details.setTotal(buildPaymentItemForTest()); | 251 details.setTotal(buildPaymentItemForTest()); |
264 PaymentOptions options; | 252 PaymentOptions options; |
265 options.setRequestShipping(true); | 253 options.setRequestShipping(true); |
266 options.setShippingType("delivery"); | 254 options.setShippingType("delivery"); |
267 | 255 |
268 PaymentRequest* request = PaymentRequest::create( | 256 PaymentRequest* request = PaymentRequest::create( |
269 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 257 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
270 options, scope.getExceptionState()); | 258 options, scope.getExceptionState()); |
271 | 259 |
272 EXPECT_EQ("delivery", request->shippingType()); | 260 EXPECT_EQ("delivery", request->shippingType()); |
273 } | 261 } |
274 | 262 |
275 TEST(PaymentRequestTest, PickupShippingTypeWhenShippingTypeIsPickup) { | 263 TEST(PaymentRequestTest, PickupShippingTypeWhenShippingTypeIsPickup) { |
276 V8TestingScope scope; | 264 V8TestingScope scope; |
277 makePaymentRequestOriginSecure(scope.document()); | 265 makePaymentRequestOriginSecure(scope.document()); |
278 PaymentDetails details; | 266 PaymentDetailsInit details; |
279 details.setTotal(buildPaymentItemForTest()); | 267 details.setTotal(buildPaymentItemForTest()); |
280 PaymentOptions options; | 268 PaymentOptions options; |
281 options.setRequestShipping(true); | 269 options.setRequestShipping(true); |
282 options.setShippingType("pickup"); | 270 options.setShippingType("pickup"); |
283 | 271 |
284 PaymentRequest* request = PaymentRequest::create( | 272 PaymentRequest* request = PaymentRequest::create( |
285 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 273 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
286 options, scope.getExceptionState()); | 274 options, scope.getExceptionState()); |
287 | 275 |
288 EXPECT_EQ("pickup", request->shippingType()); | 276 EXPECT_EQ("pickup", request->shippingType()); |
289 } | 277 } |
290 | 278 |
291 TEST(PaymentRequestTest, DefaultShippingTypeWhenShippingTypeIsInvalid) { | 279 TEST(PaymentRequestTest, DefaultShippingTypeWhenShippingTypeIsInvalid) { |
292 V8TestingScope scope; | 280 V8TestingScope scope; |
293 makePaymentRequestOriginSecure(scope.document()); | 281 makePaymentRequestOriginSecure(scope.document()); |
294 PaymentDetails details; | 282 PaymentDetailsInit details; |
295 details.setTotal(buildPaymentItemForTest()); | 283 details.setTotal(buildPaymentItemForTest()); |
296 PaymentOptions options; | 284 PaymentOptions options; |
297 options.setRequestShipping(true); | 285 options.setRequestShipping(true); |
298 options.setShippingType("invalid"); | 286 options.setShippingType("invalid"); |
299 | 287 |
300 PaymentRequest* request = PaymentRequest::create( | 288 PaymentRequest* request = PaymentRequest::create( |
301 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 289 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
302 options, scope.getExceptionState()); | 290 options, scope.getExceptionState()); |
303 | 291 |
304 EXPECT_EQ("shipping", request->shippingType()); | 292 EXPECT_EQ("shipping", request->shippingType()); |
305 } | 293 } |
306 | 294 |
307 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) { | 295 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) { |
308 V8TestingScope scope; | 296 V8TestingScope scope; |
309 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 297 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
310 makePaymentRequestOriginSecure(scope.document()); | 298 makePaymentRequestOriginSecure(scope.document()); |
311 PaymentRequest* request = PaymentRequest::create( | 299 PaymentRequest* request = PaymentRequest::create( |
312 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 300 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
313 buildPaymentDetailsForTest(), scope.getExceptionState()); | 301 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
314 EXPECT_FALSE(scope.getExceptionState().hadException()); | 302 EXPECT_FALSE(scope.getExceptionState().hadException()); |
315 | 303 |
316 request->show(scope.getScriptState()) | 304 request->show(scope.getScriptState()) |
317 .then(funcs.expectNoCall(), funcs.expectCall()); | 305 .then(funcs.expectNoCall(), funcs.expectCall()); |
318 | 306 |
319 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 307 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
320 ->OnShippingAddressChange(payments::mojom::blink::PaymentAddress::New()); | 308 ->OnShippingAddressChange(payments::mojom::blink::PaymentAddress::New()); |
321 } | 309 } |
322 | 310 |
323 TEST(PaymentRequestTest, OnShippingOptionChange) { | 311 TEST(PaymentRequestTest, OnShippingOptionChange) { |
324 V8TestingScope scope; | 312 V8TestingScope scope; |
325 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 313 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
326 makePaymentRequestOriginSecure(scope.document()); | 314 makePaymentRequestOriginSecure(scope.document()); |
327 PaymentRequest* request = PaymentRequest::create( | 315 PaymentRequest* request = PaymentRequest::create( |
328 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 316 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
329 buildPaymentDetailsForTest(), scope.getExceptionState()); | 317 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
330 EXPECT_FALSE(scope.getExceptionState().hadException()); | 318 EXPECT_FALSE(scope.getExceptionState().hadException()); |
331 | 319 |
332 request->show(scope.getScriptState()) | 320 request->show(scope.getScriptState()) |
333 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 321 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
334 | 322 |
335 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 323 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
336 ->OnShippingOptionChange("standardShipping"); | 324 ->OnShippingOptionChange("standardShipping"); |
337 } | 325 } |
338 | 326 |
339 TEST(PaymentRequestTest, CannotCallShowTwice) { | 327 TEST(PaymentRequestTest, CannotCallShowTwice) { |
340 V8TestingScope scope; | 328 V8TestingScope scope; |
341 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 329 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
342 makePaymentRequestOriginSecure(scope.document()); | 330 makePaymentRequestOriginSecure(scope.document()); |
343 PaymentRequest* request = PaymentRequest::create( | 331 PaymentRequest* request = PaymentRequest::create( |
344 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 332 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
345 buildPaymentDetailsForTest(), scope.getExceptionState()); | 333 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
346 EXPECT_FALSE(scope.getExceptionState().hadException()); | 334 EXPECT_FALSE(scope.getExceptionState().hadException()); |
347 request->show(scope.getScriptState()); | 335 request->show(scope.getScriptState()); |
348 | 336 |
349 request->show(scope.getScriptState()) | 337 request->show(scope.getScriptState()) |
350 .then(funcs.expectNoCall(), funcs.expectCall()); | 338 .then(funcs.expectNoCall(), funcs.expectCall()); |
351 } | 339 } |
352 | 340 |
353 TEST(PaymentRequestTest, CannotShowAfterAborted) { | 341 TEST(PaymentRequestTest, CannotShowAfterAborted) { |
354 V8TestingScope scope; | 342 V8TestingScope scope; |
355 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 343 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
356 makePaymentRequestOriginSecure(scope.document()); | 344 makePaymentRequestOriginSecure(scope.document()); |
357 PaymentRequest* request = PaymentRequest::create( | 345 PaymentRequest* request = PaymentRequest::create( |
358 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 346 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
359 buildPaymentDetailsForTest(), scope.getExceptionState()); | 347 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
360 EXPECT_FALSE(scope.getExceptionState().hadException()); | 348 EXPECT_FALSE(scope.getExceptionState().hadException()); |
361 request->show(scope.getScriptState()); | 349 request->show(scope.getScriptState()); |
362 request->abort(scope.getScriptState()); | 350 request->abort(scope.getScriptState()); |
363 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( | 351 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( |
364 true); | 352 true); |
365 | 353 |
366 request->show(scope.getScriptState()) | 354 request->show(scope.getScriptState()) |
367 .then(funcs.expectNoCall(), funcs.expectCall()); | 355 .then(funcs.expectNoCall(), funcs.expectCall()); |
368 } | 356 } |
369 | 357 |
370 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { | 358 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { |
371 V8TestingScope scope; | 359 V8TestingScope scope; |
372 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 360 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
373 makePaymentRequestOriginSecure(scope.document()); | 361 makePaymentRequestOriginSecure(scope.document()); |
374 PaymentRequest* request = PaymentRequest::create( | 362 PaymentRequest* request = PaymentRequest::create( |
375 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 363 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
376 buildPaymentDetailsForTest(), scope.getExceptionState()); | 364 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
377 EXPECT_FALSE(scope.getExceptionState().hadException()); | 365 EXPECT_FALSE(scope.getExceptionState().hadException()); |
378 | 366 |
379 String errorMessage; | 367 String errorMessage; |
380 request->show(scope.getScriptState()) | 368 request->show(scope.getScriptState()) |
381 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 369 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
382 | 370 |
383 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( | 371 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( |
384 payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED); | 372 payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED); |
385 | 373 |
386 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 374 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
387 EXPECT_EQ("NotSupportedError: The payment method is not supported", | 375 EXPECT_EQ("NotSupportedError: The payment method is not supported", |
388 errorMessage); | 376 errorMessage); |
389 } | 377 } |
390 | 378 |
391 TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { | 379 TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { |
392 V8TestingScope scope; | 380 V8TestingScope scope; |
393 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 381 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
394 makePaymentRequestOriginSecure(scope.document()); | 382 makePaymentRequestOriginSecure(scope.document()); |
395 PaymentRequest* request = PaymentRequest::create( | 383 PaymentRequest* request = PaymentRequest::create( |
396 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 384 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
397 buildPaymentDetailsForTest(), scope.getExceptionState()); | 385 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
398 EXPECT_FALSE(scope.getExceptionState().hadException()); | 386 EXPECT_FALSE(scope.getExceptionState().hadException()); |
399 | 387 |
400 String errorMessage; | 388 String errorMessage; |
401 request->show(scope.getScriptState()) | 389 request->show(scope.getScriptState()) |
402 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 390 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
403 | 391 |
404 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( | 392 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( |
405 payments::mojom::blink::PaymentErrorReason::USER_CANCEL); | 393 payments::mojom::blink::PaymentErrorReason::USER_CANCEL); |
406 | 394 |
407 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 395 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
408 EXPECT_EQ("AbortError: Request cancelled", errorMessage); | 396 EXPECT_EQ("AbortError: Request cancelled", errorMessage); |
409 } | 397 } |
410 | 398 |
411 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { | 399 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { |
412 V8TestingScope scope; | 400 V8TestingScope scope; |
413 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 401 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
414 makePaymentRequestOriginSecure(scope.document()); | 402 makePaymentRequestOriginSecure(scope.document()); |
415 PaymentRequest* request = PaymentRequest::create( | 403 PaymentRequest* request = PaymentRequest::create( |
416 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 404 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
417 buildPaymentDetailsForTest(), scope.getExceptionState()); | 405 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
418 EXPECT_FALSE(scope.getExceptionState().hadException()); | 406 EXPECT_FALSE(scope.getExceptionState().hadException()); |
419 | 407 |
420 String errorMessage; | 408 String errorMessage; |
421 request->show(scope.getScriptState()) | 409 request->show(scope.getScriptState()) |
422 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 410 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
423 | 411 |
424 request->onUpdatePaymentDetailsFailure("oops"); | 412 request->onUpdatePaymentDetailsFailure("oops"); |
425 | 413 |
426 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 414 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
427 EXPECT_EQ("AbortError: oops", errorMessage); | 415 EXPECT_EQ("AbortError: oops", errorMessage); |
428 } | 416 } |
429 | 417 |
430 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { | 418 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { |
431 V8TestingScope scope; | 419 V8TestingScope scope; |
432 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 420 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
433 makePaymentRequestOriginSecure(scope.document()); | 421 makePaymentRequestOriginSecure(scope.document()); |
434 PaymentRequest* request = PaymentRequest::create( | 422 PaymentRequest* request = PaymentRequest::create( |
435 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 423 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
436 buildPaymentDetailsForTest(), scope.getExceptionState()); | 424 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
437 EXPECT_FALSE(scope.getExceptionState().hadException()); | 425 EXPECT_FALSE(scope.getExceptionState().hadException()); |
438 request->show(scope.getScriptState()) | 426 request->show(scope.getScriptState()) |
439 .then(funcs.expectCall(), funcs.expectNoCall()); | 427 .then(funcs.expectCall(), funcs.expectNoCall()); |
440 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 428 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
441 ->OnPaymentResponse(buildPaymentResponseForTest()); | 429 ->OnPaymentResponse(buildPaymentResponseForTest()); |
442 | 430 |
443 request->onUpdatePaymentDetails( | 431 request->onUpdatePaymentDetails( |
444 ScriptValue::from(scope.getScriptState(), "foo")); | 432 ScriptValue::from(scope.getScriptState(), "foo")); |
445 } | 433 } |
446 | 434 |
447 TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { | 435 TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { |
448 V8TestingScope scope; | 436 V8TestingScope scope; |
449 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 437 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
450 makePaymentRequestOriginSecure(scope.document()); | 438 makePaymentRequestOriginSecure(scope.document()); |
451 PaymentRequest* request = PaymentRequest::create( | 439 PaymentRequest* request = PaymentRequest::create( |
452 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 440 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
453 buildPaymentDetailsForTest(), scope.getExceptionState()); | 441 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
454 EXPECT_FALSE(scope.getExceptionState().hadException()); | 442 EXPECT_FALSE(scope.getExceptionState().hadException()); |
455 | 443 |
456 request->show(scope.getScriptState()) | 444 request->show(scope.getScriptState()) |
457 .then(funcs.expectNoCall(), funcs.expectCall()); | 445 .then(funcs.expectNoCall(), funcs.expectCall()); |
458 | 446 |
459 request->onUpdatePaymentDetails( | 447 request->onUpdatePaymentDetails( |
460 ScriptValue::from(scope.getScriptState(), "NotPaymentDetails")); | 448 ScriptValue::from(scope.getScriptState(), "NotPaymentDetails")); |
461 } | 449 } |
462 | 450 |
463 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) { | 451 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) { |
464 V8TestingScope scope; | 452 V8TestingScope scope; |
465 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 453 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
466 makePaymentRequestOriginSecure(scope.document()); | 454 makePaymentRequestOriginSecure(scope.document()); |
467 PaymentRequest* request = PaymentRequest::create( | 455 PaymentRequest* request = PaymentRequest::create( |
468 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 456 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
469 buildPaymentDetailsForTest(), scope.getExceptionState()); | 457 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
470 EXPECT_FALSE(scope.getExceptionState().hadException()); | 458 EXPECT_FALSE(scope.getExceptionState().hadException()); |
471 | 459 |
472 request->show(scope.getScriptState()) | 460 request->show(scope.getScriptState()) |
473 .then(funcs.expectNoCall(), funcs.expectCall()); | 461 .then(funcs.expectNoCall(), funcs.expectCall()); |
474 | 462 |
475 request->onUpdatePaymentDetails( | 463 request->onUpdatePaymentDetails( |
476 ScriptValue::from(scope.getScriptState(), | 464 ScriptValue::from(scope.getScriptState(), |
477 fromJSONString(scope.getScriptState()->isolate(), "{}", | 465 fromJSONString(scope.getScriptState()->isolate(), "{}", |
478 scope.getExceptionState()))); | 466 scope.getExceptionState()))); |
479 EXPECT_FALSE(scope.getExceptionState().hadException()); | 467 EXPECT_FALSE(scope.getExceptionState().hadException()); |
480 } | 468 } |
481 | 469 |
482 TEST(PaymentRequestTest, | 470 TEST(PaymentRequestTest, |
483 ClearShippingOptionOnPaymentDetailsUpdateWithoutShippingOptions) { | 471 ClearShippingOptionOnPaymentDetailsUpdateWithoutShippingOptions) { |
484 V8TestingScope scope; | 472 V8TestingScope scope; |
485 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 473 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
486 makePaymentRequestOriginSecure(scope.document()); | 474 makePaymentRequestOriginSecure(scope.document()); |
487 PaymentDetails details; | 475 PaymentDetailsInit details; |
488 details.setTotal(buildPaymentItemForTest()); | 476 details.setTotal(buildPaymentItemForTest()); |
489 PaymentOptions options; | 477 PaymentOptions options; |
490 options.setRequestShipping(true); | 478 options.setRequestShipping(true); |
491 PaymentRequest* request = PaymentRequest::create( | 479 PaymentRequest* request = PaymentRequest::create( |
492 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 480 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
493 options, scope.getExceptionState()); | 481 options, scope.getExceptionState()); |
494 EXPECT_FALSE(scope.getExceptionState().hadException()); | 482 EXPECT_FALSE(scope.getExceptionState().hadException()); |
495 EXPECT_TRUE(request->shippingOption().isNull()); | 483 EXPECT_TRUE(request->shippingOption().isNull()); |
496 request->show(scope.getScriptState()) | 484 request->show(scope.getScriptState()) |
497 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 485 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
(...skipping 25 matching lines...) Expand all Loading... |
523 TEST( | 511 TEST( |
524 PaymentRequestTest, | 512 PaymentRequestTest, |
525 ClearShippingOptionOnPaymentDetailsUpdateWithMultipleUnselectedShippingOptio
ns) { | 513 ClearShippingOptionOnPaymentDetailsUpdateWithMultipleUnselectedShippingOptio
ns) { |
526 V8TestingScope scope; | 514 V8TestingScope scope; |
527 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 515 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
528 makePaymentRequestOriginSecure(scope.document()); | 516 makePaymentRequestOriginSecure(scope.document()); |
529 PaymentOptions options; | 517 PaymentOptions options; |
530 options.setRequestShipping(true); | 518 options.setRequestShipping(true); |
531 PaymentRequest* request = PaymentRequest::create( | 519 PaymentRequest* request = PaymentRequest::create( |
532 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 520 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
533 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 521 buildPaymentDetailsInitForTest(), options, scope.getExceptionState()); |
534 EXPECT_FALSE(scope.getExceptionState().hadException()); | 522 EXPECT_FALSE(scope.getExceptionState().hadException()); |
535 request->show(scope.getScriptState()) | 523 request->show(scope.getScriptState()) |
536 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 524 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
537 String detail = | 525 String detail = |
538 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 526 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
539 "\"value\": \"5.00\"}}," | 527 "\"value\": \"5.00\"}}," |
540 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " | 528 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " |
541 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 529 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
542 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " | 530 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " |
543 "\"USD\", \"value\": \"50.00\"}}]}"; | 531 "\"USD\", \"value\": \"50.00\"}}]}"; |
544 | 532 |
545 request->onUpdatePaymentDetails( | 533 request->onUpdatePaymentDetails( |
546 ScriptValue::from(scope.getScriptState(), | 534 ScriptValue::from(scope.getScriptState(), |
547 fromJSONString(scope.getScriptState()->isolate(), | 535 fromJSONString(scope.getScriptState()->isolate(), |
548 detail, scope.getExceptionState()))); | 536 detail, scope.getExceptionState()))); |
549 EXPECT_FALSE(scope.getExceptionState().hadException()); | 537 EXPECT_FALSE(scope.getExceptionState().hadException()); |
550 | 538 |
551 EXPECT_TRUE(request->shippingOption().isNull()); | 539 EXPECT_TRUE(request->shippingOption().isNull()); |
552 } | 540 } |
553 | 541 |
554 TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) { | 542 TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) { |
555 V8TestingScope scope; | 543 V8TestingScope scope; |
556 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 544 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
557 makePaymentRequestOriginSecure(scope.document()); | 545 makePaymentRequestOriginSecure(scope.document()); |
558 PaymentOptions options; | 546 PaymentOptions options; |
559 options.setRequestShipping(true); | 547 options.setRequestShipping(true); |
560 PaymentRequest* request = PaymentRequest::create( | 548 PaymentRequest* request = PaymentRequest::create( |
561 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 549 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
562 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 550 buildPaymentDetailsInitForTest(), options, scope.getExceptionState()); |
563 EXPECT_FALSE(scope.getExceptionState().hadException()); | 551 EXPECT_FALSE(scope.getExceptionState().hadException()); |
564 request->show(scope.getScriptState()) | 552 request->show(scope.getScriptState()) |
565 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 553 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
566 String detail = | 554 String detail = |
567 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 555 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
568 "\"value\": \"5.00\"}}," | 556 "\"value\": \"5.00\"}}," |
569 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " | 557 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " |
570 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 558 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
571 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " | 559 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " |
572 "\"USD\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 560 "\"USD\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
573 | 561 |
574 request->onUpdatePaymentDetails( | 562 request->onUpdatePaymentDetails( |
575 ScriptValue::from(scope.getScriptState(), | 563 ScriptValue::from(scope.getScriptState(), |
576 fromJSONString(scope.getScriptState()->isolate(), | 564 fromJSONString(scope.getScriptState()->isolate(), |
577 detail, scope.getExceptionState()))); | 565 detail, scope.getExceptionState()))); |
578 EXPECT_FALSE(scope.getExceptionState().hadException()); | 566 EXPECT_FALSE(scope.getExceptionState().hadException()); |
579 | 567 |
580 EXPECT_EQ("fast", request->shippingOption()); | 568 EXPECT_EQ("fast", request->shippingOption()); |
581 } | 569 } |
582 | 570 |
583 TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) { | 571 TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) { |
584 V8TestingScope scope; | 572 V8TestingScope scope; |
585 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 573 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
586 makePaymentRequestOriginSecure(scope.document()); | 574 makePaymentRequestOriginSecure(scope.document()); |
587 PaymentRequest* request = PaymentRequest::create( | 575 PaymentRequest* request = PaymentRequest::create( |
588 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 576 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
589 buildPaymentDetailsForTest(), scope.getExceptionState()); | 577 buildPaymentDetailsInitForTest(), scope.getExceptionState()); |
590 EXPECT_FALSE(scope.getExceptionState().hadException()); | 578 EXPECT_FALSE(scope.getExceptionState().hadException()); |
591 | 579 |
592 request->show(scope.getScriptState()) | 580 request->show(scope.getScriptState()) |
593 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 581 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
594 String detailWithErrorMsg = | 582 String detailWithErrorMsg = |
595 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 583 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
596 "\"value\": \"5.00\"}}," | 584 "\"value\": \"5.00\"}}," |
597 "\"error\": \"This is an error message.\"}"; | 585 "\"error\": \"This is an error message.\"}"; |
598 | 586 |
599 request->onUpdatePaymentDetails(ScriptValue::from( | 587 request->onUpdatePaymentDetails(ScriptValue::from( |
600 scope.getScriptState(), | 588 scope.getScriptState(), |
601 fromJSONString(scope.getScriptState()->isolate(), detailWithErrorMsg, | 589 fromJSONString(scope.getScriptState()->isolate(), detailWithErrorMsg, |
602 scope.getExceptionState()))); | 590 scope.getExceptionState()))); |
603 EXPECT_FALSE(scope.getExceptionState().hadException()); | 591 EXPECT_FALSE(scope.getExceptionState().hadException()); |
604 } | 592 } |
605 | 593 |
606 TEST(PaymentRequestTest, | 594 TEST(PaymentRequestTest, |
607 ShouldResolveWithEmptyShippingOptionsIfIDsOfShippingOptionsAreDuplicated) { | 595 ShouldResolveWithEmptyShippingOptionsIfIDsOfShippingOptionsAreDuplicated) { |
608 V8TestingScope scope; | 596 V8TestingScope scope; |
609 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 597 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
610 makePaymentRequestOriginSecure(scope.document()); | 598 makePaymentRequestOriginSecure(scope.document()); |
611 PaymentDetails details; | 599 PaymentDetailsInit details; |
612 details.setTotal(buildPaymentItemForTest()); | 600 details.setTotal(buildPaymentItemForTest()); |
613 HeapVector<PaymentShippingOption> shippingOptions(2); | 601 HeapVector<PaymentShippingOption> shippingOptions(2); |
614 shippingOptions[0] = buildShippingOptionForTest( | 602 shippingOptions[0] = buildShippingOptionForTest( |
615 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); | 603 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); |
616 shippingOptions[0].setSelected(true); | 604 shippingOptions[0].setSelected(true); |
617 shippingOptions[1] = buildShippingOptionForTest( | 605 shippingOptions[1] = buildShippingOptionForTest( |
618 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); | 606 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); |
619 details.setShippingOptions(shippingOptions); | 607 details.setShippingOptions(shippingOptions); |
620 PaymentOptions options; | 608 PaymentOptions options; |
621 options.setRequestShipping(true); | 609 options.setRequestShipping(true); |
(...skipping 17 matching lines...) Expand all Loading... |
639 scope.getScriptState(), | 627 scope.getScriptState(), |
640 fromJSONString(scope.getScriptState()->isolate(), | 628 fromJSONString(scope.getScriptState()->isolate(), |
641 detailWithShippingOptions, scope.getExceptionState()))); | 629 detailWithShippingOptions, scope.getExceptionState()))); |
642 | 630 |
643 EXPECT_FALSE(scope.getExceptionState().hadException()); | 631 EXPECT_FALSE(scope.getExceptionState().hadException()); |
644 EXPECT_TRUE(request->shippingOption().isNull()); | 632 EXPECT_TRUE(request->shippingOption().isNull()); |
645 } | 633 } |
646 | 634 |
647 } // namespace | 635 } // namespace |
648 } // namespace blink | 636 } // namespace blink |
OLD | NEW |