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

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

Issue 2083883003: Reject PaymentResponse.complete() promise on error. (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/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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 258 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
259 EXPECT_FALSE(scope.getExceptionState().hadException()); 259 EXPECT_FALSE(scope.getExceptionState().hadException());
260 request->show(scope.getScriptState()); 260 request->show(scope.getScriptState());
261 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); 261 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
262 262
263 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); 263 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall());
264 264
265 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); 265 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError();
266 } 266 }
267 267
268 // If user cancels the transaction during processing, the complete() promise
269 // should be rejected.
270 TEST(PaymentRequestTest, RejectCompletePromiseAfterError)
271 {
272 V8TestingScope scope;
273 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
274 makePaymentRequestOriginSecure(scope.document());
275 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
276 EXPECT_FALSE(scope.getExceptionState().hadException());
277 request->show(scope.getScriptState());
278 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
279 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError();
280
281 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall());
282 }
283
268 TEST(PaymentRequestTest, ResolvePromiseOnComplete) 284 TEST(PaymentRequestTest, ResolvePromiseOnComplete)
269 { 285 {
270 V8TestingScope scope; 286 V8TestingScope scope;
271 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 287 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
272 makePaymentRequestOriginSecure(scope.document()); 288 makePaymentRequestOriginSecure(scope.document());
273 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 289 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
274 EXPECT_FALSE(scope.getExceptionState().hadException()); 290 EXPECT_FALSE(scope.getExceptionState().hadException());
275 request->show(scope.getScriptState()); 291 request->show(scope.getScriptState());
276 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); 292 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
277 293
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; 425 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}";
410 426
411 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); 427 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState())));
412 EXPECT_FALSE(scope.getExceptionState().hadException()); 428 EXPECT_FALSE(scope.getExceptionState().hadException());
413 429
414 EXPECT_EQ("fast", request->shippingOption()); 430 EXPECT_EQ("fast", request->shippingOption());
415 } 431 }
416 432
417 } // namespace 433 } // namespace
418 } // namespace blink 434 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698