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

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: Rebase 3 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>
Marijn Kruisselbrink 2016/05/03 22:28:51 probably just my fault, but I don't see where this
please use gerrit instead 2016/05/05 04:57:48 You're right. It's not used in this file. It was a
17
18 namespace blink {
19 namespace {
20
21 class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater {
22 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater);
23 WTF_MAKE_NONCOPYABLE(MockPaymentUpdater);
24
25 public:
26 MockPaymentUpdater() {}
27 ~MockPaymentUpdater() override {}
28
29 MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptVa lue));
30 MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error));
31
32 DEFINE_INLINE_TRACE() {}
33 };
34
35 class PaymentRequestUpdateEventTest : public testing::Test {
36 public:
37 PaymentRequestUpdateEventTest()
38 : m_page(DummyPageHolder::create())
39 {
40 }
41
42 ~PaymentRequestUpdateEventTest() override {}
43
44 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); }
45 ExecutionContext* getExecutionContext() { return &m_page->document(); }
46 ExceptionState& getExceptionState() { return m_exceptionState; }
47
48 private:
49 OwnPtr<DummyPageHolder> m_page;
50 TrackExceptionState m_exceptionState;
51 };
52
53 TEST_F(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled)
54 {
55 ScriptState::Scope scope(getScriptState());
56 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create();
57 MockPaymentUpdater* updater = new MockPaymentUpdater;
58 event->setPaymentDetailsUpdater(updater);
59 event->setEventPhase(Event::CAPTURING_PHASE);
60 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(getScr iptState());
61 event->updateWith(getScriptState(), paymentDetails->promise(), getExceptionS tate());
62 EXPECT_FALSE(getExceptionState().hadException());
63
64 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_));
65 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0);
66
67 paymentDetails->resolve("foo");
68 }
69
70 TEST_F(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled)
71 {
72 ScriptState::Scope scope(getScriptState());
73 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange);
74 MockPaymentUpdater* updater = new MockPaymentUpdater;
75 event->setPaymentDetailsUpdater(updater);
76 event->setEventPhase(Event::CAPTURING_PHASE);
77 ScriptPromiseResolver* paymentDetails = ScriptPromiseResolver::create(getScr iptState());
78 event->updateWith(getScriptState(), paymentDetails->promise(), getExceptionS tate());
79 EXPECT_FALSE(getExceptionState().hadException());
80
81 EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0);
82 EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_));
83
84 paymentDetails->reject("oops");
85 }
86
87 TEST_F(PaymentRequestUpdateEventTest, CannotUpdateWithoutDispatching)
88 {
89 ScriptState::Scope scope(getScriptState());
90 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange);
91 event->setPaymentDetailsUpdater(new MockPaymentUpdater);
92
93 event->updateWith(getScriptState(), ScriptPromiseResolver::create(getScriptS tate())->promise(), getExceptionState());
94
95 EXPECT_TRUE(getExceptionState().hadException());
96 }
97
98 TEST_F(PaymentRequestUpdateEventTest, CannotUpdateTwice)
99 {
100 ScriptState::Scope scope(getScriptState());
101 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange);
102 MockPaymentUpdater* updater = new MockPaymentUpdater;
103 event->setPaymentDetailsUpdater(updater);
104 event->setEventPhase(Event::CAPTURING_PHASE);
105 event->updateWith(getScriptState(), ScriptPromiseResolver::create(getScriptS tate())->promise(), getExceptionState());
106 EXPECT_FALSE(getExceptionState().hadException());
107
108 event->updateWith(getScriptState(), ScriptPromiseResolver::create(getScriptS tate())->promise(), getExceptionState());
109
110 EXPECT_TRUE(getExceptionState().hadException());
111 }
112
113 } // namespace
114 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698