| 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" | |
| 8 #include "bindings/core/v8/JSONValuesForV8.h" | 7 #include "bindings/core/v8/JSONValuesForV8.h" |
| 8 #include "bindings/core/v8/ScriptFunction.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/V8BindingForTesting.h" | 10 #include "bindings/core/v8/V8BindingForTesting.h" |
| 11 #include "bindings/modules/v8/V8PaymentResponse.h" | 11 #include "bindings/modules/v8/V8PaymentResponse.h" |
| 12 #include "core/dom/Document.h" | 12 #include "core/dom/Document.h" |
| 13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
| 14 #include "modules/payments/CurrencyAmount.h" | |
| 15 #include "modules/payments/PaymentAddress.h" | 14 #include "modules/payments/PaymentAddress.h" |
| 16 #include "modules/payments/PaymentItem.h" | 15 #include "modules/payments/PaymentRequestTestBase.h" |
| 16 #include "modules/payments/PaymentResponse.h" |
| 17 #include "modules/payments/PaymentTestHelper.h" | 17 #include "modules/payments/PaymentTestHelper.h" |
| 18 #include "modules/payments/ShippingOption.h" | |
| 19 #include "platform/heap/HeapAllocator.h" | 18 #include "platform/heap/HeapAllocator.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "wtf/OwnPtr.h" | |
| 23 #include <utility> | 20 #include <utility> |
| 24 | 21 |
| 25 namespace blink { | 22 namespace blink { |
| 26 namespace { | 23 namespace { |
| 27 | 24 |
| 28 class PaymentRequestTest : public testing::Test { | 25 class PaymentRequestTest : public PaymentRequestTestBase {}; |
| 29 public: | |
| 30 PaymentRequestTest() | |
| 31 { | |
| 32 setSecurityOrigin("https://www.example.com/"); | |
| 33 } | |
| 34 | |
| 35 ~PaymentRequestTest() override {} | |
| 36 | |
| 37 ScriptState* getScriptState() { return m_scope.getScriptState(); } | |
| 38 ExceptionState& getExceptionState() { return m_scope.getExceptionState(); } | |
| 39 | |
| 40 void setSecurityOrigin(const String& securityOrigin) | |
| 41 { | |
| 42 m_scope.document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 V8TestingScope m_scope; | |
| 47 }; | |
| 48 | 26 |
| 49 TEST_F(PaymentRequestTest, NoExceptionWithValidData) | 27 TEST_F(PaymentRequestTest, NoExceptionWithValidData) |
| 50 { | 28 { |
| 51 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); | 29 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
| 52 | 30 |
| 53 EXPECT_FALSE(getExceptionState().hadException()); | 31 EXPECT_FALSE(getExceptionState().hadException()); |
| 54 } | 32 } |
| 55 | 33 |
| 56 TEST_F(PaymentRequestTest, SecureContextRequired) | 34 TEST_F(PaymentRequestTest, SecureContextRequired) |
| 57 { | 35 { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 shippingOptions[1].setSelected(true); | 162 shippingOptions[1].setSelected(true); |
| 185 details.setShippingOptions(shippingOptions); | 163 details.setShippingOptions(shippingOptions); |
| 186 PaymentOptions options; | 164 PaymentOptions options; |
| 187 options.setRequestShipping(true); | 165 options.setRequestShipping(true); |
| 188 | 166 |
| 189 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); | 167 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 190 | 168 |
| 191 EXPECT_EQ("express", request->shippingOption()); | 169 EXPECT_EQ("express", request->shippingOption()); |
| 192 } | 170 } |
| 193 | 171 |
| 194 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) | |
| 195 { | |
| 196 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | |
| 197 EXPECT_FALSE(getExceptionState().hadException()); | |
| 198 | |
| 199 request->abort(getExceptionState()); | |
| 200 EXPECT_TRUE(getExceptionState().hadException()); | |
| 201 } | |
| 202 | |
| 203 class MockFunction : public ScriptFunction { | |
| 204 public: | |
| 205 static v8::Local<v8::Function> noExpectations(ScriptState* scriptState) | |
| 206 { | |
| 207 MockFunction* self = new MockFunction(scriptState); | |
| 208 return self->bindToV8Function(); | |
| 209 } | |
| 210 | |
| 211 static v8::Local<v8::Function> expectCall(ScriptState* scriptState) | |
| 212 { | |
| 213 MockFunction* self = new MockFunction(scriptState); | |
| 214 EXPECT_CALL(*self, call(testing::_)); | |
| 215 return self->bindToV8Function(); | |
| 216 } | |
| 217 | |
| 218 static v8::Local<v8::Function> expectNoCall(ScriptState* scriptState) | |
| 219 { | |
| 220 MockFunction* self = new MockFunction(scriptState); | |
| 221 EXPECT_CALL(*self, call(testing::_)).Times(0); | |
| 222 return self->bindToV8Function(); | |
| 223 } | |
| 224 | |
| 225 private: | |
| 226 explicit MockFunction(ScriptState* scriptState) | |
| 227 : ScriptFunction(scriptState) | |
| 228 { | |
| 229 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); | |
| 230 } | |
| 231 | |
| 232 MOCK_METHOD1(call, ScriptValue(ScriptValue)); | |
| 233 }; | |
| 234 | |
| 235 class PaymentResponseFunction : public ScriptFunction { | |
| 236 public: | |
| 237 static v8::Local<v8::Function> create(ScriptState* scriptState, ScriptValue*
outValue) | |
| 238 { | |
| 239 PaymentResponseFunction* self = new PaymentResponseFunction(scriptState,
outValue); | |
| 240 return self->bindToV8Function(); | |
| 241 } | |
| 242 | |
| 243 ScriptValue call(ScriptValue value) override | |
| 244 { | |
| 245 DCHECK(!value.isEmpty()); | |
| 246 *m_value = value; | |
| 247 return value; | |
| 248 } | |
| 249 | |
| 250 private: | |
| 251 PaymentResponseFunction(ScriptState* scriptState, ScriptValue* outValue) | |
| 252 : ScriptFunction(scriptState) | |
| 253 , m_value(outValue) | |
| 254 { | |
| 255 DCHECK(m_value); | |
| 256 } | |
| 257 | |
| 258 ScriptValue* m_value; | |
| 259 }; | |
| 260 | |
| 261 TEST_F(PaymentRequestTest, CanAbortAfterShow) | |
| 262 { | |
| 263 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | |
| 264 EXPECT_FALSE(getExceptionState().hadException()); | |
| 265 | |
| 266 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::noExpectations(getScriptState())); | |
| 267 request->abort(getExceptionState()); | |
| 268 | |
| 269 EXPECT_FALSE(getExceptionState().hadException()); | |
| 270 } | |
| 271 | |
| 272 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) | 172 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) |
| 273 { | 173 { |
| 274 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 174 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 275 EXPECT_FALSE(getExceptionState().hadException()); | 175 EXPECT_FALSE(getExceptionState().hadException()); |
| 276 | 176 |
| 277 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 177 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 278 | 178 |
| 279 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::PaymentAddress::New()); | 179 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::PaymentAddress::New()); |
| 280 } | 180 } |
| 281 | 181 |
| 282 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndEmptyShipp
ingAddressInResponse) | 182 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndEmptyShipp
ingAddressInResponse) |
| 283 { | 183 { |
| 284 PaymentOptions options; | 184 PaymentOptions options; |
| 285 options.setRequestShipping(true); | 185 options.setRequestShipping(true); |
| 286 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); | 186 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 287 EXPECT_FALSE(getExceptionState().hadException()); | 187 EXPECT_FALSE(getExceptionState().hadException()); |
| 288 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); | 188 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); |
| 289 | 189 |
| 290 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 190 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 291 | 191 |
| 292 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 192 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 293 } | 193 } |
| 294 | 194 |
| 295 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndInvalidShi
ppingAddressInResponse) | 195 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndInvalidShi
ppingAddressInResponse) |
| 296 { | 196 { |
| 297 PaymentOptions options; | 197 PaymentOptions options; |
| 298 options.setRequestShipping(true); | 198 options.setRequestShipping(true); |
| 299 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); | 199 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 300 EXPECT_FALSE(getExceptionState().hadException()); | 200 EXPECT_FALSE(getExceptionState().hadException()); |
| 301 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); | 201 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); |
| 302 response->shipping_address = mojom::blink::PaymentAddress::New(); | 202 response->shipping_address = mojom::blink::PaymentAddress::New(); |
| 303 | 203 |
| 304 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 204 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 305 | 205 |
| 306 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 206 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 307 } | 207 } |
| 308 | 208 |
| 309 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingA
ddressExistsInResponse) | 209 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingA
ddressExistsInResponse) |
| 310 { | 210 { |
| 311 PaymentOptions options; | 211 PaymentOptions options; |
| 312 options.setRequestShipping(false); | 212 options.setRequestShipping(false); |
| 313 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); | 213 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 314 EXPECT_FALSE(getExceptionState().hadException()); | 214 EXPECT_FALSE(getExceptionState().hadException()); |
| 315 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre
ss::New(); | 215 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 316 shippingAddress->country = "US"; | 216 response->shipping_address = mojom::blink::PaymentAddress::New(); |
| 317 shippingAddress->language_code = "en"; | 217 response->shipping_address->country = "US"; |
| 318 shippingAddress->script_code = "Latn"; | 218 response->shipping_address->language_code = "en"; |
| 219 response->shipping_address->script_code = "Latn"; |
| 319 | 220 |
| 320 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 221 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 321 | 222 |
| 322 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); | 223 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 323 } | 224 } |
| 324 | 225 |
| 226 class PaymentResponseFunction : public ScriptFunction { |
| 227 public: |
| 228 static v8::Local<v8::Function> create(ScriptState* scriptState, ScriptValue*
outValue) |
| 229 { |
| 230 PaymentResponseFunction* self = new PaymentResponseFunction(scriptState,
outValue); |
| 231 return self->bindToV8Function(); |
| 232 } |
| 233 |
| 234 ScriptValue call(ScriptValue value) override |
| 235 { |
| 236 DCHECK(!value.isEmpty()); |
| 237 *m_value = value; |
| 238 return value; |
| 239 } |
| 240 |
| 241 private: |
| 242 PaymentResponseFunction(ScriptState* scriptState, ScriptValue* outValue) |
| 243 : ScriptFunction(scriptState) |
| 244 , m_value(outValue) |
| 245 { |
| 246 DCHECK(m_value); |
| 247 } |
| 248 |
| 249 ScriptValue* m_value; |
| 250 }; |
| 251 |
| 325 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShip
pingAddressInResponse) | 252 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShip
pingAddressInResponse) |
| 326 { | 253 { |
| 327 PaymentOptions options; | 254 PaymentOptions options; |
| 328 options.setRequestShipping(true); | 255 options.setRequestShipping(true); |
| 329 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); | 256 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 330 EXPECT_FALSE(getExceptionState().hadException()); | 257 EXPECT_FALSE(getExceptionState().hadException()); |
| 331 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); | 258 mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest(); |
| 332 response->shipping_address = mojom::blink::PaymentAddress::New(); | 259 response->shipping_address = mojom::blink::PaymentAddress::New(); |
| 333 response->shipping_address->country = "US"; | 260 response->shipping_address->country = "US"; |
| 334 response->shipping_address->language_code = "en"; | 261 response->shipping_address->language_code = "en"; |
| 335 response->shipping_address->script_code = "Latn"; | 262 response->shipping_address->script_code = "Latn"; |
| 336 | 263 |
| 337 ScriptValue outValue; | 264 ScriptValue outValue; |
| 338 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri
ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | 265 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri
ptState(), &outValue), expectNoCall()); |
| 339 | 266 |
| 340 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 267 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 341 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | 268 firePromiseCallbacks(); |
| 342 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState(
)->isolate(), outValue.v8Value()); | 269 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState(
)->isolate(), outValue.v8Value()); |
| 343 | 270 |
| 344 EXPECT_EQ("US", pr->shippingAddress()->country()); | 271 EXPECT_EQ("US", pr->shippingAddress()->country()); |
| 345 EXPECT_EQ("en-Latn", pr->shippingAddress()->languageCode()); | 272 EXPECT_EQ("en-Latn", pr->shippingAddress()->languageCode()); |
| 346 } | 273 } |
| 347 | 274 |
| 348 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingFalseAndEmptyShi
ppingAddressInResponse) | 275 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingFalseAndEmptyShi
ppingAddressInResponse) |
| 349 { | 276 { |
| 350 PaymentOptions options; | 277 PaymentOptions options; |
| 351 options.setRequestShipping(false); | 278 options.setRequestShipping(false); |
| 352 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); | 279 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 353 EXPECT_FALSE(getExceptionState().hadException()); | 280 EXPECT_FALSE(getExceptionState().hadException()); |
| 354 | 281 |
| 355 ScriptValue outValue; | 282 ScriptValue outValue; |
| 356 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri
ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); | 283 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri
ptState(), &outValue), expectNoCall()); |
| 357 | 284 |
| 358 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 285 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 359 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); | 286 firePromiseCallbacks(); |
| 360 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState(
)->isolate(), outValue.v8Value()); | 287 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState(
)->isolate(), outValue.v8Value()); |
| 361 | 288 |
| 362 EXPECT_EQ(nullptr, pr->shippingAddress()); | 289 EXPECT_EQ(nullptr, pr->shippingAddress()); |
| 363 } | 290 } |
| 364 | 291 |
| 365 TEST_F(PaymentRequestTest, OnShippingOptionChange) | 292 TEST_F(PaymentRequestTest, OnShippingOptionChange) |
| 366 { | 293 { |
| 367 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 294 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 368 EXPECT_FALSE(getExceptionState().hadException()); | 295 EXPECT_FALSE(getExceptionState().hadException()); |
| 369 | 296 |
| 370 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 297 request->show(getScriptState()).then(expectNoCall(), expectNoCall()); |
| 371 | 298 |
| 372 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingOptionC
hange("standardShipping"); | 299 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingOptionC
hange("standardShipping"); |
| 373 } | 300 } |
| 374 | 301 |
| 375 TEST_F(PaymentRequestTest, CannotCallShowTwice) | 302 TEST_F(PaymentRequestTest, CannotCallShowTwice) |
| 376 { | 303 { |
| 377 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 304 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 378 EXPECT_FALSE(getExceptionState().hadException()); | 305 EXPECT_FALSE(getExceptionState().hadException()); |
| 379 request->show(getScriptState()); | 306 request->show(getScriptState()); |
| 380 | 307 |
| 381 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 308 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 382 } | 309 } |
| 383 | 310 |
| 384 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) | 311 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) |
| 385 { | 312 { |
| 386 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 313 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 387 EXPECT_FALSE(getExceptionState().hadException()); | 314 EXPECT_FALSE(getExceptionState().hadException()); |
| 388 request->show(getScriptState()); | 315 request->show(getScriptState()); |
| 389 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 316 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 390 request->complete(getScriptState(), false); | 317 request->complete(getScriptState(), false); |
| 391 | 318 |
| 392 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 319 request->complete(getScriptState(), true).then(expectNoCall(), expectCall())
; |
| 393 } | 320 } |
| 394 | 321 |
| 395 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) | 322 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) |
| 396 { | 323 { |
| 397 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 324 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 398 EXPECT_FALSE(getExceptionState().hadException()); | 325 EXPECT_FALSE(getExceptionState().hadException()); |
| 399 | 326 |
| 400 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 327 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 401 | 328 |
| 402 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 329 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 403 } | 330 } |
| 404 | 331 |
| 405 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) | 332 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) |
| 406 { | 333 { |
| 407 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 334 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 408 EXPECT_FALSE(getExceptionState().hadException()); | 335 EXPECT_FALSE(getExceptionState().hadException()); |
| 409 request->show(getScriptState()); | 336 request->show(getScriptState()); |
| 410 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 337 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 411 | 338 |
| 412 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 339 request->complete(getScriptState(), true).then(expectNoCall(), expectCall())
; |
| 413 | 340 |
| 414 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 341 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 415 } | 342 } |
| 416 | 343 |
| 417 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) | 344 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) |
| 418 { | 345 { |
| 419 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 346 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 420 EXPECT_FALSE(getExceptionState().hadException()); | 347 EXPECT_FALSE(getExceptionState().hadException()); |
| 421 request->show(getScriptState()); | 348 request->show(getScriptState()); |
| 422 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 349 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 423 | 350 |
| 424 request->complete(getScriptState(), true).then(MockFunction::expectCall(getS
criptState()), MockFunction::expectNoCall(getScriptState())); | 351 request->complete(getScriptState(), true).then(expectCall(), expectNoCall())
; |
| 425 | 352 |
| 426 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); | 353 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); |
| 427 } | 354 } |
| 428 | 355 |
| 429 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) | 356 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) |
| 430 { | 357 { |
| 431 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 358 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 432 EXPECT_FALSE(getExceptionState().hadException()); | 359 EXPECT_FALSE(getExceptionState().hadException()); |
| 433 | 360 |
| 434 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 361 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 435 | 362 |
| 436 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 363 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
| 437 } | 364 } |
| 438 | 365 |
| 439 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) | 366 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) |
| 440 { | 367 { |
| 441 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 368 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 442 EXPECT_FALSE(getExceptionState().hadException()); | 369 EXPECT_FALSE(getExceptionState().hadException()); |
| 443 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 370 request->show(getScriptState()).then(expectCall(), expectNoCall()); |
| 444 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 371 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 445 | 372 |
| 446 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 373 request->complete(getScriptState(), true).then(expectNoCall(), expectCall())
; |
| 447 | 374 |
| 448 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 375 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
| 449 } | 376 } |
| 450 | 377 |
| 451 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) | 378 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) |
| 452 { | 379 { |
| 453 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 380 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 454 EXPECT_FALSE(getExceptionState().hadException()); | 381 EXPECT_FALSE(getExceptionState().hadException()); |
| 455 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 382 request->show(getScriptState()).then(expectCall(), expectNoCall()); |
| 456 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); | 383 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(buildPaymentResponseForTest()); |
| 457 | 384 |
| 458 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "foo")); | 385 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "foo")); |
| 459 } | 386 } |
| 460 | 387 |
| 461 TEST_F(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) | 388 TEST_F(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) |
| 462 { | 389 { |
| 463 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 390 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 464 EXPECT_FALSE(getExceptionState().hadException()); | 391 EXPECT_FALSE(getExceptionState().hadException()); |
| 465 | 392 |
| 466 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 393 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 467 | 394 |
| 468 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "NotPaym
entDetails")); | 395 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "NotPaym
entDetails")); |
| 469 } | 396 } |
| 470 | 397 |
| 471 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) | 398 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) |
| 472 { | 399 { |
| 473 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); | 400 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 474 EXPECT_FALSE(getExceptionState().hadException()); | 401 EXPECT_FALSE(getExceptionState().hadException()); |
| 475 | 402 |
| 476 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 403 request->show(getScriptState()).then(expectNoCall(), expectCall()); |
| 477 | 404 |
| 478 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), "{}", getExceptionState()))); | 405 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), "{}", getExceptionState()))); |
| 479 EXPECT_FALSE(getExceptionState().hadException()); | 406 EXPECT_FALSE(getExceptionState().hadException()); |
| 480 } | 407 } |
| 481 | 408 |
| 482 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
ingOptions) | 409 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
ingOptions) |
| 483 { | 410 { |
| 484 PaymentDetails details; | 411 PaymentDetails details; |
| 485 details.setTotal(buildPaymentItemForTest()); | 412 details.setTotal(buildPaymentItemForTest()); |
| 486 PaymentOptions options; | 413 PaymentOptions options; |
| 487 options.setRequestShipping(true); | 414 options.setRequestShipping(true); |
| 488 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); | 415 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 489 EXPECT_FALSE(getExceptionState().hadException()); | 416 EXPECT_FALSE(getExceptionState().hadException()); |
| 490 EXPECT_TRUE(request->shippingOption().isNull()); | 417 EXPECT_TRUE(request->shippingOption().isNull()); |
| 491 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 418 request->show(getScriptState()).then(expectNoCall(), expectNoCall()); |
| 492 String detailWithShippingOptions = "{\"total\": {\"label\": \"Total\", \"amo
unt\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 419 String detailWithShippingOptions = "{\"total\": {\"label\": \"Total\", \"amo
unt\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 493 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"},
\"selected\": true}]}"; | 420 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"},
\"selected\": true}]}"; |
| 494 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); | 421 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); |
| 495 EXPECT_FALSE(getExceptionState().hadException()); | 422 EXPECT_FALSE(getExceptionState().hadException()); |
| 496 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 423 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| 497 String detailWithoutShippingOptions = "{\"total\": {\"label\": \"Total\", \"
amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}}"; | 424 String detailWithoutShippingOptions = "{\"total\": {\"label\": \"Total\", \"
amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}}"; |
| 498 | 425 |
| 499 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); | 426 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); |
| 500 | 427 |
| 501 EXPECT_FALSE(getExceptionState().hadException()); | 428 EXPECT_FALSE(getExceptionState().hadException()); |
| 502 EXPECT_TRUE(request->shippingOption().isNull()); | 429 EXPECT_TRUE(request->shippingOption().isNull()); |
| 503 } | 430 } |
| 504 | 431 |
| 505 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
UnselectedShippingOptions) | 432 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
UnselectedShippingOptions) |
| 506 { | 433 { |
| 507 PaymentOptions options; | 434 PaymentOptions options; |
| 508 options.setRequestShipping(true); | 435 options.setRequestShipping(true); |
| 509 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); | 436 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 510 EXPECT_FALSE(getExceptionState().hadException()); | 437 EXPECT_FALSE(getExceptionState().hadException()); |
| 511 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 438 request->show(getScriptState()).then(expectNoCall(), expectNoCall()); |
| 512 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," | 439 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," |
| 513 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 440 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 514 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; | 441 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; |
| 515 | 442 |
| 516 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 443 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 517 EXPECT_FALSE(getExceptionState().hadException()); | 444 EXPECT_FALSE(getExceptionState().hadException()); |
| 518 | 445 |
| 519 EXPECT_TRUE(request->shippingOption().isNull()); | 446 EXPECT_TRUE(request->shippingOption().isNull()); |
| 520 } | 447 } |
| 521 | 448 |
| 522 TEST_F(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) | 449 TEST_F(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) |
| 523 { | 450 { |
| 524 PaymentOptions options; | 451 PaymentOptions options; |
| 525 options.setRequestShipping(true); | 452 options.setRequestShipping(true); |
| 526 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); | 453 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 527 EXPECT_FALSE(getExceptionState().hadException()); | 454 EXPECT_FALSE(getExceptionState().hadException()); |
| 528 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 455 request->show(getScriptState()).then(expectNoCall(), expectNoCall()); |
| 529 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," | 456 String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\
": \"USD\", \"value\": \"5.00\"}}," |
| 530 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 457 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 531 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 458 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 532 | 459 |
| 533 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 460 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 534 EXPECT_FALSE(getExceptionState().hadException()); | 461 EXPECT_FALSE(getExceptionState().hadException()); |
| 535 | 462 |
| 536 EXPECT_EQ("fast", request->shippingOption()); | 463 EXPECT_EQ("fast", request->shippingOption()); |
| 537 } | 464 } |
| 538 | 465 |
| 539 } // namespace | 466 } // namespace |
| 540 } // namespace blink | 467 } // namespace blink |
| OLD | NEW |