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

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

Issue 1931233002: Implement PaymentRequestUpdateEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicit-shipping
Patch Set: Created 4 years, 7 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 "modules/payments/PaymentRequestUpdateEvent.h"
6
7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h"
10 #include "core/EventTypeNames.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include "modules/payments/PaymentUpdater.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "wtf/OwnPtr.h"
16 #include <utility>
17
18 namespace blink {
19
20 class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater {
21 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater);
22 WTF_MAKE_NONCOPYABLE(MockPaymentUpdater);
23
24 public:
25 MockPaymentUpdater() {}
26 ~MockPaymentUpdater() override {}
27
28 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue));
29 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error));
30
31 DEFINE_INLINE_TRACE() {}
32 };
33
34 class PaymentRequestUpdateEventTest : public testing::Test {
35 public:
36 PaymentRequestUpdateEventTest()
37 : m_page(DummyPageHolder::create())
38 {
39 }
40
41 ~PaymentRequestUpdateEventTest() override {}
42
43 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); }
44
45 private:
46 OwnPtr<DummyPageHolder> m_page;
47 };
48
49 TEST_F(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled)
50 {
51 ScriptState::Scope scope(getScriptState());
52 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create();
53 MockPaymentUpdater* updater = new MockPaymentUpdater;
54 event->setPaymentDetailsUpdater(updater);
55 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(getScriptSta te());
56 event->updateWith(getScriptState(), resolver->promise());
57
58 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_));
59 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0);
60
61 resolver->resolve("foo");
62 }
63
64 TEST_F(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled)
65 {
66 ScriptState::Scope scope(getScriptState());
67 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange);
68 MockPaymentUpdater* updater = new MockPaymentUpdater;
69 event->setPaymentDetailsUpdater(updater);
70 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(getScriptSta te());
71 event->updateWith(getScriptState(), resolver->promise());
72
73 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0);
74 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_));
75
76 resolver->reject("oops");
77 }
78
79 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698