Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp

Issue 2039863002: PaymentRequest: Sync up PaymentAddress with the payment request spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 262 }
263 263
264 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingA ddressExistsInResponse) 264 TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingA ddressExistsInResponse)
265 { 265 {
266 ScriptState::Scope scope(getScriptState()); 266 ScriptState::Scope scope(getScriptState());
267 PaymentOptions options; 267 PaymentOptions options;
268 options.setRequestShipping(false); 268 options.setRequestShipping(false);
269 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); 269 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
270 EXPECT_FALSE(getExceptionState().hadException()); 270 EXPECT_FALSE(getExceptionState().hadException());
271 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre ss::New(); 271 mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddre ss::New();
272 shippingAddress->region_code = "US"; 272 shippingAddress->country = "US";
273 shippingAddress->language_code = "en"; 273 shippingAddress->language_code = "en";
274 shippingAddress->script_code = "Latn"; 274 shippingAddress->script_code = "Latn";
275 275
276 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState())); 276 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta te()), MockFunction::expectCall(getScriptState()));
277 277
278 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress Change(std::move(shippingAddress)); 278 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress Change(std::move(shippingAddress));
279 } 279 }
280 280
281 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShip pingAddressInResponse) 281 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShip pingAddressInResponse)
282 { 282 {
283 ScriptState::Scope scope(getScriptState()); 283 ScriptState::Scope scope(getScriptState());
284 PaymentOptions options; 284 PaymentOptions options;
285 options.setRequestShipping(true); 285 options.setRequestShipping(true);
286 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); 286 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
287 EXPECT_FALSE(getExceptionState().hadException()); 287 EXPECT_FALSE(getExceptionState().hadException());
288 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew(); 288 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N ew();
289 response->shipping_address = mojom::blink::PaymentAddress::New(); 289 response->shipping_address = mojom::blink::PaymentAddress::New();
290 response->shipping_address->region_code = "US"; 290 response->shipping_address->country = "US";
291 response->shipping_address->language_code = "en"; 291 response->shipping_address->language_code = "en";
292 response->shipping_address->script_code = "Latn"; 292 response->shipping_address->script_code = "Latn";
293 293
294 ScriptValue outValue; 294 ScriptValue outValue;
295 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState())); 295 request->show(getScriptState()).then(PaymentResponseFunction::create(getScri ptState(), &outValue), MockFunction::expectNoCall(getScriptState()));
296 296
297 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response)); 297 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (std::move(response));
298 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); 298 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate());
299 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value()); 299 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState( )->isolate(), outValue.v8Value());
300 300
301 EXPECT_EQ("US", pr->shippingAddress()->regionCode()); 301 EXPECT_EQ("US", pr->shippingAddress()->country());
302 EXPECT_EQ("en-Latn", pr->shippingAddress()->languageCode()); 302 EXPECT_EQ("en-Latn", pr->shippingAddress()->languageCode());
303 } 303 }
304 304
305 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingFalseAndEmptyShi ppingAddressInResponse) 305 TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingFalseAndEmptyShi ppingAddressInResponse)
306 { 306 {
307 ScriptState::Scope scope(getScriptState()); 307 ScriptState::Scope scope(getScriptState());
308 PaymentOptions options; 308 PaymentOptions options;
309 options.setRequestShipping(false); 309 options.setRequestShipping(false);
310 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); 310 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
311 EXPECT_FALSE(getExceptionState().hadException()); 311 EXPECT_FALSE(getExceptionState().hadException());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }"; 502 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \ "Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}] }";
503 503
504 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState()))); 504 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON String(getScriptState(), detail, getExceptionState())));
505 EXPECT_FALSE(getExceptionState().hadException()); 505 EXPECT_FALSE(getExceptionState().hadException());
506 506
507 EXPECT_EQ("standardShippingOption", request->shippingOption()); 507 EXPECT_EQ("standardShippingOption", request->shippingOption());
508 } 508 }
509 509
510 } // namespace 510 } // namespace
511 } // namespace blink 511 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698