forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[remoting host] Add unittest for RemoteOpenUrlMessageHandler
This CL adds a unittest for RemoteOpenUrlMessageHandler. Bug: b:183135000 Change-Id: I78757a438b9e80c74c4420b15ac03fe55bfbf128 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3126902 Commit-Queue: Yuwei Huang <yuweih@chromium.org> Reviewed-by: Joe Downing <joedow@chromium.org> Cr-Commit-Position: refs/heads/main@{#917805}
- Loading branch information
Showing
9 changed files
with
365 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2021 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 "remoting/host/fake_ipc_server.h" | ||
|
||
namespace remoting { | ||
|
||
FakeIpcServer::TestState::TestState() = default; | ||
|
||
FakeIpcServer::TestState::~TestState() = default; | ||
|
||
FakeIpcServer::FakeIpcServer(TestState* test_state) : test_state_(test_state) {} | ||
|
||
FakeIpcServer::~FakeIpcServer() = default; | ||
|
||
void FakeIpcServer::StartServer() { | ||
test_state_->is_server_started = true; | ||
} | ||
|
||
void FakeIpcServer::StopServer() { | ||
test_state_->is_server_started = false; | ||
} | ||
|
||
void FakeIpcServer::Close(mojo::ReceiverId id) { | ||
test_state_->last_closed_receiver = id; | ||
} | ||
|
||
void FakeIpcServer::set_disconnect_handler(base::RepeatingClosure handler) { | ||
test_state_->disconnect_handler = handler; | ||
} | ||
|
||
mojo::ReceiverId FakeIpcServer::current_receiver() const { | ||
return test_state_->current_receiver; | ||
} | ||
|
||
} // namespace remoting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2021 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. | ||
|
||
#ifndef REMOTING_HOST_FAKE_IPC_SERVER_H_ | ||
#define REMOTING_HOST_FAKE_IPC_SERVER_H_ | ||
|
||
#include "remoting/host/ipc_server.h" | ||
|
||
namespace remoting { | ||
|
||
class FakeIpcServer final : public IpcServer { | ||
public: | ||
// Used to interact with FakeIpcServer after ownership is passed elsewhere. | ||
struct TestState { | ||
TestState(); | ||
~TestState(); | ||
|
||
bool is_server_started = false; | ||
base::RepeatingClosure disconnect_handler; | ||
mojo::ReceiverId current_receiver = 0u; | ||
mojo::ReceiverId last_closed_receiver = 0u; | ||
}; | ||
|
||
explicit FakeIpcServer(TestState* test_state); | ||
FakeIpcServer(const FakeIpcServer&) = delete; | ||
FakeIpcServer& operator=(const FakeIpcServer&) = delete; | ||
~FakeIpcServer() override; | ||
|
||
void StartServer() override; | ||
void StopServer() override; | ||
void Close(mojo::ReceiverId id) override; | ||
void set_disconnect_handler(base::RepeatingClosure handler) override; | ||
mojo::ReceiverId current_receiver() const override; | ||
|
||
private: | ||
TestState* test_state_; | ||
}; | ||
|
||
} // namespace remoting | ||
|
||
#endif // REMOTING_HOST_FAKE_IPC_SERVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2021 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. | ||
|
||
#ifndef REMOTING_HOST_IPC_SERVER_H_ | ||
#define REMOTING_HOST_IPC_SERVER_H_ | ||
|
||
#include "base/callback.h" | ||
#include "mojo/public/cpp/bindings/receiver_set.h" | ||
|
||
namespace remoting { | ||
|
||
// An interface for MojoIpcServer to allow mocking in unittests. | ||
class IpcServer { | ||
public: | ||
virtual ~IpcServer() = default; | ||
|
||
// Starts sending out mojo invitations and accepting IPCs. No-op if the server | ||
// is already started. | ||
virtual void StartServer() = 0; | ||
|
||
// Stops sending out mojo invitations and accepting IPCs. No-op if the server | ||
// is already stopped. | ||
virtual void StopServer() = 0; | ||
|
||
// Close the receiver identified by |id| and disconnect the remote. No-op if | ||
// |id| doesn't exist or the receiver is already closed. | ||
virtual void Close(mojo::ReceiverId id) = 0; | ||
|
||
// Sets a callback to be invoked any time a receiver is disconnected. You may | ||
// find out which receiver is being disconnected by calling | ||
// |current_receiver()|. | ||
virtual void set_disconnect_handler(base::RepeatingClosure handler) = 0; | ||
|
||
// Call this method to learn which receiver has received the incoming IPC or | ||
// which receiver is being disconnected. | ||
virtual mojo::ReceiverId current_receiver() const = 0; | ||
}; | ||
|
||
} // namespace remoting | ||
|
||
#endif // REMOTING_HOST_IPC_SERVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.