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

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

Issue 2193183002: Print proper debug message in case of change event timeout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed review 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
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/PaymentRequestUpdateEvent.h" 5 #include "modules/payments/PaymentRequestUpdateEvent.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8BindingForTesting.h" 10 #include "bindings/core/v8/V8BindingForTesting.h"
11 #include "core/EventTypeNames.h" 11 #include "core/EventTypeNames.h"
12 #include "modules/payments/PaymentRequest.h"
13 #include "modules/payments/PaymentTestHelper.h"
12 #include "modules/payments/PaymentUpdater.h" 14 #include "modules/payments/PaymentUpdater.h"
13 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 #include <memory> 17 #include <memory>
16 18
17 namespace blink { 19 namespace blink {
18 namespace { 20 namespace {
19 21
20 class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater { 22 class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater {
21 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater); 23 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater);
22 WTF_MAKE_NONCOPYABLE(MockPaymentUpdater); 24 WTF_MAKE_NONCOPYABLE(MockPaymentUpdater);
23 25
24 public: 26 public:
25 MockPaymentUpdater() {} 27 MockPaymentUpdater() {}
26 ~MockPaymentUpdater() override {} 28 ~MockPaymentUpdater() override {}
27 29
28 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue)); 30 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue));
29 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error)); 31 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const String& error));
30 32
31 DEFINE_INLINE_TRACE() {} 33 DEFINE_INLINE_TRACE() {}
32 }; 34 };
33 35
34 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled) 36 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled)
35 { 37 {
36 V8TestingScope scope; 38 V8TestingScope scope;
37 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); 39 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create();
38 MockPaymentUpdater* updater = new MockPaymentUpdater; 40 MockPaymentUpdater* updater = new MockPaymentUpdater;
39 event->setPaymentDetailsUpdater(updater); 41 event->setPaymentDetailsUpdater(updater);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); 99 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange);
98 100
99 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop e.getScriptState())->promise(), scope.getExceptionState()); 101 event->updateWith(scope.getScriptState(), ScriptPromiseResolver::create(scop e.getScriptState())->promise(), scope.getExceptionState());
100 102
101 EXPECT_FALSE(scope.getExceptionState().hadException()); 103 EXPECT_FALSE(scope.getExceptionState().hadException());
102 } 104 }
103 105
104 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout) 106 TEST(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsTimeout)
105 { 107 {
106 V8TestingScope scope; 108 V8TestingScope scope;
109 PaymentRequestMockFunctionScope funcs(scope.getScriptState());
110 makePaymentRequestOriginSecure(scope.document());
111 PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), bui ldPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionSt ate());
107 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(); 112 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create();
108 MockPaymentUpdater* updater = new MockPaymentUpdater; 113 event->setPaymentDetailsUpdater(request);
109 event->setPaymentDetailsUpdater(updater); 114 EXPECT_FALSE(scope.getExceptionState().hadException());
110 115
111 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0); 116 String errorMessage;
112 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)); 117 request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expec tCall(&errorMessage));
113 118
114 event->onTimerFired(0); 119 event->onTimerFired(0);
120
121 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
122 EXPECT_EQ("AbortError: Timed out as the page didn't resolve the promise from change event", errorMessage);
115 } 123 }
116 124
117 } // namespace 125 } // namespace
118 } // namespace blink 126 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698