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