| // Copyright 2012 The Chromium Authors | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #include "remoting/protocol/protocol_mock_objects.h" | |
| #include <memory> | |
| #include <utility> | |
| #include "base/check.h" | |
| #include "base/task/single_thread_task_runner.h" | |
| #include "remoting/proto/video.pb.h" | |
| #include "remoting/protocol/session_plugin.h" | |
| #include "remoting/protocol/video_stream.h" | |
| #include "remoting/signaling/signaling_address.h" | |
| namespace remoting::protocol { | |
| MockAuthenticator::MockAuthenticator() = default; | |
| MockAuthenticator::~MockAuthenticator() = default; | |
| MockConnectionToClientEventHandler::MockConnectionToClientEventHandler() = | |
| default; | |
| MockConnectionToClientEventHandler::~MockConnectionToClientEventHandler() = | |
| default; | |
| MockClipboardStub::MockClipboardStub() = default; | |
| MockClipboardStub::~MockClipboardStub() = default; | |
| MockInputStub::MockInputStub() = default; | |
| MockInputStub::~MockInputStub() = default; | |
| MockHostStub::MockHostStub() = default; | |
| MockHostStub::~MockHostStub() = default; | |
| MockClientStub::MockClientStub() = default; | |
| MockClientStub::~MockClientStub() = default; | |
| MockCursorShapeStub::MockCursorShapeStub() = default; | |
| MockCursorShapeStub::~MockCursorShapeStub() = default; | |
| MockVideoStub::MockVideoStub() = default; | |
| MockVideoStub::~MockVideoStub() = default; | |
| void MockVideoStub::ProcessVideoPacket( | |
| std::unique_ptr<VideoPacket> video_packet, | |
| base::OnceClosure done) { | |
| ProcessVideoPacketPtr(video_packet.get(), &done); | |
| } | |
| MockSession::MockSession() { | |
| ON_CALL(*this, SetEventHandler(testing::_)) | |
| .WillByDefault( | |
| [this](Session::EventHandler* handler) { event_handler_ = handler; }); | |
| ON_CALL(*this, error()).WillByDefault([this]() { return error_; }); | |
| ON_CALL(*this, Close(testing::_, testing::_, testing::_)) | |
| .WillByDefault([this](ErrorCode error, std::string_view error_details, | |
| const SourceLocation& location) { | |
| error_ = error; | |
| if (event_handler_) { | |
| event_handler_->OnSessionStateChange( | |
| error == ErrorCode::OK ? Session::CLOSED : Session::FAILED); | |
| } | |
| }); | |
| } | |
| MockSession::~MockSession() = default; | |
| MockSessionManager::MockSessionManager() = default; | |
| MockSessionManager::~MockSessionManager() = default; | |
| MockSessionObserver::MockSessionObserver() = default; | |
| MockSessionObserver::~MockSessionObserver() = default; | |
| MockPairingRegistryDelegate::MockPairingRegistryDelegate() = default; | |
| MockPairingRegistryDelegate::~MockPairingRegistryDelegate() = default; | |
| base::ListValue MockPairingRegistryDelegate::LoadAll() { | |
| base::ListValue result; | |
| for (Pairings::const_iterator i = pairings_.begin(); i != pairings_.end(); | |
| ++i) { | |
| result.Append(i->second.ToValue()); | |
| } | |
| return result; | |
| } | |
| bool MockPairingRegistryDelegate::DeleteAll() { | |
| pairings_.clear(); | |
| return true; | |
| } | |
| protocol::PairingRegistry::Pairing MockPairingRegistryDelegate::Load( | |
| const std::string& client_id) { | |
| Pairings::const_iterator i = pairings_.find(client_id); | |
| if (i != pairings_.end()) { | |
| return i->second; | |
| } else { | |
| return protocol::PairingRegistry::Pairing(); | |
| } | |
| } | |
| bool MockPairingRegistryDelegate::Save( | |
| const protocol::PairingRegistry::Pairing& pairing) { | |
| pairings_[pairing.client_id()] = pairing; | |
| return true; | |
| } | |
| bool MockPairingRegistryDelegate::Delete(const std::string& client_id) { | |
| pairings_.erase(client_id); | |
| return true; | |
| } | |
| SynchronousPairingRegistry::SynchronousPairingRegistry( | |
| std::unique_ptr<Delegate> delegate) | |
| : PairingRegistry(base::SingleThreadTaskRunner::GetCurrentDefault(), | |
| std::move(delegate)) {} | |
| SynchronousPairingRegistry::~SynchronousPairingRegistry() = default; | |
| void SynchronousPairingRegistry::PostTask( | |
| const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | |
| const base::Location& from_here, | |
| base::OnceClosure task) { | |
| DCHECK(task_runner->BelongsToCurrentThread()); | |
| std::move(task).Run(); | |
| } | |
| } // namespace remoting::protocol |