#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "mojo/public/cpp/system/invitation.h"
#include <optional>
#include <string_view>
#include <utility>
#include "base/base_paths.h"
#include "base/base_switches.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/multiprocess_test.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/test/test_switches.h"
#include "mojo/public/c/system/invitation.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "mojo/public/cpp/system/wait.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_IOS)
#include "mojo/public/cpp/platform/named_platform_channel.h"
#endif
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "base/win/access_token.h"
#endif
namespace mojo {
namespace {
enum class InvitationType { … };
enum class TransportType { … };
const char kTransportTypeSwitch[] = …;
const char kTransportTypeChannel[] = …;
#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_IOS)
const char kTransportTypeChannelServer[] = …;
#endif
#if defined(THREAD_SANITIZER)
#define MAYBE_InvitationCppTest …
#else
#define MAYBE_InvitationCppTest …
#endif
class MAYBE_InvitationCppTest
: public testing::Test,
public testing::WithParamInterface<TransportType> { … };
class TestClientBase : public MAYBE_InvitationCppTest { … };
#define DEFINE_TEST_CLIENT(name) …
const char kTestMessage1[] = …;
const char kTestMessage2[] = …;
TEST_P(MAYBE_InvitationCppTest, Send) { … }
DEFINE_TEST_CLIENT(CppSendClient) { … }
TEST_P(MAYBE_InvitationCppTest, SendIsolated) { … }
DEFINE_TEST_CLIENT(CppSendIsolatedClient) { … }
#if BUILDFLAG(IS_WIN)
TEST_P(MAYBE_InvitationCppTest, SendElevated) {
ScopedMessagePipeHandle pipe;
LaunchChildTestClient("CppSendElevatedClient", &pipe, 1,
InvitationType::kElevated, GetParam());
WriteMessage(pipe, kTestMessage1);
WaitForChildExit();
}
DEFINE_TEST_CLIENT(CppSendElevatedClient) {
auto invitation = AcceptInvitation(MOJO_ACCEPT_INVITATION_FLAG_ELEVATED);
auto pipe = invitation.ExtractMessagePipe(0);
CHECK_EQ(kTestMessage1, ReadMessage(pipe));
}
#endif
TEST_P(MAYBE_InvitationCppTest, SendWithMultiplePipes) { … }
DEFINE_TEST_CLIENT(CppSendWithMultiplePipesClient) { … }
TEST(MAYBE_InvitationCppTest_NoParam, SendIsolatedInvitationWithDuplicateName) { … }
const char kErrorMessage[] = …;
const char kDisconnectMessage[] = …;
#if BUILDFLAG(IS_ANDROID) && defined(ADDRESS_SANITIZER)
#define MAYBE_ProcessErrors …
#else
#define MAYBE_ProcessErrors …
#endif
TEST_P(MAYBE_InvitationCppTest, MAYBE_ProcessErrors) { … }
DEFINE_TEST_CLIENT(CppProcessErrorsClient) { … }
INSTANTIATE_TEST_SUITE_P(…);
}
}