#include "components/named_mojo_ipc_server/named_mojo_ipc_server.h"
#include <memory>
#include <string>
#include <string_view>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/process/process.h"
#include "base/process/process_handle.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/mock_callback.h"
#include "base/test/multiprocess_test.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "components/named_mojo_ipc_server/connection_info.h"
#include "components/named_mojo_ipc_server/endpoint_options.h"
#include "components/named_mojo_ipc_server/named_mojo_ipc_server_client_util.h"
#include "components/named_mojo_ipc_server/named_mojo_ipc_test_util.h"
#include "components/named_mojo_ipc_server/testing.test-mojom.h"
#include "components/test/test_switches.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/embedder/scoped_ipc_support.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel_endpoint.h"
#include "mojo/public/cpp/system/invitation.h"
#include "mojo/public/cpp/system/isolated_connection.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
namespace named_mojo_ipc_server {
namespace {
_;
Return;
EchoStringHandler;
static const char kEchoClientName[] = …;
static const char kClientProcessServerNameSwitch[] = …;
static const char kClientProcessExitAfterConnectSwitch[] = …;
static const char kClientProcessHangAfterConnectSwitch[] = …;
static const char kClientProcessWaitUntilDisconnectedSwitch[] = …;
static const char kClientProcessUseIsolatedConnectionSwitch[] = …;
static constexpr int kInvalidEndpointExitCode = …;
static constexpr uint64_t kTestMessagePipeId = …;
class NamedMojoIpcServerTest
: public testing::TestWithParam< bool>,
public test::mojom::Echo { … };
NamedMojoIpcServerTest::NamedMojoIpcServerTest() { … }
NamedMojoIpcServerTest::~NamedMojoIpcServerTest() = default;
void NamedMojoIpcServerTest::SetUp() { … }
void NamedMojoIpcServerTest::TearDown() { … }
void NamedMojoIpcServerTest::CreateIpcServer() { … }
void NamedMojoIpcServerTest::WaitForServerEndpointCreated() { … }
base::Process NamedMojoIpcServerTest::LaunchClientProcess(
std::string_view extra_switch) { … }
int NamedMojoIpcServerTest::WaitForProcessExit(base::Process& process) { … }
void NamedMojoIpcServerTest::EchoString(const std::string& input,
EchoStringCallback callback) { … }
void NamedMojoIpcServerTest::OnServerEndpointCreated() { … }
TEST_P(NamedMojoIpcServerTest, SendEcho) { … }
TEST_P(NamedMojoIpcServerTest, DeleteNamedMojoServer_NoLingeringInvitations) { … }
TEST_P(NamedMojoIpcServerTest, DisconnectHandler) { … }
TEST_P(NamedMojoIpcServerTest, DeleteNamedMojoServer_RemoteDisconnected) { … }
TEST_P(NamedMojoIpcServerTest, StopServer_RemoteDisconnected) { … }
TEST_P(NamedMojoIpcServerTest, CloseReceiver_RemoteDisconnected) { … }
TEST_P(NamedMojoIpcServerTest, CloseNonexistentReceiver_NoCrash) { … }
TEST_P(NamedMojoIpcServerTest, RemoteProcessTerminated_ConnectionRemoved) { … }
#if BUILDFLAG(IS_WIN)
TEST_P(NamedMojoIpcServerTest,
RemoteTerminatedBeforeBound_NewServerEndpointCreated) {
base::Process child_process =
LaunchClientProcess(kClientProcessExitAfterConnectSwitch);
WaitForProcessExit(child_process);
WaitForServerEndpointCreated();
}
TEST_P(NamedMojoIpcServerTest,
RemoteConnectsAndHangs_NewServerEndpointCreated) {
base::Process child_process =
LaunchClientProcess(kClientProcessHangAfterConnectSwitch);
WaitForServerEndpointCreated();
}
#endif
TEST_P(NamedMojoIpcServerTest, ParallelIpcs) { … }
TEST_P(NamedMojoIpcServerTest, IpcServerRestarted_NewIpcsCanBeMade) { … }
MULTIPROCESS_TEST_MAIN(EchoClient) { … }
INSTANTIATE_TEST_SUITE_P(,
NamedMojoIpcServerTest,
testing::Values(true, false),
[](const testing::TestParamInfo<bool>& info) { … };
}
}