| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" |
| 14 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 17 #include "base/files/scoped_file.h" | 18 #include "base/files/scoped_file.h" |
| 18 #include "base/files/scoped_temp_dir.h" | 19 #include "base/files/scoped_temp_dir.h" |
| 19 #include "base/logging.h" | 20 #include "base/logging.h" |
| 20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 #include "mojo/edk/embedder/platform_channel_pair.h" | 23 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 23 #include "mojo/edk/embedder/scoped_platform_handle.h" | 24 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| (...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 | 1274 |
| 1274 // Create a new pipe using our end of the channel. | 1275 // Create a new pipe using our end of the channel. |
| 1275 ScopedMessagePipeHandle pipe = | 1276 ScopedMessagePipeHandle pipe = |
| 1276 edk::CreateMessagePipe(platform_channel.PassServerHandle()); | 1277 edk::CreateMessagePipe(platform_channel.PassServerHandle()); |
| 1277 | 1278 |
| 1278 // Ensure that we can read and write on the new pipe. | 1279 // Ensure that we can read and write on the new pipe. |
| 1279 VerifyEcho(pipe.get().value(), "goodbye"); | 1280 VerifyEcho(pipe.get().value(), "goodbye"); |
| 1280 END_CHILD() | 1281 END_CHILD() |
| 1281 } | 1282 } |
| 1282 | 1283 |
| 1284 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(BadMessageClient, MultiprocessMessagePipeTest, |
| 1285 parent) { |
| 1286 MojoHandle pipe; |
| 1287 EXPECT_EQ("hi", ReadMessageWithHandles(parent, &pipe, 1)); |
| 1288 WriteMessage(pipe, "derp"); |
| 1289 EXPECT_EQ("bye", ReadMessage(parent)); |
| 1290 } |
| 1291 |
| 1292 void OnBadMessage(bool* flag) { *flag = true; } |
| 1293 |
| 1294 TEST_F(MultiprocessMessagePipeTest, NotifyBadMessage) { |
| 1295 bool first_process_bad = false; |
| 1296 bool second_process_bad = false; |
| 1297 |
| 1298 set_bad_message_callback(base::Bind(&OnBadMessage, &first_process_bad)); |
| 1299 RUN_CHILD_ON_PIPE(BadMessageClient, child1) |
| 1300 set_bad_message_callback(base::Bind(&OnBadMessage, &second_process_bad)); |
| 1301 RUN_CHILD_ON_PIPE(BadMessageClient, child2) |
| 1302 MojoHandle a, b, c, d; |
| 1303 CreateMessagePipe(&a, &b); |
| 1304 CreateMessagePipe(&c, &d); |
| 1305 WriteMessageWithHandles(child1, "hi", &b, 1); |
| 1306 WriteMessageWithHandles(child2, "hi", &d, 1); |
| 1307 |
| 1308 // Read a message from the pipe we sent to child1 and flag it as bad. |
| 1309 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(a, MOJO_HANDLE_SIGNAL_READABLE, |
| 1310 MOJO_DEADLINE_INDEFINITE, nullptr)); |
| 1311 uint32_t num_bytes = 0; |
| 1312 MojoMessageHandle message; |
| 1313 ASSERT_EQ(MOJO_RESULT_OK, |
| 1314 MojoReadMessageNew(a, &message, &num_bytes, nullptr, 0, |
| 1315 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 1316 EXPECT_EQ(MOJO_RESULT_OK, MojoNotifyBadMessage(message)); |
| 1317 EXPECT_EQ(MOJO_RESULT_OK, MojoFreeMessage(message)); |
| 1318 |
| 1319 // Read a message from the pipe we sent to child2 and flag it as bad. |
| 1320 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(c, MOJO_HANDLE_SIGNAL_READABLE, |
| 1321 MOJO_DEADLINE_INDEFINITE, nullptr)); |
| 1322 ASSERT_EQ(MOJO_RESULT_OK, |
| 1323 MojoReadMessageNew(c, &message, &num_bytes, nullptr, 0, |
| 1324 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 1325 EXPECT_EQ(MOJO_RESULT_OK, MojoNotifyBadMessage(message)); |
| 1326 EXPECT_EQ(MOJO_RESULT_OK, MojoFreeMessage(message)); |
| 1327 |
| 1328 WriteMessage(child2, "bye"); |
| 1329 END_CHILD(); |
| 1330 |
| 1331 WriteMessage(child1, "bye"); |
| 1332 END_CHILD() |
| 1333 |
| 1334 // Both flags should be set. |
| 1335 EXPECT_TRUE(first_process_bad); |
| 1336 EXPECT_TRUE(second_process_bad); |
| 1337 } |
| 1338 |
| 1283 } // namespace | 1339 } // namespace |
| 1284 } // namespace edk | 1340 } // namespace edk |
| 1285 } // namespace mojo | 1341 } // namespace mojo |
| OLD | NEW |