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

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

Issue 2192413002: Timeout if website never completes the transaction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marijn's comments Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 // Tests for PaymentRequest::complete().
6
7 #include "bindings/core/v8/V8BindingForTesting.h"
8 #include "modules/payments/PaymentRequest.h"
9 #include "modules/payments/PaymentTestHelper.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace blink {
13 namespace {
14
15 TEST(CompleteTest, CannotCallCompleteTwice)
16 {
17 V8TestingScope scope;
18 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
19 makePaymentRequestOriginSecure(scope.document());
20 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
21 EXPECT_FALSE(scope.getExceptionState().hadException());
22 request->show(scope.getScriptState());
23 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
24 request->complete(scope.getScriptState(), PaymentCompleter::Fail);
25
26 request->complete(scope.getScriptState(), PaymentCompleter::Success).then(fu ncs.expectNoCall(), funcs.expectCall());
27 }
28
29 TEST(CompleteTest, RejectCompletePromiseOnError)
30 {
31 V8TestingScope scope;
32 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
33 makePaymentRequestOriginSecure(scope.document());
34 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
35 EXPECT_FALSE(scope.getExceptionState().hadException());
36 request->show(scope.getScriptState());
37 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
38
39 String errorMessage;
40 request->complete(scope.getScriptState(), PaymentCompleter::Success).then(fu ncs.expectNoCall(), funcs.expectCall(&errorMessage));
41
42 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::UNKNOWN);
43
44 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
45 EXPECT_EQ("UnknownError: Request failed", errorMessage);
46 }
47
48 // If user cancels the transaction during processing, the complete() promise
49 // should be rejected.
50 TEST(CompleteTest, RejectCompletePromiseAfterError)
51 {
52 V8TestingScope scope;
53 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
54 makePaymentRequestOriginSecure(scope.document());
55 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
56 EXPECT_FALSE(scope.getExceptionState().hadException());
57 request->show(scope.getScriptState());
58 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
59 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::bl ink::PaymentErrorReason::USER_CANCEL);
60
61 request->complete(scope.getScriptState(), PaymentCompleter::Success).then(fu ncs.expectNoCall(), funcs.expectCall());
62 }
63
64 TEST(CompleteTest, ResolvePromiseOnComplete)
65 {
66 V8TestingScope scope;
67 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
68 makePaymentRequestOriginSecure(scope.document());
69 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
70 EXPECT_FALSE(scope.getExceptionState().hadException());
71 request->show(scope.getScriptState());
72 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
73
74 request->complete(scope.getScriptState(), PaymentCompleter::Success).then(fu ncs.expectCall(), funcs.expectNoCall());
75
76 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete();
77 }
78
79 TEST(CompleteTest, RejectCompletePromiseOnUpdateDetailsFailure)
80 {
81 V8TestingScope scope;
82 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
83 makePaymentRequestOriginSecure(scope.document());
84 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
85 EXPECT_FALSE(scope.getExceptionState().hadException());
86 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN oCall());
87 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
88
89 String errorMessage;
90 request->complete(scope.getScriptState(), PaymentCompleter::Success).then(fu ncs.expectNoCall(), funcs.expectCall(&errorMessage));
91
92 request->onUpdatePaymentDetailsFailure("oops");
93
94 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
95 EXPECT_EQ("AbortError: oops", errorMessage);
96 }
97
98 TEST(CompleteTest, RejectCompletePromiseAfterTimeout)
99 {
100 V8TestingScope scope;
101 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
102 makePaymentRequestOriginSecure(scope.document());
103 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
104 EXPECT_FALSE(scope.getExceptionState().hadException());
105 request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectN oCall());
106 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse (buildPaymentResponseForTest());
107 request->onCompleteTimeoutForTesting();
108
109 String errorMessage;
110 request->complete(scope.getScriptState(), PaymentCompleter::Success).then(fu ncs.expectNoCall(), funcs.expectCall(&errorMessage));
111
112 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
113 EXPECT_EQ("InvalidStateError: Timed out after 60 seconds, complete() called too late", errorMessage);
114 }
115
116 } // namespace
117 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/modules.gypi ('k') | third_party/WebKit/Source/modules/payments/PaymentCompleter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698