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

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

Issue 2697123003: Use ExecutionContext instead of Document in PaymentRequest constructor. (Closed)
Patch Set: ExecutionContext in constructor only Created 3 years, 10 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 | « no previous file | third_party/WebKit/Source/modules/payments/CanMakePaymentTest.cpp » ('j') | 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 // Tests for PaymentRequest::abort(). 5 // Tests for PaymentRequest::abort().
6 6
7 #include "bindings/core/v8/V8BindingForTesting.h" 7 #include "bindings/core/v8/V8BindingForTesting.h"
8 #include "modules/payments/PaymentRequest.h" 8 #include "modules/payments/PaymentRequest.h"
9 #include "modules/payments/PaymentTestHelper.h" 9 #include "modules/payments/PaymentTestHelper.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace blink { 12 namespace blink {
13 namespace { 13 namespace {
14 14
15 // If request.abort() is called without calling request.show() first, then 15 // If request.abort() is called without calling request.show() first, then
16 // abort() should reject with exception. 16 // abort() should reject with exception.
17 TEST(AbortTest, CannotAbortBeforeShow) { 17 TEST(AbortTest, CannotAbortBeforeShow) {
18 V8TestingScope scope; 18 V8TestingScope scope;
19 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 19 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
20 makePaymentRequestOriginSecure(scope.document()); 20 makePaymentRequestOriginSecure(scope.document());
21 PaymentRequest* request = PaymentRequest::create( 21 PaymentRequest* request = PaymentRequest::create(
22 scope.document(), buildPaymentMethodDataForTest(), 22 scope.getExecutionContext(), buildPaymentMethodDataForTest(),
23 buildPaymentDetailsForTest(), scope.getExceptionState()); 23 buildPaymentDetailsForTest(), scope.getExceptionState());
24 24
25 request->abort(scope.getScriptState()) 25 request->abort(scope.getScriptState())
26 .then(funcs.expectNoCall(), funcs.expectCall()); 26 .then(funcs.expectNoCall(), funcs.expectCall());
27 } 27 }
28 28
29 // If request.abort() is called again before the previous abort() resolved, then 29 // If request.abort() is called again before the previous abort() resolved, then
30 // the second abort() should reject with exception. 30 // the second abort() should reject with exception.
31 TEST(AbortTest, CannotAbortTwiceConcurrently) { 31 TEST(AbortTest, CannotAbortTwiceConcurrently) {
32 V8TestingScope scope; 32 V8TestingScope scope;
33 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 33 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
34 makePaymentRequestOriginSecure(scope.document()); 34 makePaymentRequestOriginSecure(scope.document());
35 PaymentRequest* request = PaymentRequest::create( 35 PaymentRequest* request = PaymentRequest::create(
36 scope.document(), buildPaymentMethodDataForTest(), 36 scope.getExecutionContext(), buildPaymentMethodDataForTest(),
37 buildPaymentDetailsForTest(), scope.getExceptionState()); 37 buildPaymentDetailsForTest(), scope.getExceptionState());
38 request->show(scope.getScriptState()); 38 request->show(scope.getScriptState());
39 request->abort(scope.getScriptState()); 39 request->abort(scope.getScriptState());
40 40
41 request->abort(scope.getScriptState()) 41 request->abort(scope.getScriptState())
42 .then(funcs.expectNoCall(), funcs.expectCall()); 42 .then(funcs.expectNoCall(), funcs.expectCall());
43 } 43 }
44 44
45 // If request.abort() is called after calling request.show(), then abort() 45 // If request.abort() is called after calling request.show(), then abort()
46 // should not reject with exception. 46 // should not reject with exception.
47 TEST(AbortTest, CanAbortAfterShow) { 47 TEST(AbortTest, CanAbortAfterShow) {
48 V8TestingScope scope; 48 V8TestingScope scope;
49 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 49 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
50 makePaymentRequestOriginSecure(scope.document()); 50 makePaymentRequestOriginSecure(scope.document());
51 PaymentRequest* request = PaymentRequest::create( 51 PaymentRequest* request = PaymentRequest::create(
52 scope.document(), buildPaymentMethodDataForTest(), 52 scope.getExecutionContext(), buildPaymentMethodDataForTest(),
53 buildPaymentDetailsForTest(), scope.getExceptionState()); 53 buildPaymentDetailsForTest(), scope.getExceptionState());
54 request->show(scope.getScriptState()); 54 request->show(scope.getScriptState());
55 55
56 request->abort(scope.getScriptState()) 56 request->abort(scope.getScriptState())
57 .then(funcs.expectNoCall(), funcs.expectNoCall()); 57 .then(funcs.expectNoCall(), funcs.expectNoCall());
58 } 58 }
59 59
60 // If the browser is unable to abort the payment, then the request.abort() 60 // If the browser is unable to abort the payment, then the request.abort()
61 // promise should be rejected. 61 // promise should be rejected.
62 TEST(AbortTest, FailedAbortShouldRejectAbortPromise) { 62 TEST(AbortTest, FailedAbortShouldRejectAbortPromise) {
63 V8TestingScope scope; 63 V8TestingScope scope;
64 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 64 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
65 makePaymentRequestOriginSecure(scope.document()); 65 makePaymentRequestOriginSecure(scope.document());
66 PaymentRequest* request = PaymentRequest::create( 66 PaymentRequest* request = PaymentRequest::create(
67 scope.document(), buildPaymentMethodDataForTest(), 67 scope.getExecutionContext(), buildPaymentMethodDataForTest(),
68 buildPaymentDetailsForTest(), scope.getExceptionState()); 68 buildPaymentDetailsForTest(), scope.getExceptionState());
69 request->show(scope.getScriptState()); 69 request->show(scope.getScriptState());
70 70
71 request->abort(scope.getScriptState()) 71 request->abort(scope.getScriptState())
72 .then(funcs.expectNoCall(), funcs.expectCall()); 72 .then(funcs.expectNoCall(), funcs.expectCall());
73 73
74 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( 74 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort(
75 false); 75 false);
76 } 76 }
77 77
78 // After the browser is unable to abort the payment once, the second abort() 78 // After the browser is unable to abort the payment once, the second abort()
79 // call should not be rejected, as it's not a duplicate request anymore. 79 // call should not be rejected, as it's not a duplicate request anymore.
80 TEST(AbortTest, CanAbortAgainAfterFirstAbortRejected) { 80 TEST(AbortTest, CanAbortAgainAfterFirstAbortRejected) {
81 V8TestingScope scope; 81 V8TestingScope scope;
82 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 82 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
83 makePaymentRequestOriginSecure(scope.document()); 83 makePaymentRequestOriginSecure(scope.document());
84 PaymentRequest* request = PaymentRequest::create( 84 PaymentRequest* request = PaymentRequest::create(
85 scope.document(), buildPaymentMethodDataForTest(), 85 scope.getExecutionContext(), buildPaymentMethodDataForTest(),
86 buildPaymentDetailsForTest(), scope.getExceptionState()); 86 buildPaymentDetailsForTest(), scope.getExceptionState());
87 request->show(scope.getScriptState()); 87 request->show(scope.getScriptState());
88 request->abort(scope.getScriptState()); 88 request->abort(scope.getScriptState());
89 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( 89 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort(
90 false); 90 false);
91 91
92 request->abort(scope.getScriptState()) 92 request->abort(scope.getScriptState())
93 .then(funcs.expectNoCall(), funcs.expectNoCall()); 93 .then(funcs.expectNoCall(), funcs.expectNoCall());
94 } 94 }
95 95
96 // If the browser successfully aborts the payment, then the request.show() 96 // If the browser successfully aborts the payment, then the request.show()
97 // promise should be rejected, and request.abort() promise should be resolved. 97 // promise should be rejected, and request.abort() promise should be resolved.
98 TEST(AbortTest, SuccessfulAbortShouldRejectShowPromiseAndResolveAbortPromise) { 98 TEST(AbortTest, SuccessfulAbortShouldRejectShowPromiseAndResolveAbortPromise) {
99 V8TestingScope scope; 99 V8TestingScope scope;
100 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); 100 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
101 makePaymentRequestOriginSecure(scope.document()); 101 makePaymentRequestOriginSecure(scope.document());
102 PaymentRequest* request = PaymentRequest::create( 102 PaymentRequest* request = PaymentRequest::create(
103 scope.document(), buildPaymentMethodDataForTest(), 103 scope.getExecutionContext(), buildPaymentMethodDataForTest(),
104 buildPaymentDetailsForTest(), scope.getExceptionState()); 104 buildPaymentDetailsForTest(), scope.getExceptionState());
105 105
106 request->show(scope.getScriptState()) 106 request->show(scope.getScriptState())
107 .then(funcs.expectNoCall(), funcs.expectCall()); 107 .then(funcs.expectNoCall(), funcs.expectCall());
108 request->abort(scope.getScriptState()) 108 request->abort(scope.getScriptState())
109 .then(funcs.expectCall(), funcs.expectNoCall()); 109 .then(funcs.expectCall(), funcs.expectNoCall());
110 110
111 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( 111 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort(
112 true); 112 true);
113 } 113 }
114 114
115 } // namespace 115 } // namespace
116 } // namespace blink 116 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/payments/CanMakePaymentTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698