Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: mojo/edk/system/multiprocess_message_pipe_unittest.cc

Issue 2043713004: Mojo: Add NotifyBadMessage API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no bindings Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/message_for_transit.h ('k') | mojo/edk/system/node_channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 OnProcessError(std::string* out_error, const std::string& error) {
1293 *out_error = error;
1294 }
1295
1296 TEST_F(MultiprocessMessagePipeTest, NotifyBadMessage) {
1297 const std::string kFirstErrorMessage = "everything is terrible!";
1298 const std::string kSecondErrorMessage = "not the bits you're looking for";
1299
1300 std::string first_process_error;
1301 std::string second_process_error;
1302
1303 set_process_error_callback(base::Bind(&OnProcessError, &first_process_error));
1304 RUN_CHILD_ON_PIPE(BadMessageClient, child1)
1305 set_process_error_callback(base::Bind(&OnProcessError,
1306 &second_process_error));
1307 RUN_CHILD_ON_PIPE(BadMessageClient, child2)
1308 MojoHandle a, b, c, d;
1309 CreateMessagePipe(&a, &b);
1310 CreateMessagePipe(&c, &d);
1311 WriteMessageWithHandles(child1, "hi", &b, 1);
1312 WriteMessageWithHandles(child2, "hi", &d, 1);
1313
1314 // Read a message from the pipe we sent to child1 and flag it as bad.
1315 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(a, MOJO_HANDLE_SIGNAL_READABLE,
1316 MOJO_DEADLINE_INDEFINITE, nullptr));
1317 uint32_t num_bytes = 0;
1318 MojoMessageHandle message;
1319 ASSERT_EQ(MOJO_RESULT_OK,
1320 MojoReadMessageNew(a, &message, &num_bytes, nullptr, 0,
1321 MOJO_READ_MESSAGE_FLAG_NONE));
1322 EXPECT_EQ(MOJO_RESULT_OK,
1323 MojoNotifyBadMessage(message, kFirstErrorMessage.data(),
1324 kFirstErrorMessage.size()));
1325 EXPECT_EQ(MOJO_RESULT_OK, MojoFreeMessage(message));
1326
1327 // Read a message from the pipe we sent to child2 and flag it as bad.
1328 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(c, MOJO_HANDLE_SIGNAL_READABLE,
1329 MOJO_DEADLINE_INDEFINITE, nullptr));
1330 ASSERT_EQ(MOJO_RESULT_OK,
1331 MojoReadMessageNew(c, &message, &num_bytes, nullptr, 0,
1332 MOJO_READ_MESSAGE_FLAG_NONE));
1333 EXPECT_EQ(MOJO_RESULT_OK,
1334 MojoNotifyBadMessage(message, kSecondErrorMessage.data(),
1335 kSecondErrorMessage.size()));
1336 EXPECT_EQ(MOJO_RESULT_OK, MojoFreeMessage(message));
1337
1338 WriteMessage(child2, "bye");
1339 END_CHILD();
1340
1341 WriteMessage(child1, "bye");
1342 END_CHILD()
1343
1344 // The error messages should match the processes which triggered them.
1345 EXPECT_NE(std::string::npos, first_process_error.find(kFirstErrorMessage));
1346 EXPECT_NE(std::string::npos, second_process_error.find(kSecondErrorMessage));
1347 }
1348
1283 } // namespace 1349 } // namespace
1284 } // namespace edk 1350 } // namespace edk
1285 } // namespace mojo 1351 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_for_transit.h ('k') | mojo/edk/system/node_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698