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