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

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentRequestTestBase.cpp

Issue 2048823004: PaymentRequest.abort() should return a promise. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Include what you use 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/PaymentRequestTestBase.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequestTestBase.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequestTestBase.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6880974eb05231457e7650ec04c3d646b1292d3f
--- /dev/null
+++ b/third_party/WebKit/Source/modules/payments/PaymentRequestTestBase.cpp
@@ -0,0 +1,77 @@
+// 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/PaymentRequestTestBase.h"
+
+#include "bindings/core/v8/ScriptState.h"
+#include "core/dom/Document.h"
+#include "core/frame/LocalDOMWindow.h"
+#include "platform/weborigin/KURL.h"
+#include "platform/weborigin/SecurityOrigin.h"
+
+namespace blink {
+
+PaymentRequestTestBase::PaymentRequestTestBase()
+{
+ DCHECK(getScriptState()->getExecutionContext());
+ DCHECK(getScriptState()->domWindow());
+ DCHECK(getScriptState()->domWindow()->document());
+ DCHECK(getScriptState()->domWindow()->frame());
+ setSecurityOrigin("https://www.example.com/");
+}
+
+PaymentRequestTestBase::~PaymentRequestTestBase()
+{
+ firePromiseCallbacks();
+ for (MockFunction* mockFunction : m_mockFunctions) {
+ testing::Mock::VerifyAndClearExpectations(mockFunction);
+ }
+}
+
+ScriptState* PaymentRequestTestBase::getScriptState()
+{
+ return m_scriptState.getScriptState();
+}
+
+ExceptionState& PaymentRequestTestBase::getExceptionState()
+{
+ return m_exceptionState;
+}
+
+void PaymentRequestTestBase::setSecurityOrigin(const String& securityOrigin)
+{
+ getScriptState()->domWindow()->document()->updateSecurityOrigin(SecurityOrigin::create(KURL(KURL(), securityOrigin)));
+}
+
+v8::Local<v8::Function> PaymentRequestTestBase::expectCall()
+{
+ m_mockFunctions.append(new MockFunction(getScriptState()));
+ EXPECT_CALL(*m_mockFunctions.last(), call(testing::_));
+ return m_mockFunctions.last()->bind();
+}
+
+v8::Local<v8::Function> PaymentRequestTestBase::expectNoCall()
+{
+ m_mockFunctions.append(new MockFunction(getScriptState()));
+ EXPECT_CALL(*m_mockFunctions.last(), call(testing::_)).Times(0);
+ return m_mockFunctions.last()->bind();
+}
+
+void PaymentRequestTestBase::firePromiseCallbacks()
+{
+ v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate());
+}
+
+PaymentRequestTestBase::MockFunction::MockFunction(ScriptState* scriptState)
+ : ScriptFunction(scriptState)
+{
+ ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>());
+}
+
+v8::Local<v8::Function> PaymentRequestTestBase::MockFunction::bind()
+{
+ return bindToV8Function();
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698