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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEventTest.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEventTest.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEventTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..66e6d6913fcd63ac8df26c05bc8bd27fedb975e6
--- /dev/null
+++ b/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEventTest.cpp
@@ -0,0 +1,79 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/payments/PaymentRequestUpdateEvent.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/core/v8/ScriptState.h"
+#include "core/EventTypeNames.h"
+#include "core/testing/DummyPageHolder.h"
+#include "modules/payments/PaymentUpdater.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/OwnPtr.h"
+#include <utility>
+
+namespace blink {
+
+class MockPaymentUpdater : public GarbageCollectedFinalized<MockPaymentUpdater>, public PaymentUpdater {
+ USING_GARBAGE_COLLECTED_MIXIN(MockPaymentUpdater);
+ WTF_MAKE_NONCOPYABLE(MockPaymentUpdater);
+
+public:
+ MockPaymentUpdater() {}
+ ~MockPaymentUpdater() override {}
+
+ MOCK_METHOD1(onUpdatePaymentDetails, void(const ScriptValue& detailsScriptValue));
+ MOCK_METHOD1(onUpdatePaymentDetailsFailure, void(const ScriptValue& error));
+
+ DEFINE_INLINE_TRACE() {}
+};
+
+class PaymentRequestUpdateEventTest : public testing::Test {
+public:
+ PaymentRequestUpdateEventTest()
+ : m_page(DummyPageHolder::create())
+ {
+ }
+
+ ~PaymentRequestUpdateEventTest() override {}
+
+ ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->document().frame()); }
+
+private:
+ OwnPtr<DummyPageHolder> m_page;
+};
+
+TEST_F(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsCalled)
+{
+ ScriptState::Scope scope(getScriptState());
+ PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create();
+ MockPaymentUpdater* updater = new MockPaymentUpdater;
+ event->setPaymentDetailsUpdater(updater);
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(getScriptState());
+ event->updateWith(getScriptState(), resolver->promise());
+
+ EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_));
+ EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_)).Times(0);
+
+ resolver->resolve("foo");
+}
+
+TEST_F(PaymentRequestUpdateEventTest, OnUpdatePaymentDetailsFailureCalled)
+{
+ ScriptState::Scope scope(getScriptState());
+ PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTypeNames::shippingaddresschange);
+ MockPaymentUpdater* updater = new MockPaymentUpdater;
+ event->setPaymentDetailsUpdater(updater);
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(getScriptState());
+ event->updateWith(getScriptState(), resolver->promise());
+
+ EXPECT_CALL(*updater, onUpdatePaymentDetails(testing::_)).Times(0);
+ EXPECT_CALL(*updater, onUpdatePaymentDetailsFailure(testing::_));
+
+ resolver->reject("oops");
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698