chromium/mojo/core/shared_buffer_unittest.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/core/ipcz_driver/shared_buffer.h"

#include <string.h>

#include <string>
#include <utility>

#include "base/memory/platform_shared_memory_region.h"
#include "base/notreached.h"
#include "build/blink_buildflags.h"
#include "build/build_config.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/test/mojo_test_base.h"
#include "mojo/public/c/system/types.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(MOJO_SUPPORT_LEGACY_CORE)
#include "mojo/core/core.h"
#include "mojo/core/shared_buffer_dispatcher.h"
#endif

namespace mojo::core {
namespace {

SharedBufferTest;

TEST_F(SharedBufferTest, CreateSharedBuffer) {}

TEST_F(SharedBufferTest, DuplicateSharedBuffer) {}

TEST_F(SharedBufferTest, PassSharedBufferLocal) {}

#if BUILDFLAG(USE_BLINK)

// Reads a single message with a shared buffer handle, maps the buffer, copies
// the message contents into it, then exits.
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CopyToBufferClient, SharedBufferTest, h) {}

#if BUILDFLAG(IS_IOS)
// TODO(crbug.com/40257752): Test currently fails on iOS.
#define MAYBE_PassSharedBufferCrossProcess
#else
#define MAYBE_PassSharedBufferCrossProcess
#endif  // BUILDFLAG(IS_IOS)
TEST_F(SharedBufferTest, MAYBE_PassSharedBufferCrossProcess) {}

// Creates a new buffer, maps it, writes a message contents to it, unmaps it,
// and finally passes it back to the parent.
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CreateBufferClient, SharedBufferTest, h) {}

#if BUILDFLAG(IS_IOS)
// TODO(crbug.com/40257752): Test currently fails on iOS.
#define MAYBE_PassSharedBufferFromChild
#else
#define MAYBE_PassSharedBufferFromChild
#endif  // BUILDFLAG(IS_IOS)
TEST_F(SharedBufferTest, MAYBE_PassSharedBufferFromChild) {}

DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CreateAndPassBuffer, SharedBufferTest, h) {}

DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveAndEditBuffer, SharedBufferTest, h) {}

#if BUILDFLAG(IS_IOS)
// TODO(crbug.com/40257752): Test currently fails on iOS.
#define MAYBE_PassSharedBufferFromChildToChild
#else
#define MAYBE_PassSharedBufferFromChildToChild
#endif  // BUILDFLAG(IS_IOS)
TEST_F(SharedBufferTest, MAYBE_PassSharedBufferFromChildToChild) {}

DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CreateAndPassBufferParent,
                                  SharedBufferTest,
                                  parent) {}

DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveAndEditBufferParent,
                                  SharedBufferTest,
                                  parent) {}

#if BUILDFLAG(IS_ANDROID)
// Android multi-process tests are not executing the new process. This is flaky.
#define MAYBE_PassHandleBetweenCousins
#else
#define MAYBE_PassHandleBetweenCousins
#endif
TEST_F(SharedBufferTest, MAYBE_PassHandleBetweenCousins) {}

DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReadAndMapWriteSharedBuffer,
                                  SharedBufferTest,
                                  h) {}

#if BUILDFLAG(IS_IOS)
// TODO(crbug.com/40257752): Test currently fails on iOS.
#define MAYBE_CreateAndPassReadOnlyBuffer
#else
#define MAYBE_CreateAndPassReadOnlyBuffer
#endif  // BUILDFLAG(IS_IOS)
TEST_F(SharedBufferTest, MAYBE_CreateAndPassReadOnlyBuffer) {}

DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CreateAndPassReadOnlyBuffer,
                                  SharedBufferTest,
                                  h) {}

#if BUILDFLAG(IS_IOS)
// TODO(crbug.com/40257752): Test currently fails on iOS.
#define MAYBE_CreateAndPassFromChildReadOnlyBuffer
#else
#define MAYBE_CreateAndPassFromChildReadOnlyBuffer
#endif  // BUILDFLAG(IS_IOS)
TEST_F(SharedBufferTest, MAYBE_CreateAndPassFromChildReadOnlyBuffer) {}

#endif  // BUILDFLAG(USE_BLINK)

}  // namespace
}  // namespace mojo::core