OLD | NEW |
(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/PaymentRequestTestBase.h" |
| 6 |
| 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/LocalDOMWindow.h" |
| 10 #include "core/testing/DummyPageHolder.h" |
| 11 #include "platform/weborigin/KURL.h" |
| 12 #include "platform/weborigin/SecurityOrigin.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 PaymentRequestTestBase::PaymentRequestTestBase() |
| 17 : m_holder(DummyPageHolder::create()) |
| 18 { |
| 19 setSecurityOrigin("https://www.example.com/"); |
| 20 } |
| 21 |
| 22 PaymentRequestTestBase::~PaymentRequestTestBase() |
| 23 { |
| 24 firePromiseCallbacks(); |
| 25 for (MockFunction* mockFunction : m_mockFunctions) { |
| 26 testing::Mock::VerifyAndClearExpectations(mockFunction); |
| 27 } |
| 28 } |
| 29 |
| 30 ScriptState* PaymentRequestTestBase::getScriptState() |
| 31 { |
| 32 return ScriptState::forMainWorld(m_holder->document().frame()); |
| 33 } |
| 34 |
| 35 ExceptionState& PaymentRequestTestBase::getExceptionState() |
| 36 { |
| 37 return m_exceptionState; |
| 38 } |
| 39 |
| 40 void PaymentRequestTestBase::setSecurityOrigin(const String& securityOrigin) |
| 41 { |
| 42 getScriptState()->domWindow()->document()->updateSecurityOrigin(SecurityOrig
in::create(KURL(KURL(), securityOrigin))); |
| 43 } |
| 44 |
| 45 v8::Local<v8::Function> PaymentRequestTestBase::expectCall() |
| 46 { |
| 47 m_mockFunctions.append(new MockFunction(getScriptState())); |
| 48 EXPECT_CALL(*m_mockFunctions.last(), call(testing::_)); |
| 49 return m_mockFunctions.last()->bind(); |
| 50 } |
| 51 |
| 52 v8::Local<v8::Function> PaymentRequestTestBase::expectNoCall() |
| 53 { |
| 54 m_mockFunctions.append(new MockFunction(getScriptState())); |
| 55 EXPECT_CALL(*m_mockFunctions.last(), call(testing::_)).Times(0); |
| 56 return m_mockFunctions.last()->bind(); |
| 57 } |
| 58 |
| 59 void PaymentRequestTestBase::firePromiseCallbacks() |
| 60 { |
| 61 v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
| 62 } |
| 63 |
| 64 PaymentRequestTestBase::MockFunction::MockFunction(ScriptState* scriptState) |
| 65 : ScriptFunction(scriptState) |
| 66 { |
| 67 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); |
| 68 } |
| 69 |
| 70 v8::Local<v8::Function> PaymentRequestTestBase::MockFunction::bind() |
| 71 { |
| 72 return bindToV8Function(); |
| 73 } |
| 74 |
| 75 } // namespace blink |
OLD | NEW |