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

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

Issue 2048823004: PaymentRequest.abort() should return a promise. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove DummyPageHolder and TrackExceptionState for haraken@ comment. 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
(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 #include "bindings/core/v8/ScriptState.h"
6 #include "modules/payments/PaymentRequest.h"
7 #include "modules/payments/PaymentRequestTestBase.h"
8 #include "modules/payments/PaymentTestHelper.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace blink {
12 namespace {
13
14 // Tests for PaymentRequest::abort().
15 class AbortTest : public PaymentRequestTestBase {
16 };
17
18 // If request.abort() is called without calling request.show() first, then
19 // abort() should reject with exception.
20 TEST_F(AbortTest, CannotAbortBeforeShow)
21 {
22 ScriptState::Scope scope(getScriptState());
23 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
24
25 request->abort(getScriptState()).then(expectNoCall(), expectCall());
26 }
27
28 // If request.abort() is called again before the previous abort() resolved, then
29 // the second abort() should reject with exception.
30 TEST_F(AbortTest, CannotAbortTwiceConcurrently)
31 {
32 ScriptState::Scope scope(getScriptState());
33 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
34 request->show(getScriptState());
35 request->abort(getScriptState());
36
37 request->abort(getScriptState()).then(expectNoCall(), expectCall());
38 }
39
40 // If request.abort() is called after calling request.show(), then abort()
41 // should not reject with exception.
42 TEST_F(AbortTest, CanAbortAfterShow)
43 {
44 ScriptState::Scope scope(getScriptState());
45 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
46 request->show(getScriptState());
47
48 request->abort(getScriptState()).then(expectNoCall(), expectNoCall());
49 }
50
51 // If the browser is unable to abort the payment, then the request.abort()
52 // promise should be rejected.
53 TEST_F(AbortTest, FailedAbortShouldRejectAbortPromise)
54 {
55 ScriptState::Scope scope(getScriptState());
56 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
57 request->show(getScriptState());
58
59 request->abort(getScriptState()).then(expectNoCall(), expectCall());
60
61 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(false);
62 }
63
64 // After the browser is unable to abort the payment once, the second abort()
65 // call should not be rejected, as it's not a duplicate request anymore.
66 TEST_F(AbortTest, CanAbortAgainAfterFirstAbortRejected)
67 {
68 ScriptState::Scope scope(getScriptState());
69 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
70 request->show(getScriptState());
71 request->abort(getScriptState());
72 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(false);
73
74 request->abort(getScriptState()).then(expectNoCall(), expectNoCall());
75 }
76
77 // If the browser successfully aborts the payment, then the request.show()
78 // promise should be rejected, and request.abort() promise should be resolved.
79 TEST_F(AbortTest, SuccessfulAbortShouldRejectShowPromiseAndResolveAbortPromise)
80 {
81 ScriptState::Scope scope(getScriptState());
82 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState());
83
84 request->show(getScriptState()).then(expectNoCall(), expectCall());
85 request->abort(getScriptState()).then(expectCall(), expectNoCall());
86
87 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnAbort(true);
88 }
89
90 } // namespace
91 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/modules.gypi ('k') | third_party/WebKit/Source/modules/payments/PaymentRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698