1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/capture/video/shared_memory_handle_provider.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/memory/shared_memory.h"
#include "mojo/public/cpp/system/buffer.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace {
const size_t kMemorySize = 1024;
} // anonymous namespace
class SharedMemoryHandleProviderTest : public ::testing::Test {
public:
SharedMemoryHandleProviderTest() = default;
~SharedMemoryHandleProviderTest() override = default;
void UnwrapAndVerifyMojoHandle(
mojo::ScopedSharedBufferHandle buffer_handle,
size_t expected_size,
mojo::UnwrappedSharedMemoryHandleProtection expected_protection) {
base::SharedMemoryHandle memory_handle;
size_t memory_size = 0;
mojo::UnwrappedSharedMemoryHandleProtection protection;
const MojoResult result = mojo::UnwrapSharedMemoryHandle(
std::move(buffer_handle), &memory_handle, &memory_size, &protection);
EXPECT_EQ(MOJO_RESULT_OK, result);
EXPECT_EQ(expected_size, memory_size);
EXPECT_EQ(expected_protection, protection);
}
protected:
SharedMemoryHandleProvider handle_provider_;
private:
DISALLOW_COPY_AND_ASSIGN(SharedMemoryHandleProviderTest);
};
TEST_F(SharedMemoryHandleProviderTest,
VerifyInterProcessTransitHandleForReadOnly) {
handle_provider_.InitForSize(kMemorySize);
auto mojo_handle =
handle_provider_.GetHandleForInterProcessTransit(true /* read_only */);
// TODO(https://crbug.com/803136): See comment within
// GetHandleForInterProcessTransit() for an explanation of why this
// intentionally read-write even though it ought to be read-only.
UnwrapAndVerifyMojoHandle(
std::move(mojo_handle), kMemorySize,
mojo::UnwrappedSharedMemoryHandleProtection::kReadWrite);
}
TEST_F(SharedMemoryHandleProviderTest,
VerifyInterProcessTransitHandleForReadWrite) {
handle_provider_.InitForSize(kMemorySize);
auto mojo_handle =
handle_provider_.GetHandleForInterProcessTransit(false /* read_only */);
UnwrapAndVerifyMojoHandle(
std::move(mojo_handle), kMemorySize,
mojo::UnwrappedSharedMemoryHandleProtection::kReadWrite);
}
} // namespace media
|