| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 // Create a new shared buffer. | 120 // Create a new shared buffer. |
| 121 MojoHandle b = CreateBuffer(message.size()); | 121 MojoHandle b = CreateBuffer(message.size()); |
| 122 | 122 |
| 123 // Send a copy of the buffer to the parent and the other child. | 123 // Send a copy of the buffer to the parent and the other child. |
| 124 MojoHandle dupe = DuplicateBuffer(b, false); | 124 MojoHandle dupe = DuplicateBuffer(b, false); |
| 125 WriteMessageWithHandles(h, "", &b, 1); | 125 WriteMessageWithHandles(h, "", &b, 1); |
| 126 WriteMessageWithHandles(other_child, "", &dupe, 1); | 126 WriteMessageWithHandles(other_child, "", &dupe, 1); |
| 127 | 127 |
| 128 EXPECT_EQ("quit", ReadMessage(h)); | 128 EXPECT_EQ("quit", ReadMessage(h)); |
| 129 WriteMessage(h, "ok"); | |
| 130 } | 129 } |
| 131 | 130 |
| 132 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveAndEditBuffer, SharedBufferTest, h) { | 131 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveAndEditBuffer, SharedBufferTest, h) { |
| 133 // Receive a pipe handle over the primordial pipe. This will be connected to | 132 // Receive a pipe handle over the primordial pipe. This will be connected to |
| 134 // another child process (running CreateAndPassBuffer). | 133 // another child process (running CreateAndPassBuffer). |
| 135 MojoHandle other_child; | 134 MojoHandle other_child; |
| 136 std::string message = ReadMessageWithHandles(h, &other_child, 1); | 135 std::string message = ReadMessageWithHandles(h, &other_child, 1); |
| 137 | 136 |
| 138 // Receive a shared buffer from the other child. | 137 // Receive a shared buffer from the other child. |
| 139 MojoHandle b; | 138 MojoHandle b; |
| 140 ReadMessageWithHandles(other_child, &b, 1); | 139 ReadMessageWithHandles(other_child, &b, 1); |
| 141 | 140 |
| 142 // Write the message from the parent into the buffer and exit. | 141 // Write the message from the parent into the buffer and exit. |
| 143 WriteToBuffer(b, 0, message); | 142 WriteToBuffer(b, 0, message); |
| 144 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(b)); | 143 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(b)); |
| 145 EXPECT_EQ("quit", ReadMessage(h)); | 144 EXPECT_EQ("quit", ReadMessage(h)); |
| 146 WriteMessage(h, "ok"); | |
| 147 } | 145 } |
| 148 | 146 |
| 149 #if defined(OS_ANDROID) | 147 #if defined(OS_ANDROID) |
| 150 // Android multi-process tests are not executing the new process. This is flaky. | 148 // Android multi-process tests are not executing the new process. This is flaky. |
| 151 #define MAYBE_PassSharedBufferFromChildToChild \ | 149 #define MAYBE_PassSharedBufferFromChildToChild \ |
| 152 DISABLED_PassSharedBufferFromChildToChild | 150 DISABLED_PassSharedBufferFromChildToChild |
| 153 #else | 151 #else |
| 154 #define MAYBE_PassSharedBufferFromChildToChild PassSharedBufferFromChildToChild | 152 #define MAYBE_PassSharedBufferFromChildToChild PassSharedBufferFromChildToChild |
| 155 #endif | 153 #endif |
| 156 TEST_F(SharedBufferTest, MAYBE_PassSharedBufferFromChildToChild) { | 154 TEST_F(SharedBufferTest, MAYBE_PassSharedBufferFromChildToChild) { |
| 157 const std::string message = "hello"; | 155 const std::string message = "hello"; |
| 158 MojoHandle p0, p1; | 156 MojoHandle p0, p1; |
| 159 CreateMessagePipe(&p0, &p1); | 157 CreateMessagePipe(&p0, &p1); |
| 160 | 158 |
| 161 MojoHandle b; | 159 MojoHandle b; |
| 162 RUN_CHILD_ON_PIPE(CreateAndPassBuffer, h0) | 160 RUN_CHILD_ON_PIPE(CreateAndPassBuffer, h0) |
| 163 RUN_CHILD_ON_PIPE(ReceiveAndEditBuffer, h1) | 161 RUN_CHILD_ON_PIPE(ReceiveAndEditBuffer, h1) |
| 164 // Send one end of the pipe to each child. The first child will create | 162 // Send one end of the pipe to each child. The first child will create |
| 165 // and pass a buffer to the second child and back to us. The second child | 163 // and pass a buffer to the second child and back to us. The second child |
| 166 // will write our message into the buffer. | 164 // will write our message into the buffer. |
| 167 WriteMessageWithHandles(h0, message, &p0, 1); | 165 WriteMessageWithHandles(h0, message, &p0, 1); |
| 168 WriteMessageWithHandles(h1, message, &p1, 1); | 166 WriteMessageWithHandles(h1, message, &p1, 1); |
| 169 | 167 |
| 170 // Receive the buffer back from the first child. | 168 // Receive the buffer back from the first child. |
| 171 ReadMessageWithHandles(h0, &b, 1); | 169 ReadMessageWithHandles(h0, &b, 1); |
| 172 | 170 |
| 173 WriteMessage(h1, "quit"); | 171 WriteMessage(h1, "quit"); |
| 174 EXPECT_EQ("ok", ReadMessage(h1)); | |
| 175 END_CHILD() | 172 END_CHILD() |
| 176 WriteMessage(h0, "quit"); | 173 WriteMessage(h0, "quit"); |
| 177 EXPECT_EQ("ok", ReadMessage(h0)); | |
| 178 END_CHILD() | 174 END_CHILD() |
| 179 | 175 |
| 180 // The second child should have written this message. | 176 // The second child should have written this message. |
| 181 ExpectBufferContents(b, 0, message); | 177 ExpectBufferContents(b, 0, message); |
| 182 } | 178 } |
| 183 | 179 |
| 184 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CreateAndPassBufferParent, SharedBufferTest, | 180 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(CreateAndPassBufferParent, SharedBufferTest, |
| 185 parent) { | 181 parent) { |
| 186 RUN_CHILD_ON_PIPE(CreateAndPassBuffer, child) | 182 RUN_CHILD_ON_PIPE(CreateAndPassBuffer, child) |
| 187 // Read a pipe from the parent and forward it to our child. | 183 // Read a pipe from the parent and forward it to our child. |
| 188 MojoHandle pipe; | 184 MojoHandle pipe; |
| 189 std::string message = ReadMessageWithHandles(parent, &pipe, 1); | 185 std::string message = ReadMessageWithHandles(parent, &pipe, 1); |
| 190 | 186 |
| 191 WriteMessageWithHandles(child, message, &pipe, 1); | 187 WriteMessageWithHandles(child, message, &pipe, 1); |
| 192 | 188 |
| 193 // Read a buffer handle from the child and pass it back to the parent. | 189 // Read a buffer handle from the child and pass it back to the parent. |
| 194 MojoHandle buffer; | 190 MojoHandle buffer; |
| 195 EXPECT_EQ("", ReadMessageWithHandles(child, &buffer, 1)); | 191 EXPECT_EQ("", ReadMessageWithHandles(child, &buffer, 1)); |
| 196 WriteMessageWithHandles(parent, "", &buffer, 1); | 192 WriteMessageWithHandles(parent, "", &buffer, 1); |
| 197 | 193 |
| 198 EXPECT_EQ("quit", ReadMessage(parent)); | 194 EXPECT_EQ("quit", ReadMessage(parent)); |
| 199 WriteMessage(child, "quit"); | 195 WriteMessage(child, "quit"); |
| 200 EXPECT_EQ("ok", ReadMessage(child)); | |
| 201 WriteMessage(parent, "ok"); | |
| 202 END_CHILD() | 196 END_CHILD() |
| 203 } | 197 } |
| 204 | 198 |
| 205 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveAndEditBufferParent, SharedBufferTest, | 199 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceiveAndEditBufferParent, SharedBufferTest, |
| 206 parent) { | 200 parent) { |
| 207 RUN_CHILD_ON_PIPE(ReceiveAndEditBuffer, child) | 201 RUN_CHILD_ON_PIPE(ReceiveAndEditBuffer, child) |
| 208 // Read a pipe from the parent and forward it to our child. | 202 // Read a pipe from the parent and forward it to our child. |
| 209 MojoHandle pipe; | 203 MojoHandle pipe; |
| 210 std::string message = ReadMessageWithHandles(parent, &pipe, 1); | 204 std::string message = ReadMessageWithHandles(parent, &pipe, 1); |
| 211 WriteMessageWithHandles(child, message, &pipe, 1); | 205 WriteMessageWithHandles(child, message, &pipe, 1); |
| 212 | 206 |
| 213 EXPECT_EQ("quit", ReadMessage(parent)); | 207 EXPECT_EQ("quit", ReadMessage(parent)); |
| 214 WriteMessage(child, "quit"); | 208 WriteMessage(child, "quit"); |
| 215 EXPECT_EQ("ok", ReadMessage(child)); | |
| 216 WriteMessage(parent, "ok"); | |
| 217 END_CHILD() | 209 END_CHILD() |
| 218 } | 210 } |
| 219 | 211 |
| 220 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 212 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 221 // Android multi-process tests are not executing the new process. This is flaky. | 213 // Android multi-process tests are not executing the new process. This is flaky. |
| 222 // Passing shared memory handles between cousins is not currently supported on | 214 // Passing shared memory handles between cousins is not currently supported on |
| 223 // OSX. | 215 // OSX. |
| 224 #define MAYBE_PassHandleBetweenCousins DISABLED_PassHandleBetweenCousins | 216 #define MAYBE_PassHandleBetweenCousins DISABLED_PassHandleBetweenCousins |
| 225 #else | 217 #else |
| 226 #define MAYBE_PassHandleBetweenCousins PassHandleBetweenCousins | 218 #define MAYBE_PassHandleBetweenCousins PassHandleBetweenCousins |
| (...skipping 11 matching lines...) Expand all Loading... |
| 238 MojoHandle pipe[2]; | 230 MojoHandle pipe[2]; |
| 239 CreateMessagePipe(&pipe[0], &pipe[1]); | 231 CreateMessagePipe(&pipe[0], &pipe[1]); |
| 240 | 232 |
| 241 WriteMessageWithHandles(child1, message, &pipe[0], 1); | 233 WriteMessageWithHandles(child1, message, &pipe[0], 1); |
| 242 WriteMessageWithHandles(child2, message, &pipe[1], 1); | 234 WriteMessageWithHandles(child2, message, &pipe[1], 1); |
| 243 | 235 |
| 244 // Receive the buffer back from the first child. | 236 // Receive the buffer back from the first child. |
| 245 ReadMessageWithHandles(child1, &b, 1); | 237 ReadMessageWithHandles(child1, &b, 1); |
| 246 | 238 |
| 247 WriteMessage(child2, "quit"); | 239 WriteMessage(child2, "quit"); |
| 248 EXPECT_EQ("ok", ReadMessage(child2)); | |
| 249 END_CHILD() | 240 END_CHILD() |
| 250 WriteMessage(child1, "quit"); | 241 WriteMessage(child1, "quit"); |
| 251 EXPECT_EQ("ok", ReadMessage(child1)); | |
| 252 END_CHILD() | 242 END_CHILD() |
| 253 | 243 |
| 254 // The second grandchild should have written this message. | 244 // The second grandchild should have written this message. |
| 255 ExpectBufferContents(b, 0, message); | 245 ExpectBufferContents(b, 0, message); |
| 256 } | 246 } |
| 257 | 247 |
| 258 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReadAndMapWriteSharedBuffer, | 248 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReadAndMapWriteSharedBuffer, |
| 259 SharedBufferTest, h) { | 249 SharedBufferTest, h) { |
| 260 // Receive the shared buffer. | 250 // Receive the shared buffer. |
| 261 MojoHandle b; | 251 MojoHandle b; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 WriteMessage(h, "quit"); | 328 WriteMessage(h, "quit"); |
| 339 EXPECT_EQ("ok", ReadMessage(h)); | 329 EXPECT_EQ("ok", ReadMessage(h)); |
| 340 END_CHILD() | 330 END_CHILD() |
| 341 } | 331 } |
| 342 | 332 |
| 343 #endif // !defined(OS_IOS) | 333 #endif // !defined(OS_IOS) |
| 344 | 334 |
| 345 } // namespace | 335 } // namespace |
| 346 } // namespace edk | 336 } // namespace edk |
| 347 } // namespace mojo | 337 } // namespace mojo |
| OLD | NEW |