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/unguessable_token.h" |
13 #include "ipc/ipc_channel_handle.h" | 14 #include "ipc/ipc_channel_handle.h" |
14 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace IPC { | 18 namespace IPC { |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Tests nesting of messages as parameters to other messages. | 21 // Tests nesting of messages as parameters to other messages. |
21 TEST(IPCMessageUtilsTest, NestedMessages) { | 22 TEST(IPCMessageUtilsTest, NestedMessages) { |
22 int32_t nested_routing = 12; | 23 int32_t nested_routing = 12; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 IPC::LogParam(opt, &log); | 193 IPC::LogParam(opt, &log); |
193 EXPECT_EQ("10", log); | 194 EXPECT_EQ("10", log); |
194 | 195 |
195 base::Optional<int> unserialized_opt; | 196 base::Optional<int> unserialized_opt; |
196 base::PickleIterator iter(pickle); | 197 base::PickleIterator iter(pickle); |
197 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &unserialized_opt)); | 198 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &unserialized_opt)); |
198 EXPECT_TRUE(unserialized_opt); | 199 EXPECT_TRUE(unserialized_opt); |
199 EXPECT_EQ(opt.value(), unserialized_opt.value()); | 200 EXPECT_EQ(opt.value(), unserialized_opt.value()); |
200 } | 201 } |
201 | 202 |
| 203 TEST(IPCMessageUtilsTest, UnguessableTokenTest) { |
| 204 base::UnguessableToken token = base::UnguessableToken::Create(); |
| 205 base::Pickle pickle; |
| 206 IPC::WriteParam(&pickle, token); |
| 207 |
| 208 base::PickleSizer sizer; |
| 209 IPC::GetParamSize(&sizer, token); |
| 210 |
| 211 EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); |
| 212 |
| 213 std::string log; |
| 214 IPC::LogParam(token, &log); |
| 215 EXPECT_EQ(token.ToString(), log); |
| 216 |
| 217 base::UnguessableToken deserialized_token; |
| 218 base::PickleIterator iter(pickle); |
| 219 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &deserialized_token)); |
| 220 EXPECT_EQ(token, deserialized_token); |
| 221 } |
| 222 |
202 } // namespace | 223 } // namespace |
203 } // namespace IPC | 224 } // namespace IPC |
OLD | NEW |