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

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

Issue 2145553002: Parameterize OnError method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Parameterize OnError method. 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
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 238 }
239 239
240 TEST(PaymentRequestTest, RejectShowPromiseOnError) 240 TEST(PaymentRequestTest, RejectShowPromiseOnError)
241 { 241 {
242 V8TestingScope scope; 242 V8TestingScope scope;
243 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 243 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
244 makePaymentRequestOriginSecure(scope.document()); 244 makePaymentRequestOriginSecure(scope.document());
245 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 245 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
246 EXPECT_FALSE(scope.getExceptionState().hadException()); 246 EXPECT_FALSE(scope.getExceptionState().hadException());
247 247
248 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall()); 248 String onRejected;
249 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall(&onRejected));
249 250
250 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); 251 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::NOT_SUPPORTED);
252 EXPECT_TRUE(onRejected.isNull());
please use gerrit instead 2016/07/12 15:57:35 Remove this EXPECT_TRUE(onRejected.isNull()) check
pals 2016/07/13 05:54:27 Done.
253
254 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
255 EXPECT_EQ("NotSupportedError: The payment method is not supported.", onRejec ted);
251 } 256 }
252 257
253 TEST(PaymentRequestTest, RejectCompletePromiseOnError) 258 TEST(PaymentRequestTest, RejectCompletePromiseOnError)
254 { 259 {
255 V8TestingScope scope; 260 V8TestingScope scope;
256 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 261 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
257 makePaymentRequestOriginSecure(scope.document()); 262 makePaymentRequestOriginSecure(scope.document());
258 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 263 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
259 EXPECT_FALSE(scope.getExceptionState().hadException()); 264 EXPECT_FALSE(scope.getExceptionState().hadException());
260 request->show(scope.getScriptState()); 265 request->show(scope.getScriptState());
261 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); 266 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
262 267
263 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); 268 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall());
264 269
265 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); 270 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::UNKNOWN);
266 } 271 }
267 272
268 // If user cancels the transaction during processing, the complete() promise 273 // If user cancels the transaction during processing, the complete() promise
269 // should be rejected. 274 // should be rejected.
270 TEST(PaymentRequestTest, RejectCompletePromiseAfterError) 275 TEST(PaymentRequestTest, RejectCompletePromiseAfterError)
271 { 276 {
272 V8TestingScope scope; 277 V8TestingScope scope;
273 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 278 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
274 makePaymentRequestOriginSecure(scope.document()); 279 makePaymentRequestOriginSecure(scope.document());
275 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 280 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
276 EXPECT_FALSE(scope.getExceptionState().hadException()); 281 EXPECT_FALSE(scope.getExceptionState().hadException());
277 request->show(scope.getScriptState()); 282 request->show(scope.getScriptState());
278 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest()); 283 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
279 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); 284 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::USER_CANCEL);
280 285
281 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall()); 286 request->complete(scope.getScriptState(), Success).then(funcs.expectNoCall() , funcs.expectCall());
282 } 287 }
283 288
284 TEST(PaymentRequestTest, ResolvePromiseOnComplete) 289 TEST(PaymentRequestTest, ResolvePromiseOnComplete)
285 { 290 {
286 V8TestingScope scope; 291 V8TestingScope scope;
287 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 292 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
288 makePaymentRequestOriginSecure(scope.document()); 293 makePaymentRequestOriginSecure(scope.document());
289 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate()); 294 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}"; 430 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US D\", \"value\": \"50.00\"}, \"selected\": true}]}";
426 431
427 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState()))); 432 request->onUpdatePaymentDetails(ScriptValue::from(scope.getScriptState(), fr omJSONString(scope.getScriptState(), detail, scope.getExceptionState())));
428 EXPECT_FALSE(scope.getExceptionState().hadException()); 433 EXPECT_FALSE(scope.getExceptionState().hadException());
429 434
430 EXPECT_EQ("fast", request->shippingOption()); 435 EXPECT_EQ("fast", request->shippingOption());
431 } 436 }
432 437
433 } // namespace 438 } // namespace
434 } // namespace blink 439 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698