OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ipc/ipc_message_utils.h" | 5 #include "ipc/ipc_message_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/shared_memory.h" |
14 #include "base/unguessable_token.h" | 15 #include "base/unguessable_token.h" |
15 #include "ipc/ipc_channel_handle.h" | 16 #include "ipc/ipc_channel_handle.h" |
16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace IPC { | 20 namespace IPC { |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Tests nesting of messages as parameters to other messages. | 23 // Tests nesting of messages as parameters to other messages. |
23 TEST(IPCMessageUtilsTest, NestedMessages) { | 24 TEST(IPCMessageUtilsTest, NestedMessages) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 IPC::LogParam(opt, &log); | 189 IPC::LogParam(opt, &log); |
189 EXPECT_EQ("10", log); | 190 EXPECT_EQ("10", log); |
190 | 191 |
191 base::Optional<int> unserialized_opt; | 192 base::Optional<int> unserialized_opt; |
192 base::PickleIterator iter(pickle); | 193 base::PickleIterator iter(pickle); |
193 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &unserialized_opt)); | 194 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &unserialized_opt)); |
194 EXPECT_TRUE(unserialized_opt); | 195 EXPECT_TRUE(unserialized_opt); |
195 EXPECT_EQ(opt.value(), unserialized_opt.value()); | 196 EXPECT_EQ(opt.value(), unserialized_opt.value()); |
196 } | 197 } |
197 | 198 |
| 199 TEST(IPCMessageUtilsTest, SharedMemoryHandle) { |
| 200 base::SharedMemoryCreateOptions options; |
| 201 options.size = 1004; |
| 202 base::SharedMemory shmem; |
| 203 ASSERT_TRUE(shmem.Create(options)); |
| 204 |
| 205 base::SharedMemoryHandle pre_pickle = shmem.handle().Duplicate(); |
| 206 ASSERT_TRUE(pre_pickle.IsValid()); |
| 207 |
| 208 IPC::Message message; |
| 209 IPC::WriteParam(&message, pre_pickle); |
| 210 |
| 211 base::SharedMemoryHandle post_pickle; |
| 212 base::PickleIterator iter(message); |
| 213 EXPECT_TRUE(IPC::ReadParam(&message, &iter, &post_pickle)); |
| 214 EXPECT_EQ(pre_pickle.GetGUID(), post_pickle.GetGUID()); |
| 215 EXPECT_EQ(pre_pickle.GetSize(), post_pickle.GetSize()); |
| 216 } |
| 217 |
198 TEST(IPCMessageUtilsTest, UnguessableTokenTest) { | 218 TEST(IPCMessageUtilsTest, UnguessableTokenTest) { |
199 base::UnguessableToken token = base::UnguessableToken::Create(); | 219 base::UnguessableToken token = base::UnguessableToken::Create(); |
200 base::Pickle pickle; | 220 base::Pickle pickle; |
201 IPC::WriteParam(&pickle, token); | 221 IPC::WriteParam(&pickle, token); |
202 | 222 |
203 base::PickleSizer sizer; | 223 base::PickleSizer sizer; |
204 IPC::GetParamSize(&sizer, token); | 224 IPC::GetParamSize(&sizer, token); |
205 | 225 |
206 EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); | 226 EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); |
207 | 227 |
(...skipping 22 matching lines...) Expand all Loading... |
230 | 250 |
231 base::PickleIterator iter(pickle); | 251 base::PickleIterator iter(pickle); |
232 base::flat_map<std::string, int> output; | 252 base::flat_map<std::string, int> output; |
233 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &output)); | 253 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &output)); |
234 | 254 |
235 EXPECT_EQ(input, output); | 255 EXPECT_EQ(input, output); |
236 } | 256 } |
237 | 257 |
238 } // namespace | 258 } // namespace |
239 } // namespace IPC | 259 } // namespace IPC |
OLD | NEW |