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

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

Issue 2163193002: Reject payment request with AbortError if web page rejects promise from updateWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentRequest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/JSONValuesForV8.h" 7 #include "bindings/core/v8/JSONValuesForV8.h"
8 #include "bindings/core/v8/V8BindingForTesting.h" 8 #include "bindings/core/v8/V8BindingForTesting.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 322 }
323 323
324 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) 324 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure)
325 { 325 {
326 V8TestingScope scope; 326 V8TestingScope scope;
327 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 327 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
328 makePaymentRequestOriginSecure(scope.document()); 328 makePaymentRequestOriginSecure(scope.document());
329 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 329 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
330 EXPECT_FALSE(scope.getExceptionState().hadException()); 330 EXPECT_FALSE(scope.getExceptionState().hadException());
331 331
332 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); 332 String errorMessage;
333 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall(&errorMessage));
333 334
334 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat e(), "oops")); 335 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat e(), "oops"));
336
337 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
338 EXPECT_EQ("AbortError: oops", errorMessage);
335 } 339 }
336 340
337 TEST(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) 341 TEST(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure)
338 { 342 {
339 V8TestingScope scope; 343 V8TestingScope scope;
340 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 344 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
341 makePaymentRequestOriginSecure(scope.document()); 345 makePaymentRequestOriginSecure(scope.document());
342 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 346 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
343 EXPECT_FALSE(scope.getExceptionState().hadException()); 347 EXPECT_FALSE(scope.getExceptionState().hadException());
344 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN oCall()); 348 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN oCall());
345 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); 349 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
346 350
347 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); 351 String errorMessage;
352 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall(&errorMessage));
348 353
349 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat e(), "oops")); 354 request->onUpdatePaymentDetailsFailure(ScriptValue::from(scope.getScriptStat e(), "oops"));
355
356 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
357 EXPECT_EQ("AbortError: oops", errorMessage);
350 } 358 }
351 359
352 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) 360 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved)
353 { 361 {
354 V8TestingScope scope; 362 V8TestingScope scope;
355 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 363 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
356 makePaymentRequestOriginSecure(scope.document()); 364 makePaymentRequestOriginSecure(scope.document());
357 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 365 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
358 EXPECT_FALSE(scope.getExceptionState().hadException()); 366 EXPECT_FALSE(scope.getExceptionState().hadException());
359 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN oCall()); 367 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN oCall());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 "{\"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}]}";
451 459
452 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); 460 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState())));
453 EXPECT_FALSE(scope.getExceptionState().hadException()); 461 EXPECT_FALSE(scope.getExceptionState().hadException());
454 462
455 EXPECT_EQ("fast", request->shippingOption()); 463 EXPECT_EQ("fast", request->shippingOption());
456 } 464 }
457 465
458 } // namespace 466 } // namespace
459 } // namespace blink 467 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentRequest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698