| 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 "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 217 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 218 } | 218 } |
| 219 | 219 |
| 220 TEST_F(PaymentRequestTest, DontRejectShowPromiseForValidShippingAddress) | 220 TEST_F(PaymentRequestTest, DontRejectShowPromiseForValidShippingAddress) |
| 221 { | 221 { |
| 222 ScriptState::Scope scope(getScriptState()); | 222 ScriptState::Scope scope(getScriptState()); |
| 223 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 223 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
| 224 EXPECT_FALSE(getExceptionState().hadException()); | 224 EXPECT_FALSE(getExceptionState().hadException()); |
| 225 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre
ss::New(); | 225 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre
ss::New(); |
| 226 shippingAddress->region_code = "US"; | 226 shippingAddress->country = "US"; |
| 227 shippingAddress->language_code = "en"; | 227 shippingAddress->language_code = "en"; |
| 228 shippingAddress->script_code = "Latn"; | 228 shippingAddress->script_code = "Latn"; |
| 229 | 229 |
| 230 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 230 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 231 | 231 |
| 232 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); | 232 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); |
| 233 } | 233 } |
| 234 | 234 |
| 235 TEST_F(PaymentRequestTest, ResolveShowPromiseWithValidShippingAddressInResponse) | 235 TEST_F(PaymentRequestTest, ResolveShowPromiseWithValidShippingAddressInResponse) |
| 236 { | 236 { |
| 237 ScriptState::Scope scope(getScriptState()); | 237 ScriptState::Scope scope(getScriptState()); |
| 238 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 238 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); |
| 239 EXPECT_FALSE(getExceptionState().hadException()); | 239 EXPECT_FALSE(getExceptionState().hadException()); |
| 240 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 240 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 241 response->shipping_address = mojom::blink::PaymentAddress::New(); | 241 response->shipping_address = mojom::blink::PaymentAddress::New(); |
| 242 response->shipping_address->region_code = "US"; | 242 response->shipping_address->country = "US"; |
| 243 response->shipping_address->language_code = "en"; | 243 response->shipping_address->language_code = "en"; |
| 244 response->shipping_address->script_code = "Latn"; | 244 response->shipping_address->script_code = "Latn"; |
| 245 | 245 |
| 246 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 246 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 247 | 247 |
| 248 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 248 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 249 } | 249 } |
| 250 | 250 |
| 251 TEST_F(PaymentRequestTest, ResolveShowPromiseWithoutShippingAddressInResponse) | 251 TEST_F(PaymentRequestTest, ResolveShowPromiseWithoutShippingAddressInResponse) |
| 252 { | 252 { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; | 441 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; |
| 442 | 442 |
| 443 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 443 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 444 EXPECT_FALSE(getExceptionState().hadException()); | 444 EXPECT_FALSE(getExceptionState().hadException()); |
| 445 | 445 |
| 446 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 446 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| 447 } | 447 } |
| 448 | 448 |
| 449 } // namespace | 449 } // namespace |
| 450 } // namespace blink | 450 } // namespace blink |
| OLD | NEW |