fake_ipc_server.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2021 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. #ifndef REMOTING_HOST_MOJO_IPC_FAKE_IPC_SERVER_H_
  5. #define REMOTING_HOST_MOJO_IPC_FAKE_IPC_SERVER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "remoting/host/mojo_ipc/ipc_server.h"
  8. namespace remoting {
  9. class FakeIpcServer final : public IpcServer {
  10. public:
  11. // Used to interact with FakeIpcServer after ownership is passed elsewhere.
  12. struct TestState {
  13. TestState();
  14. ~TestState();
  15. bool is_server_started = false;
  16. base::RepeatingClosure disconnect_handler;
  17. mojo::ReceiverId current_receiver = 0u;
  18. mojo::ReceiverId last_closed_receiver = 0u;
  19. int32_t current_peer_pid = 0;
  20. };
  21. explicit FakeIpcServer(TestState* test_state);
  22. FakeIpcServer(const FakeIpcServer&) = delete;
  23. FakeIpcServer& operator=(const FakeIpcServer&) = delete;
  24. ~FakeIpcServer() override;
  25. void StartServer() override;
  26. void StopServer() override;
  27. void Close(mojo::ReceiverId id) override;
  28. void set_disconnect_handler(base::RepeatingClosure handler) override;
  29. mojo::ReceiverId current_receiver() const override;
  30. base::ProcessId current_peer_pid() const override;
  31. private:
  32. raw_ptr<TestState> test_state_;
  33. };
  34. } // namespace remoting
  35. #endif // REMOTING_HOST_MOJO_IPC_FAKE_IPC_SERVER_H_