#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <memory>
#include <string_view>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/safe_math.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "build/blink_buildflags.h"
#include "build/build_config.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/ipcz_driver/mojo_message.h"
#include "mojo/core/test/mojo_test_base.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/buffer.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "mojo/public/cpp/system/platform_handle.h"
#if BUILDFLAG(MOJO_SUPPORT_LEGACY_CORE)
#include "mojo/core/user_message_impl.h"
#endif
namespace mojo::core {
namespace {
MessageTest;
#if BUILDFLAG(MOJO_SUPPORT_LEGACY_CORE)
constexpr uint32_t kLegacyMinimumPayloadBufferSize = kMinimumPayloadBufferSize;
#else
constexpr uint32_t kLegacyMinimumPayloadBufferSize = …;
#endif
class TestMessageBase { … };
class NeverSerializedMessage : public TestMessageBase { … };
class SimpleMessage : public TestMessageBase { … };
TEST_F(MessageTest, InvalidMessageObjects) { … }
TEST_F(MessageTest, SendLocalMessageWithContext) { … }
TEST_F(MessageTest, DestroyMessageWithContext) { … }
const char kTestMessageWithContext1[] = …;
#if BUILDFLAG(USE_BLINK)
const char kTestMessageWithContext2[] = …;
const char kTestMessageWithContext3[] = …;
const char kTestMessageWithContext4[] = …;
const char kTestQuitMessage[] = …;
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveMessageNoHandles, MessageTest, h) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_SerializeSimpleMessageNoHandlesWithContext …
#else
#define MAYBE_SerializeSimpleMessageNoHandlesWithContext …
#endif
TEST_F(MessageTest, MAYBE_SerializeSimpleMessageNoHandlesWithContext) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_SerializeDynamicallySizedMessage …
#else
#define MAYBE_SerializeDynamicallySizedMessage …
#endif
TEST_F(MessageTest, MAYBE_SerializeDynamicallySizedMessage) { … }
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveMessageOneHandle, MessageTest, h) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_SerializeSimpleMessageOneHandleWithContext …
#else
#define MAYBE_SerializeSimpleMessageOneHandleWithContext …
#endif
TEST_F(MessageTest, MAYBE_SerializeSimpleMessageOneHandleWithContext) { … }
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveMessageWithHandles, MessageTest, h) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_SerializeSimpleMessageWithHandlesWithContext …
#else
#define MAYBE_SerializeSimpleMessageWithHandlesWithContext …
#endif
TEST_F(MessageTest, MAYBE_SerializeSimpleMessageWithHandlesWithContext) { … }
#endif
TEST_F(MessageTest, SendLocalSimpleMessageWithHandlesWithContext) { … }
TEST_F(MessageTest, DropUnreadLocalMessageWithContext) { … }
TEST_F(MessageTest, GetMessageDataWithHandles) { … }
TEST_F(MessageTest, ReadMessageWithContextAsSerializedMessage) { … }
TEST_F(MessageTest, ReadSerializedMessageAsMessageWithContext) { … }
TEST_F(MessageTest, ForceSerializeMessageWithContext) { … }
TEST_F(MessageTest, DoubleSerialize) { … }
TEST_F(MessageTest, ExtendMessagePayload) { … }
TEST_F(MessageTest, PreallocateEnoughMemoryForMessage) { … }
TEST_F(MessageTest, PreallocateNotEnoughMemoryForMessage) { … }
TEST_F(MessageTest, ExtendMessageWithHandlesPayload) { … }
TEST_F(MessageTest, ExtendMessagePayloadLarge) { … }
TEST_F(MessageTest, CorrectPayloadBufferBoundaries) { … }
#if BUILDFLAG(MOJO_SUPPORT_LEGACY_CORE)
TEST_F(MessageTest, CommitInvalidMessageContents) {
MojoMessageHandle message;
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessage(nullptr, &message));
EXPECT_EQ(MOJO_RESULT_OK, MojoAppendMessageData(message, 0, nullptr, 0,
nullptr, nullptr, nullptr));
MojoHandle a, b;
CreateMessagePipe(&a, &b);
EXPECT_EQ(MOJO_RESULT_OK, MojoAppendMessageData(message, 0, &a, 1, nullptr,
nullptr, nullptr));
UserMessageImpl::FailHandleSerializationForTesting(true);
MojoAppendMessageDataOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_APPEND_MESSAGE_DATA_FLAG_COMMIT_SIZE;
EXPECT_EQ(MOJO_RESULT_OK, MojoAppendMessageData(message, 0, nullptr, 0,
nullptr, nullptr, nullptr));
UserMessageImpl::FailHandleSerializationForTesting(false);
EXPECT_EQ(MOJO_RESULT_OK, MojoDestroyMessage(message));
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(b));
}
#endif
#if BUILDFLAG(USE_BLINK)
#if BUILDFLAG(IS_IOS)
#define MAYBE_ExtendPayloadWithHandlesAttached …
#else
#define MAYBE_ExtendPayloadWithHandlesAttached …
#endif
TEST_F(MessageTest, MAYBE_ExtendPayloadWithHandlesAttached) { … }
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReadAndIgnoreMessage, MessageTest, h) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_ExtendPayloadWithHandlesAttachedViaExtension …
#else
#define MAYBE_ExtendPayloadWithHandlesAttachedViaExtension …
#endif
TEST_F(MessageTest, MAYBE_ExtendPayloadWithHandlesAttachedViaExtension) { … }
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReadMessageAndCheckPipe, MessageTest, h) { … }
#endif
TEST_F(MessageTest, PartiallySerializedMessagesDontLeakHandles) { … }
}
}