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/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/JSONValuesForV8.h" | 8 #include "bindings/core/v8/JSONValuesForV8.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/modules/v8/V8PaymentResponse.h" | 10 #include "bindings/modules/v8/V8PaymentResponse.h" |
11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
12 #include "core/testing/DummyPageHolder.h" | 12 #include "core/testing/DummyPageHolder.h" |
13 #include "modules/payments/CurrencyAmount.h" | 13 #include "modules/payments/CurrencyAmount.h" |
14 #include "modules/payments/PaymentAddress.h" | 14 #include "modules/payments/PaymentAddress.h" |
15 #include "modules/payments/PaymentDetailsTestHelper.h" | |
16 #include "modules/payments/PaymentItem.h" | 15 #include "modules/payments/PaymentItem.h" |
| 16 #include "modules/payments/PaymentTestHelper.h" |
17 #include "modules/payments/ShippingOption.h" | 17 #include "modules/payments/ShippingOption.h" |
18 #include "platform/heap/HeapAllocator.h" | 18 #include "platform/heap/HeapAllocator.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "wtf/OwnPtr.h" | 21 #include "wtf/OwnPtr.h" |
22 #include <utility> | 22 #include <utility> |
23 | 23 |
24 namespace blink { | 24 namespace blink { |
25 namespace { | 25 namespace { |
26 | 26 |
(...skipping 15 matching lines...) Expand all Loading... |
42 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); | 42 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 OwnPtr<DummyPageHolder> m_page; | 46 OwnPtr<DummyPageHolder> m_page; |
47 TrackExceptionState m_exceptionState; | 47 TrackExceptionState m_exceptionState; |
48 }; | 48 }; |
49 | 49 |
50 TEST_F(PaymentRequestTest, NoExceptionWithValidData) | 50 TEST_F(PaymentRequestTest, NoExceptionWithValidData) |
51 { | 51 { |
52 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(), getExceptionState()); | 52 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
53 | 53 |
54 EXPECT_FALSE(getExceptionState().hadException()); | 54 EXPECT_FALSE(getExceptionState().hadException()); |
55 } | 55 } |
56 | 56 |
57 TEST_F(PaymentRequestTest, SecureContextRequired) | 57 TEST_F(PaymentRequestTest, SecureContextRequired) |
58 { | 58 { |
59 setSecurityOrigin("http://www.example.com"); | 59 setSecurityOrigin("http://www.example.com"); |
60 | 60 |
61 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(), getExceptionState()); | 61 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
62 | 62 |
63 EXPECT_TRUE(getExceptionState().hadException()); | 63 EXPECT_TRUE(getExceptionState().hadException()); |
64 EXPECT_EQ(SecurityError, getExceptionState().code()); | 64 EXPECT_EQ(SecurityError, getExceptionState().code()); |
65 } | 65 } |
66 | 66 |
67 TEST_F(PaymentRequestTest, SupportedMethodListRequired) | 67 TEST_F(PaymentRequestTest, SupportedMethodListRequired) |
68 { | 68 { |
69 PaymentRequest::create(getScriptState(), Vector<String>(), buildPaymentDetai
lsForTest(), getExceptionState()); | 69 PaymentRequest::create(getScriptState(), HeapVector<PaymentMethodData>(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
70 | 70 |
71 EXPECT_TRUE(getExceptionState().hadException()); | 71 EXPECT_TRUE(getExceptionState().hadException()); |
72 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 72 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
73 } | 73 } |
74 | 74 |
75 TEST_F(PaymentRequestTest, TotalRequired) | 75 TEST_F(PaymentRequestTest, TotalRequired) |
76 { | 76 { |
77 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe
tails(), getExceptionState()); | 77 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), Pa
ymentDetails(), getExceptionState()); |
78 | 78 |
79 EXPECT_TRUE(getExceptionState().hadException()); | 79 EXPECT_TRUE(getExceptionState().hadException()); |
80 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 80 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
81 } | 81 } |
82 | 82 |
83 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) | 83 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) |
84 { | 84 { |
85 PaymentDetails details; | 85 PaymentDetails details; |
86 details.setTotal(buildPaymentItemForTest()); | 86 details.setTotal(buildPaymentItemForTest()); |
87 PaymentOptions options; | 87 PaymentOptions options; |
88 options.setRequestShipping(true); | 88 options.setRequestShipping(true); |
89 | 89 |
90 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 90 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
91 | 91 |
92 EXPECT_TRUE(request->shippingOption().isNull()); | 92 EXPECT_TRUE(request->shippingOption().isNull()); |
93 } | 93 } |
94 | 94 |
95 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) | 95 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) |
96 { | 96 { |
97 PaymentDetails details; | 97 PaymentDetails details; |
98 details.setTotal(buildPaymentItemForTest()); | 98 details.setTotal(buildPaymentItemForTest()); |
99 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); | 99 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); |
100 PaymentOptions options; | 100 PaymentOptions options; |
101 options.setRequestShipping(true); | 101 options.setRequestShipping(true); |
102 | 102 |
103 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 103 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
104 | 104 |
105 EXPECT_TRUE(request->shippingOption().isNull()); | 105 EXPECT_TRUE(request->shippingOption().isNull()); |
106 } | 106 } |
107 | 107 |
108 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) | 108 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) |
109 { | 109 { |
110 PaymentDetails details; | 110 PaymentDetails details; |
111 details.setTotal(buildPaymentItemForTest()); | 111 details.setTotal(buildPaymentItemForTest()); |
112 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); | 112 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); |
113 | 113 |
114 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); | 114 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, getExceptionState()); |
115 | 115 |
116 EXPECT_TRUE(request->shippingOption().isNull()); | 116 EXPECT_TRUE(request->shippingOption().isNull()); |
117 } | 117 } |
118 | 118 |
119 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo
tRequested) | 119 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo
tRequested) |
120 { | 120 { |
121 PaymentDetails details; | 121 PaymentDetails details; |
122 details.setTotal(buildPaymentItemForTest()); | 122 details.setTotal(buildPaymentItemForTest()); |
123 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); | 123 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); |
124 PaymentOptions options; | 124 PaymentOptions options; |
125 options.setRequestShipping(false); | 125 options.setRequestShipping(false); |
126 | 126 |
127 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 127 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
128 | 128 |
129 EXPECT_TRUE(request->shippingOption().isNull()); | 129 EXPECT_TRUE(request->shippingOption().isNull()); |
130 } | 130 } |
131 | 131 |
132 TEST_F(PaymentRequestTest, DontSelectSingleUnselectedShippingOptionWhenShippingR
equested) | 132 TEST_F(PaymentRequestTest, DontSelectSingleUnselectedShippingOptionWhenShippingR
equested) |
133 { | 133 { |
134 PaymentDetails details; | 134 PaymentDetails details; |
135 details.setTotal(buildPaymentItemForTest()); | 135 details.setTotal(buildPaymentItemForTest()); |
136 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); | 136 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); |
137 PaymentOptions options; | 137 PaymentOptions options; |
138 options.setRequestShipping(true); | 138 options.setRequestShipping(true); |
139 | 139 |
140 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 140 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
141 | 141 |
142 EXPECT_TRUE(request->shippingOption().isNull()); | 142 EXPECT_TRUE(request->shippingOption().isNull()); |
143 } | 143 } |
144 | 144 |
145 TEST_F(PaymentRequestTest, SelectSingleSelectedShippingOptionWhenShippingRequest
ed) | 145 TEST_F(PaymentRequestTest, SelectSingleSelectedShippingOptionWhenShippingRequest
ed) |
146 { | 146 { |
147 PaymentDetails details; | 147 PaymentDetails details; |
148 details.setTotal(buildPaymentItemForTest()); | 148 details.setTotal(buildPaymentItemForTest()); |
149 HeapVector<ShippingOption> shippingOptions(1, buildShippingOptionForTest(Pay
mentTestDataId, PaymentTestOverwriteValue, "standard")); | 149 HeapVector<ShippingOption> shippingOptions(1, buildShippingOptionForTest(Pay
mentTestDataId, PaymentTestOverwriteValue, "standard")); |
150 shippingOptions[0].setSelected(true); | 150 shippingOptions[0].setSelected(true); |
151 details.setShippingOptions(shippingOptions); | 151 details.setShippingOptions(shippingOptions); |
152 PaymentOptions options; | 152 PaymentOptions options; |
153 options.setRequestShipping(true); | 153 options.setRequestShipping(true); |
154 | 154 |
155 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 155 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
156 | 156 |
157 EXPECT_EQ("standard", request->shippingOption()); | 157 EXPECT_EQ("standard", request->shippingOption()); |
158 } | 158 } |
159 | 159 |
160 TEST_F(PaymentRequestTest, SelectOnlySelectedShippingOptionWhenShippingRequested
) | 160 TEST_F(PaymentRequestTest, SelectOnlySelectedShippingOptionWhenShippingRequested
) |
161 { | 161 { |
162 PaymentDetails details; | 162 PaymentDetails details; |
163 details.setTotal(buildPaymentItemForTest()); | 163 details.setTotal(buildPaymentItemForTest()); |
164 HeapVector<ShippingOption> shippingOptions(2); | 164 HeapVector<ShippingOption> shippingOptions(2); |
165 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); | 165 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); |
166 shippingOptions[0].setSelected(true); | 166 shippingOptions[0].setSelected(true); |
167 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); | 167 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); |
168 details.setShippingOptions(shippingOptions); | 168 details.setShippingOptions(shippingOptions); |
169 PaymentOptions options; | 169 PaymentOptions options; |
170 options.setRequestShipping(true); | 170 options.setRequestShipping(true); |
171 | 171 |
172 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 172 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
173 | 173 |
174 EXPECT_EQ("standard", request->shippingOption()); | 174 EXPECT_EQ("standard", request->shippingOption()); |
175 } | 175 } |
176 | 176 |
177 TEST_F(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested
) | 177 TEST_F(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested
) |
178 { | 178 { |
179 PaymentDetails details; | 179 PaymentDetails details; |
180 details.setTotal(buildPaymentItemForTest()); | 180 details.setTotal(buildPaymentItemForTest()); |
181 HeapVector<ShippingOption> shippingOptions(2); | 181 HeapVector<ShippingOption> shippingOptions(2); |
182 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); | 182 shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "standard"); |
183 shippingOptions[0].setSelected(true); | 183 shippingOptions[0].setSelected(true); |
184 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); | 184 shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTe
stOverwriteValue, "express"); |
185 shippingOptions[1].setSelected(true); | 185 shippingOptions[1].setSelected(true); |
186 details.setShippingOptions(shippingOptions); | 186 details.setShippingOptions(shippingOptions); |
187 PaymentOptions options; | 187 PaymentOptions options; |
188 options.setRequestShipping(true); | 188 options.setRequestShipping(true); |
189 | 189 |
190 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 190 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
191 | 191 |
192 EXPECT_EQ("express", request->shippingOption()); | 192 EXPECT_EQ("express", request->shippingOption()); |
193 } | 193 } |
194 | 194 |
195 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) | 195 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) |
196 { | 196 { |
197 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 197 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
198 EXPECT_FALSE(getExceptionState().hadException()); | 198 EXPECT_FALSE(getExceptionState().hadException()); |
199 | 199 |
200 request->abort(getExceptionState()); | 200 request->abort(getExceptionState()); |
201 EXPECT_TRUE(getExceptionState().hadException()); | 201 EXPECT_TRUE(getExceptionState().hadException()); |
202 } | 202 } |
203 | 203 |
204 class MockFunction : public ScriptFunction { | 204 class MockFunction : public ScriptFunction { |
205 public: | 205 public: |
206 static v8::Local<v8::Function> noExpectations(ScriptState* scriptState) | 206 static v8::Local<v8::Function> noExpectations(ScriptState* scriptState) |
207 { | 207 { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 { | 255 { |
256 DCHECK(m_value); | 256 DCHECK(m_value); |
257 } | 257 } |
258 | 258 |
259 ScriptValue* m_value; | 259 ScriptValue* m_value; |
260 }; | 260 }; |
261 | 261 |
262 TEST_F(PaymentRequestTest, CanAbortAfterShow) | 262 TEST_F(PaymentRequestTest, CanAbortAfterShow) |
263 { | 263 { |
264 ScriptState::Scope scope(getScriptState()); | 264 ScriptState::Scope scope(getScriptState()); |
265 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 265 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
266 EXPECT_FALSE(getExceptionState().hadException()); | 266 EXPECT_FALSE(getExceptionState().hadException()); |
267 | 267 |
268 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::noExpectations(getScriptState())); | 268 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::noExpectations(getScriptState())); |
269 request->abort(getExceptionState()); | 269 request->abort(getExceptionState()); |
270 | 270 |
271 EXPECT_FALSE(getExceptionState().hadException()); | 271 EXPECT_FALSE(getExceptionState().hadException()); |
272 } | 272 } |
273 | 273 |
274 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) | 274 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) |
275 { | 275 { |
276 ScriptState::Scope scope(getScriptState()); | 276 ScriptState::Scope scope(getScriptState()); |
277 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 277 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
278 EXPECT_FALSE(getExceptionState().hadException()); | 278 EXPECT_FALSE(getExceptionState().hadException()); |
279 | 279 |
280 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 280 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
281 | 281 |
282 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::PaymentAddress::New()); | 282 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::PaymentAddress::New()); |
283 } | 283 } |
284 | 284 |
285 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndEmptyShipp
ingAddressInResponse) | 285 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndEmptyShipp
ingAddressInResponse) |
286 { | 286 { |
287 ScriptState::Scope scope(getScriptState()); | 287 ScriptState::Scope scope(getScriptState()); |
288 PaymentOptions options; | 288 PaymentOptions options; |
289 options.setRequestShipping(true); | 289 options.setRequestShipping(true); |
290 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 290 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
291 EXPECT_FALSE(getExceptionState().hadException()); | 291 EXPECT_FALSE(getExceptionState().hadException()); |
292 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 292 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
293 | 293 |
294 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 294 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
295 | 295 |
296 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 296 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
297 } | 297 } |
298 | 298 |
299 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndInvalidShi
ppingAddressInResponse) | 299 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndInvalidShi
ppingAddressInResponse) |
300 { | 300 { |
301 ScriptState::Scope scope(getScriptState()); | 301 ScriptState::Scope scope(getScriptState()); |
302 PaymentOptions options; | 302 PaymentOptions options; |
303 options.setRequestShipping(true); | 303 options.setRequestShipping(true); |
304 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 304 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
305 EXPECT_FALSE(getExceptionState().hadException()); | 305 EXPECT_FALSE(getExceptionState().hadException()); |
306 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 306 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
307 response->shipping_address = mojom::blink::PaymentAddress::New(); | 307 response->shipping_address = mojom::blink::PaymentAddress::New(); |
308 | 308 |
309 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 309 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
310 | 310 |
311 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 311 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
312 } | 312 } |
313 | 313 |
314 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingA
ddressExistsInResponse) | 314 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingA
ddressExistsInResponse) |
315 { | 315 { |
316 ScriptState::Scope scope(getScriptState()); | 316 ScriptState::Scope scope(getScriptState()); |
317 PaymentOptions options; | 317 PaymentOptions options; |
318 options.setRequestShipping(false); | 318 options.setRequestShipping(false); |
319 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 319 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
320 EXPECT_FALSE(getExceptionState().hadException()); | 320 EXPECT_FALSE(getExceptionState().hadException()); |
321 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre
ss::New(); | 321 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre
ss::New(); |
322 shippingAddress->country = "US"; | 322 shippingAddress->country = "US"; |
323 shippingAddress->language_code = "en"; | 323 shippingAddress->language_code = "en"; |
324 shippingAddress->script_code = "Latn"; | 324 shippingAddress->script_code = "Latn"; |
325 | 325 |
326 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 326 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
327 | 327 |
328 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); | 328 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); |
329 } | 329 } |
330 | 330 |
331 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShip
pingAddressInResponse) | 331 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShip
pingAddressInResponse) |
332 { | 332 { |
333 ScriptState::Scope scope(getScriptState()); | 333 ScriptState::Scope scope(getScriptState()); |
334 PaymentOptions options; | 334 PaymentOptions options; |
335 options.setRequestShipping(true); | 335 options.setRequestShipping(true); |
336 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 336 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
337 EXPECT_FALSE(getExceptionState().hadException()); | 337 EXPECT_FALSE(getExceptionState().hadException()); |
338 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 338 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
339 response->shipping_address = mojom::blink::PaymentAddress::New(); | 339 response->shipping_address = mojom::blink::PaymentAddress::New(); |
340 response->shipping_address->country = "US"; | 340 response->shipping_address->country = "US"; |
341 response->shipping_address->language_code = "en"; | 341 response->shipping_address->language_code = "en"; |
342 response->shipping_address->script_code = "Latn"; | 342 response->shipping_address->script_code = "Latn"; |
343 | 343 |
344 ScriptValue outValue; | 344 ScriptValue outValue; |
345 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri
ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | 345 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri
ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); |
346 | 346 |
347 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 347 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
348 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | 348 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
349 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState(
)->isolate(), outValue.v8Value()); | 349 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState(
)->isolate(), outValue.v8Value()); |
350 | 350 |
351 EXPECT_EQ("US", pr->shippingAddress()->country()); | 351 EXPECT_EQ("US", pr->shippingAddress()->country()); |
352 EXPECT_EQ("en-Latn", pr->shippingAddress()->languageCode()); | 352 EXPECT_EQ("en-Latn", pr->shippingAddress()->languageCode()); |
353 } | 353 } |
354 | 354 |
355 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingFalseAndEmptyShi
ppingAddressInResponse) | 355 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingFalseAndEmptyShi
ppingAddressInResponse) |
356 { | 356 { |
357 ScriptState::Scope scope(getScriptState()); | 357 ScriptState::Scope scope(getScriptState()); |
358 PaymentOptions options; | 358 PaymentOptions options; |
359 options.setRequestShipping(false); | 359 options.setRequestShipping(false); |
360 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 360 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
361 EXPECT_FALSE(getExceptionState().hadException()); | 361 EXPECT_FALSE(getExceptionState().hadException()); |
362 | 362 |
363 ScriptValue outValue; | 363 ScriptValue outValue; |
364 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri
ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | 364 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri
ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); |
365 | 365 |
366 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 366 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
367 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | 367 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
368 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState(
)->isolate(), outValue.v8Value()); | 368 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState(
)->isolate(), outValue.v8Value()); |
369 | 369 |
370 EXPECT_EQ(nullptr, pr->shippingAddress()); | 370 EXPECT_EQ(nullptr, pr->shippingAddress()); |
371 } | 371 } |
372 | 372 |
373 TEST_F(PaymentRequestTest, OnShippingOptionChange) | 373 TEST_F(PaymentRequestTest, OnShippingOptionChange) |
374 { | 374 { |
375 ScriptState::Scope scope(getScriptState()); | 375 ScriptState::Scope scope(getScriptState()); |
376 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 376 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
377 EXPECT_FALSE(getExceptionState().hadException()); | 377 EXPECT_FALSE(getExceptionState().hadException()); |
378 | 378 |
379 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 379 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
380 | 380 |
381 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingOptionC
hange("standardShipping"); | 381 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingOptionC
hange("standardShipping"); |
382 } | 382 } |
383 | 383 |
384 TEST_F(PaymentRequestTest, CannotCallShowTwice) | 384 TEST_F(PaymentRequestTest, CannotCallShowTwice) |
385 { | 385 { |
386 ScriptState::Scope scope(getScriptState()); | 386 ScriptState::Scope scope(getScriptState()); |
387 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 387 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
388 EXPECT_FALSE(getExceptionState().hadException()); | 388 EXPECT_FALSE(getExceptionState().hadException()); |
389 request->show(getScriptState()); | 389 request->show(getScriptState()); |
390 | 390 |
391 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 391 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
392 } | 392 } |
393 | 393 |
394 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) | 394 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) |
395 { | 395 { |
396 ScriptState::Scope scope(getScriptState()); | 396 ScriptState::Scope scope(getScriptState()); |
397 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 397 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
398 EXPECT_FALSE(getExceptionState().hadException()); | 398 EXPECT_FALSE(getExceptionState().hadException()); |
399 request->show(getScriptState()); | 399 request->show(getScriptState()); |
400 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 400 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
401 request->complete(getScriptState(), false); | 401 request->complete(getScriptState(), false); |
402 | 402 |
403 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 403 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
404 } | 404 } |
405 | 405 |
406 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) | 406 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) |
407 { | 407 { |
408 ScriptState::Scope scope(getScriptState()); | 408 ScriptState::Scope scope(getScriptState()); |
409 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 409 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
410 EXPECT_FALSE(getExceptionState().hadException()); | 410 EXPECT_FALSE(getExceptionState().hadException()); |
411 | 411 |
412 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 412 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
413 | 413 |
414 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 414 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
415 } | 415 } |
416 | 416 |
417 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) | 417 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) |
418 { | 418 { |
419 ScriptState::Scope scope(getScriptState()); | 419 ScriptState::Scope scope(getScriptState()); |
420 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 420 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
421 EXPECT_FALSE(getExceptionState().hadException()); | 421 EXPECT_FALSE(getExceptionState().hadException()); |
422 request->show(getScriptState()); | 422 request->show(getScriptState()); |
423 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 423 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
424 | 424 |
425 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 425 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
426 | 426 |
427 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 427 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
428 } | 428 } |
429 | 429 |
430 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) | 430 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) |
431 { | 431 { |
432 ScriptState::Scope scope(getScriptState()); | 432 ScriptState::Scope scope(getScriptState()); |
433 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 433 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
434 EXPECT_FALSE(getExceptionState().hadException()); | 434 EXPECT_FALSE(getExceptionState().hadException()); |
435 request->show(getScriptState()); | 435 request->show(getScriptState()); |
436 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 436 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
437 | 437 |
438 request->complete(getScriptState(), true).then(MockFunction::expectCall(getS
criptState()), MockFunction::expectNoCall(getScriptState())); | 438 request->complete(getScriptState(), true).then(MockFunction::expectCall(getS
criptState()), MockFunction::expectNoCall(getScriptState())); |
439 | 439 |
440 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); | 440 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); |
441 } | 441 } |
442 | 442 |
443 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) | 443 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) |
444 { | 444 { |
445 ScriptState::Scope scope(getScriptState()); | 445 ScriptState::Scope scope(getScriptState()); |
446 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 446 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
447 EXPECT_FALSE(getExceptionState().hadException()); | 447 EXPECT_FALSE(getExceptionState().hadException()); |
448 | 448 |
449 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 449 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
450 | 450 |
451 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 451 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
452 } | 452 } |
453 | 453 |
454 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) | 454 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) |
455 { | 455 { |
456 ScriptState::Scope scope(getScriptState()); | 456 ScriptState::Scope scope(getScriptState()); |
457 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 457 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
458 EXPECT_FALSE(getExceptionState().hadException()); | 458 EXPECT_FALSE(getExceptionState().hadException()); |
459 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 459 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
460 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 460 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
461 | 461 |
462 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 462 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
463 | 463 |
464 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 464 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
465 } | 465 } |
466 | 466 |
467 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) | 467 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) |
468 { | 468 { |
469 ScriptState::Scope scope(getScriptState()); | 469 ScriptState::Scope scope(getScriptState()); |
470 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 470 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
471 EXPECT_FALSE(getExceptionState().hadException()); | 471 EXPECT_FALSE(getExceptionState().hadException()); |
472 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 472 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
473 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 473 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
474 | 474 |
475 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "foo")); | 475 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "foo")); |
476 } | 476 } |
477 | 477 |
478 TEST_F(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) | 478 TEST_F(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) |
479 { | 479 { |
480 ScriptState::Scope scope(getScriptState()); | 480 ScriptState::Scope scope(getScriptState()); |
481 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 481 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
482 EXPECT_FALSE(getExceptionState().hadException()); | 482 EXPECT_FALSE(getExceptionState().hadException()); |
483 | 483 |
484 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 484 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
485 | 485 |
486 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "NotPaym
entDetails")); | 486 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "NotPaym
entDetails")); |
487 } | 487 } |
488 | 488 |
489 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) | 489 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) |
490 { | 490 { |
491 ScriptState::Scope scope(getScriptState()); | 491 ScriptState::Scope scope(getScriptState()); |
492 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 492 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
493 EXPECT_FALSE(getExceptionState().hadException()); | 493 EXPECT_FALSE(getExceptionState().hadException()); |
494 | 494 |
495 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 495 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
496 | 496 |
497 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), "{}", getExceptionState()))); | 497 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), "{}", getExceptionState()))); |
498 EXPECT_FALSE(getExceptionState().hadException()); | 498 EXPECT_FALSE(getExceptionState().hadException()); |
499 } | 499 } |
500 | 500 |
501 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
ingOptions) | 501 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
ingOptions) |
502 { | 502 { |
503 ScriptState::Scope scope(getScriptState()); | 503 ScriptState::Scope scope(getScriptState()); |
504 PaymentDetails details; | 504 PaymentDetails details; |
505 details.setTotal(buildPaymentItemForTest()); | 505 details.setTotal(buildPaymentItemForTest()); |
506 PaymentOptions options; | 506 PaymentOptions options; |
507 options.setRequestShipping(true); | 507 options.setRequestShipping(true); |
508 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 508 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
509 EXPECT_FALSE(getExceptionState().hadException()); | 509 EXPECT_FALSE(getExceptionState().hadException()); |
510 EXPECT_TRUE(request->shippingOption().isNull()); | 510 EXPECT_TRUE(request->shippingOption().isNull()); |
511 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 511 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
512 String detailWithShippingOptions = "{\"total\": {\"label\": \"Total\", \"amo
unt\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 512 String detailWithShippingOptions = "{\"total\": {\"label\": \"Total\", \"amo
unt\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
513 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"},
\"selected\": true}]}"; | 513 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"},
\"selected\": true}]}"; |
514 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); | 514 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); |
515 EXPECT_FALSE(getExceptionState().hadException()); | 515 EXPECT_FALSE(getExceptionState().hadException()); |
516 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 516 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
517 String detailWithoutShippingOptions = "{\"total\": {\"label\": \"Total\", \"
amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}}"; | 517 String detailWithoutShippingOptions = "{\"total\": {\"label\": \"Total\", \"
amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}}"; |
518 | 518 |
519 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); | 519 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); |
520 | 520 |
521 EXPECT_FALSE(getExceptionState().hadException()); | 521 EXPECT_FALSE(getExceptionState().hadException()); |
522 EXPECT_TRUE(request->shippingOption().isNull()); | 522 EXPECT_TRUE(request->shippingOption().isNull()); |
523 } | 523 } |
524 | 524 |
525 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
UnselectedShippingOptions) | 525 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
UnselectedShippingOptions) |
526 { | 526 { |
527 ScriptState::Scope scope(getScriptState()); | 527 ScriptState::Scope scope(getScriptState()); |
528 PaymentOptions options; | 528 PaymentOptions options; |
529 options.setRequestShipping(true); | 529 options.setRequestShipping(true); |
530 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 530 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
531 EXPECT_FALSE(getExceptionState().hadException()); | 531 EXPECT_FALSE(getExceptionState().hadException()); |
532 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 532 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
533 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," | 533 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," |
534 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 534 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
535 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; | 535 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; |
536 | 536 |
537 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 537 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
538 EXPECT_FALSE(getExceptionState().hadException()); | 538 EXPECT_FALSE(getExceptionState().hadException()); |
539 | 539 |
540 EXPECT_TRUE(request->shippingOption().isNull()); | 540 EXPECT_TRUE(request->shippingOption().isNull()); |
541 } | 541 } |
542 | 542 |
543 TEST_F(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) | 543 TEST_F(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) |
544 { | 544 { |
545 ScriptState::Scope scope(getScriptState()); | 545 ScriptState::Scope scope(getScriptState()); |
546 PaymentOptions options; | 546 PaymentOptions options; |
547 options.setRequestShipping(true); | 547 options.setRequestShipping(true); |
548 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 548 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
549 EXPECT_FALSE(getExceptionState().hadException()); | 549 EXPECT_FALSE(getExceptionState().hadException()); |
550 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 550 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
551 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," | 551 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," |
552 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 552 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
553 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 553 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
554 | 554 |
555 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 555 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
556 EXPECT_FALSE(getExceptionState().hadException()); | 556 EXPECT_FALSE(getExceptionState().hadException()); |
557 | 557 |
558 EXPECT_EQ("fast", request->shippingOption()); | 558 EXPECT_EQ("fast", request->shippingOption()); |
559 } | 559 } |
560 | 560 |
561 } // namespace | 561 } // namespace |
562 } // namespace blink | 562 } // namespace blink |
OLD | NEW |