| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_channel_mojo.h" | 5 #include "ipc/ipc_channel_mojo.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 31 #include "ipc/ipc_message.h" | 31 #include "ipc/ipc_message.h" |
| 32 #include "ipc/ipc_mojo_handle_attachment.h" | 32 #include "ipc/ipc_mojo_handle_attachment.h" |
| 33 #include "ipc/ipc_mojo_message_helper.h" | 33 #include "ipc/ipc_mojo_message_helper.h" |
| 34 #include "ipc/ipc_mojo_param_traits.h" | 34 #include "ipc/ipc_mojo_param_traits.h" |
| 35 #include "ipc/ipc_sync_channel.h" | 35 #include "ipc/ipc_sync_channel.h" |
| 36 #include "ipc/ipc_sync_message.h" | 36 #include "ipc/ipc_sync_message.h" |
| 37 #include "ipc/ipc_test.mojom.h" | 37 #include "ipc/ipc_test.mojom.h" |
| 38 #include "ipc/ipc_test_base.h" | 38 #include "ipc/ipc_test_base.h" |
| 39 #include "ipc/ipc_test_channel_listener.h" | 39 #include "ipc/ipc_test_channel_listener.h" |
| 40 #include "mojo/edk/test/mojo_test_base.h" | |
| 41 #include "mojo/edk/test/multiprocess_test_helper.h" | |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 43 | 41 |
| 44 #if defined(OS_POSIX) | 42 #if defined(OS_POSIX) |
| 45 #include "base/file_descriptor_posix.h" | 43 #include "base/file_descriptor_posix.h" |
| 46 #include "ipc/ipc_platform_file_attachment_posix.h" | 44 #include "ipc/ipc_platform_file_attachment_posix.h" |
| 47 #endif | 45 #endif |
| 48 | 46 |
| 49 #define DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(client_name, test_base) \ | |
| 50 class client_name##_MainFixture : public test_base { \ | |
| 51 public: \ | |
| 52 void Main(); \ | |
| 53 }; \ | |
| 54 MULTIPROCESS_TEST_MAIN_WITH_SETUP( \ | |
| 55 client_name##TestChildMain, \ | |
| 56 ::mojo::edk::test::MultiprocessTestHelper::ChildSetup) { \ | |
| 57 client_name##_MainFixture test; \ | |
| 58 test.Init( \ | |
| 59 std::move(mojo::edk::test::MultiprocessTestHelper::primordial_pipe)); \ | |
| 60 test.Main(); \ | |
| 61 return (::testing::Test::HasFatalFailure() || \ | |
| 62 ::testing::Test::HasNonfatalFailure()) \ | |
| 63 ? 1 \ | |
| 64 : 0; \ | |
| 65 } \ | |
| 66 void client_name##_MainFixture::Main() | |
| 67 | |
| 68 namespace { | 47 namespace { |
| 69 | 48 |
| 70 void SendString(IPC::Sender* sender, const std::string& str) { | 49 void SendString(IPC::Sender* sender, const std::string& str) { |
| 71 IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL); | 50 IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL); |
| 72 message->WriteString(str); | 51 message->WriteString(str); |
| 73 ASSERT_TRUE(sender->Send(message)); | 52 ASSERT_TRUE(sender->Send(message)); |
| 74 } | 53 } |
| 75 | 54 |
| 76 void SendValue(IPC::Sender* sender, int32_t value) { | 55 void SendValue(IPC::Sender* sender, int32_t value) { |
| 77 IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL); | 56 IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 101 // process dies. | 80 // process dies. |
| 102 DCHECK(received_ok_); | 81 DCHECK(received_ok_); |
| 103 } | 82 } |
| 104 | 83 |
| 105 static void SendOK(IPC::Sender* sender) { SendString(sender, "OK"); } | 84 static void SendOK(IPC::Sender* sender) { SendString(sender, "OK"); } |
| 106 | 85 |
| 107 private: | 86 private: |
| 108 bool received_ok_; | 87 bool received_ok_; |
| 109 }; | 88 }; |
| 110 | 89 |
| 111 class ChannelClient { | 90 using IPCChannelMojoTest = IPCChannelMojoTestBase; |
| 112 public: | |
| 113 void Init(mojo::ScopedMessagePipeHandle handle) { | |
| 114 handle_ = std::move(handle); | |
| 115 } | |
| 116 | |
| 117 void Connect(IPC::Listener* listener) { | |
| 118 channel_ = IPC::ChannelMojo::Create( | |
| 119 std::move(handle_), IPC::Channel::MODE_CLIENT, listener, | |
| 120 base::ThreadTaskRunnerHandle::Get()); | |
| 121 CHECK(channel_->Connect()); | |
| 122 } | |
| 123 | |
| 124 void Close() { | |
| 125 channel_->Close(); | |
| 126 | |
| 127 base::RunLoop run_loop; | |
| 128 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | |
| 129 run_loop.QuitClosure()); | |
| 130 run_loop.Run(); | |
| 131 } | |
| 132 | |
| 133 IPC::ChannelMojo* channel() const { return channel_.get(); } | |
| 134 | |
| 135 private: | |
| 136 base::MessageLoopForIO main_message_loop_; | |
| 137 mojo::ScopedMessagePipeHandle handle_; | |
| 138 std::unique_ptr<IPC::ChannelMojo> channel_; | |
| 139 }; | |
| 140 | |
| 141 class IPCChannelMojoTestBase : public testing::Test { | |
| 142 public: | |
| 143 void InitWithMojo(const std::string& test_client_name) { | |
| 144 handle_ = helper_.StartChild(test_client_name); | |
| 145 } | |
| 146 | |
| 147 bool WaitForClientShutdown() { return helper_.WaitForChildTestShutdown(); } | |
| 148 | |
| 149 protected: | |
| 150 mojo::ScopedMessagePipeHandle TakeHandle() { return std::move(handle_); } | |
| 151 | |
| 152 private: | |
| 153 mojo::ScopedMessagePipeHandle handle_; | |
| 154 mojo::edk::test::MultiprocessTestHelper helper_; | |
| 155 }; | |
| 156 | |
| 157 class IPCChannelMojoTest : public IPCChannelMojoTestBase { | |
| 158 public: | |
| 159 void TearDown() override { base::RunLoop().RunUntilIdle(); } | |
| 160 | |
| 161 void CreateChannel(IPC::Listener* listener) { | |
| 162 channel_ = IPC::ChannelMojo::Create( | |
| 163 TakeHandle(), IPC::Channel::MODE_SERVER, listener, | |
| 164 base::ThreadTaskRunnerHandle::Get()); | |
| 165 } | |
| 166 | |
| 167 bool ConnectChannel() { return channel_->Connect(); } | |
| 168 | |
| 169 void DestroyChannel() { channel_.reset(); } | |
| 170 | |
| 171 IPC::Sender* sender() { return channel(); } | |
| 172 IPC::Channel* channel() { return channel_.get(); } | |
| 173 | |
| 174 private: | |
| 175 base::MessageLoop message_loop_; | |
| 176 std::unique_ptr<IPC::Channel> channel_; | |
| 177 }; | |
| 178 | 91 |
| 179 class TestChannelListenerWithExtraExpectations | 92 class TestChannelListenerWithExtraExpectations |
| 180 : public IPC::TestChannelListener { | 93 : public IPC::TestChannelListener { |
| 181 public: | 94 public: |
| 182 TestChannelListenerWithExtraExpectations() : is_connected_called_(false) {} | 95 TestChannelListenerWithExtraExpectations() : is_connected_called_(false) {} |
| 183 | 96 |
| 184 void OnChannelConnected(int32_t peer_pid) override { | 97 void OnChannelConnected(int32_t peer_pid) override { |
| 185 IPC::TestChannelListener::OnChannelConnected(peer_pid); | 98 IPC::TestChannelListener::OnChannelConnected(peer_pid); |
| 186 EXPECT_TRUE(base::kNullProcessId != peer_pid); | 99 EXPECT_TRUE(base::kNullProcessId != peer_pid); |
| 187 is_connected_called_ = true; | 100 is_connected_called_ = true; |
| 188 } | 101 } |
| 189 | 102 |
| 190 bool is_connected_called() const { return is_connected_called_; } | 103 bool is_connected_called() const { return is_connected_called_; } |
| 191 | 104 |
| 192 private: | 105 private: |
| 193 bool is_connected_called_; | 106 bool is_connected_called_; |
| 194 }; | 107 }; |
| 195 | 108 |
| 196 TEST_F(IPCChannelMojoTest, ConnectedFromClient) { | 109 TEST_F(IPCChannelMojoTest, ConnectedFromClient) { |
| 197 InitWithMojo("IPCChannelMojoTestClient"); | 110 Init("IPCChannelMojoTestClient"); |
| 198 | 111 |
| 199 // Set up IPC channel and start client. | 112 // Set up IPC channel and start client. |
| 200 TestChannelListenerWithExtraExpectations listener; | 113 TestChannelListenerWithExtraExpectations listener; |
| 201 CreateChannel(&listener); | 114 CreateChannel(&listener); |
| 202 listener.Init(sender()); | 115 listener.Init(sender()); |
| 203 ASSERT_TRUE(ConnectChannel()); | 116 ASSERT_TRUE(ConnectChannel()); |
| 204 | 117 |
| 205 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); | 118 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); |
| 206 | 119 |
| 207 base::RunLoop().Run(); | 120 base::RunLoop().Run(); |
| 208 | 121 |
| 209 channel()->Close(); | 122 channel()->Close(); |
| 210 | 123 |
| 211 EXPECT_TRUE(WaitForClientShutdown()); | 124 EXPECT_TRUE(WaitForClientShutdown()); |
| 212 EXPECT_TRUE(listener.is_connected_called()); | 125 EXPECT_TRUE(listener.is_connected_called()); |
| 213 EXPECT_TRUE(listener.HasSentAll()); | 126 EXPECT_TRUE(listener.HasSentAll()); |
| 214 | 127 |
| 215 DestroyChannel(); | 128 DestroyChannel(); |
| 216 } | 129 } |
| 217 | 130 |
| 218 // A long running process that connects to us | 131 // A long running process that connects to us |
| 219 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestClient, ChannelClient) { | 132 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestClient) { |
| 220 TestChannelListenerWithExtraExpectations listener; | 133 TestChannelListenerWithExtraExpectations listener; |
| 221 Connect(&listener); | 134 Connect(&listener); |
| 222 listener.Init(channel()); | 135 listener.Init(channel()); |
| 223 | 136 |
| 224 IPC::TestChannelListener::SendOneMessage(channel(), "hello from child"); | 137 IPC::TestChannelListener::SendOneMessage(channel(), "hello from child"); |
| 225 base::RunLoop().Run(); | 138 base::RunLoop().Run(); |
| 226 EXPECT_TRUE(listener.is_connected_called()); | 139 EXPECT_TRUE(listener.is_connected_called()); |
| 227 EXPECT_TRUE(listener.HasSentAll()); | 140 EXPECT_TRUE(listener.HasSentAll()); |
| 228 | 141 |
| 229 Close(); | 142 Close(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 251 ListenerThatQuits() {} | 164 ListenerThatQuits() {} |
| 252 | 165 |
| 253 bool OnMessageReceived(const IPC::Message& message) override { return true; } | 166 bool OnMessageReceived(const IPC::Message& message) override { return true; } |
| 254 | 167 |
| 255 void OnChannelConnected(int32_t peer_pid) override { | 168 void OnChannelConnected(int32_t peer_pid) override { |
| 256 base::MessageLoop::current()->QuitWhenIdle(); | 169 base::MessageLoop::current()->QuitWhenIdle(); |
| 257 } | 170 } |
| 258 }; | 171 }; |
| 259 | 172 |
| 260 // A long running process that connects to us. | 173 // A long running process that connects to us. |
| 261 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoErraticTestClient, | 174 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoErraticTestClient) { |
| 262 ChannelClient) { | |
| 263 ListenerThatQuits listener; | 175 ListenerThatQuits listener; |
| 264 Connect(&listener); | 176 Connect(&listener); |
| 265 | 177 |
| 266 base::RunLoop().Run(); | 178 base::RunLoop().Run(); |
| 267 | 179 |
| 268 Close(); | 180 Close(); |
| 269 } | 181 } |
| 270 | 182 |
| 271 TEST_F(IPCChannelMojoTest, SendFailWithPendingMessages) { | 183 TEST_F(IPCChannelMojoTest, SendFailWithPendingMessages) { |
| 272 InitWithMojo("IPCChannelMojoErraticTestClient"); | 184 Init("IPCChannelMojoErraticTestClient"); |
| 273 | 185 |
| 274 // Set up IPC channel and start client. | 186 // Set up IPC channel and start client. |
| 275 ListenerExpectingErrors listener; | 187 ListenerExpectingErrors listener; |
| 276 CreateChannel(&listener); | 188 CreateChannel(&listener); |
| 277 ASSERT_TRUE(ConnectChannel()); | 189 ASSERT_TRUE(ConnectChannel()); |
| 278 | 190 |
| 279 // This matches a value in mojo/edk/system/constants.h | 191 // This matches a value in mojo/edk/system/constants.h |
| 280 const int kMaxMessageNumBytes = 4 * 1024 * 1024; | 192 const int kMaxMessageNumBytes = 4 * 1024 * 1024; |
| 281 std::string overly_large_data(kMaxMessageNumBytes, '*'); | 193 std::string overly_large_data(kMaxMessageNumBytes, '*'); |
| 282 // This messages are queued as pending. | 194 // This messages are queued as pending. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 base::MessageLoop::current()->QuitWhenIdle(); | 318 base::MessageLoop::current()->QuitWhenIdle(); |
| 407 } | 319 } |
| 408 | 320 |
| 409 void set_sender(IPC::Sender* sender) { sender_ = sender; } | 321 void set_sender(IPC::Sender* sender) { sender_ = sender; } |
| 410 | 322 |
| 411 private: | 323 private: |
| 412 IPC::Sender* sender_; | 324 IPC::Sender* sender_; |
| 413 }; | 325 }; |
| 414 | 326 |
| 415 TEST_F(IPCChannelMojoTest, SendMessagePipe) { | 327 TEST_F(IPCChannelMojoTest, SendMessagePipe) { |
| 416 InitWithMojo("IPCChannelMojoTestSendMessagePipeClient"); | 328 Init("IPCChannelMojoTestSendMessagePipeClient"); |
| 417 | 329 |
| 418 ListenerThatExpectsOK listener; | 330 ListenerThatExpectsOK listener; |
| 419 CreateChannel(&listener); | 331 CreateChannel(&listener); |
| 420 ASSERT_TRUE(ConnectChannel()); | 332 ASSERT_TRUE(ConnectChannel()); |
| 421 | 333 |
| 422 TestingMessagePipe pipe; | 334 TestingMessagePipe pipe; |
| 423 HandleSendingHelper::WritePipeThenSend(channel(), &pipe); | 335 HandleSendingHelper::WritePipeThenSend(channel(), &pipe); |
| 424 | 336 |
| 425 base::RunLoop().Run(); | 337 base::RunLoop().Run(); |
| 426 channel()->Close(); | 338 channel()->Close(); |
| 427 | 339 |
| 428 EXPECT_TRUE(WaitForClientShutdown()); | 340 EXPECT_TRUE(WaitForClientShutdown()); |
| 429 DestroyChannel(); | 341 DestroyChannel(); |
| 430 } | 342 } |
| 431 | 343 |
| 432 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendMessagePipeClient, | 344 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendMessagePipeClient) { |
| 433 ChannelClient) { | |
| 434 ListenerThatExpectsMessagePipe listener; | 345 ListenerThatExpectsMessagePipe listener; |
| 435 Connect(&listener); | 346 Connect(&listener); |
| 436 listener.set_sender(channel()); | 347 listener.set_sender(channel()); |
| 437 | 348 |
| 438 base::RunLoop().Run(); | 349 base::RunLoop().Run(); |
| 439 | 350 |
| 440 Close(); | 351 Close(); |
| 441 } | 352 } |
| 442 | 353 |
| 443 void ReadOK(mojo::MessagePipeHandle pipe) { | 354 void ReadOK(mojo::MessagePipeHandle pipe) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 base::MessageLoop::current()->QuitWhenIdle(); | 395 base::MessageLoop::current()->QuitWhenIdle(); |
| 485 } | 396 } |
| 486 | 397 |
| 487 void set_sender(IPC::Sender* sender) { sender_ = sender; } | 398 void set_sender(IPC::Sender* sender) { sender_ = sender; } |
| 488 | 399 |
| 489 private: | 400 private: |
| 490 IPC::Sender* sender_; | 401 IPC::Sender* sender_; |
| 491 bool receiving_valid_; | 402 bool receiving_valid_; |
| 492 }; | 403 }; |
| 493 | 404 |
| 494 class ParamTraitMessagePipeClient : public ChannelClient { | 405 class ParamTraitMessagePipeClient : public IpcChannelMojoTestClient { |
| 495 public: | 406 public: |
| 496 void RunTest(bool receiving_valid_handle) { | 407 void RunTest(bool receiving_valid_handle) { |
| 497 ListenerThatExpectsMessagePipeUsingParamTrait listener( | 408 ListenerThatExpectsMessagePipeUsingParamTrait listener( |
| 498 receiving_valid_handle); | 409 receiving_valid_handle); |
| 499 Connect(&listener); | 410 Connect(&listener); |
| 500 listener.set_sender(channel()); | 411 listener.set_sender(channel()); |
| 501 | 412 |
| 502 base::RunLoop().Run(); | 413 base::RunLoop().Run(); |
| 503 | 414 |
| 504 Close(); | 415 Close(); |
| 505 } | 416 } |
| 506 }; | 417 }; |
| 507 | 418 |
| 508 TEST_F(IPCChannelMojoTest, ParamTraitValidMessagePipe) { | 419 TEST_F(IPCChannelMojoTest, ParamTraitValidMessagePipe) { |
| 509 InitWithMojo("ParamTraitValidMessagePipeClient"); | 420 Init("ParamTraitValidMessagePipeClient"); |
| 510 | 421 |
| 511 ListenerThatExpectsOK listener; | 422 ListenerThatExpectsOK listener; |
| 512 CreateChannel(&listener); | 423 CreateChannel(&listener); |
| 513 ASSERT_TRUE(ConnectChannel()); | 424 ASSERT_TRUE(ConnectChannel()); |
| 514 | 425 |
| 515 TestingMessagePipe pipe; | 426 TestingMessagePipe pipe; |
| 516 | 427 |
| 517 std::unique_ptr<IPC::Message> message(new IPC::Message()); | 428 std::unique_ptr<IPC::Message> message(new IPC::Message()); |
| 518 IPC::ParamTraits<mojo::MessagePipeHandle>::Write(message.get(), | 429 IPC::ParamTraits<mojo::MessagePipeHandle>::Write(message.get(), |
| 519 pipe.peer.release()); | 430 pipe.peer.release()); |
| 520 WriteOK(pipe.self.get()); | 431 WriteOK(pipe.self.get()); |
| 521 | 432 |
| 522 channel()->Send(message.release()); | 433 channel()->Send(message.release()); |
| 523 base::RunLoop().Run(); | 434 base::RunLoop().Run(); |
| 524 channel()->Close(); | 435 channel()->Close(); |
| 525 | 436 |
| 526 EXPECT_TRUE(WaitForClientShutdown()); | 437 EXPECT_TRUE(WaitForClientShutdown()); |
| 527 DestroyChannel(); | 438 DestroyChannel(); |
| 528 } | 439 } |
| 529 | 440 |
| 530 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ParamTraitValidMessagePipeClient, | 441 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE( |
| 531 ParamTraitMessagePipeClient) { | 442 ParamTraitValidMessagePipeClient, |
| 443 ParamTraitMessagePipeClient) { |
| 532 RunTest(true); | 444 RunTest(true); |
| 533 } | 445 } |
| 534 | 446 |
| 535 TEST_F(IPCChannelMojoTest, ParamTraitInvalidMessagePipe) { | 447 TEST_F(IPCChannelMojoTest, ParamTraitInvalidMessagePipe) { |
| 536 InitWithMojo("ParamTraitInvalidMessagePipeClient"); | 448 Init("ParamTraitInvalidMessagePipeClient"); |
| 537 | 449 |
| 538 ListenerThatExpectsOK listener; | 450 ListenerThatExpectsOK listener; |
| 539 CreateChannel(&listener); | 451 CreateChannel(&listener); |
| 540 ASSERT_TRUE(ConnectChannel()); | 452 ASSERT_TRUE(ConnectChannel()); |
| 541 | 453 |
| 542 mojo::MessagePipeHandle invalid_handle; | 454 mojo::MessagePipeHandle invalid_handle; |
| 543 std::unique_ptr<IPC::Message> message(new IPC::Message()); | 455 std::unique_ptr<IPC::Message> message(new IPC::Message()); |
| 544 IPC::ParamTraits<mojo::MessagePipeHandle>::Write(message.get(), | 456 IPC::ParamTraits<mojo::MessagePipeHandle>::Write(message.get(), |
| 545 invalid_handle); | 457 invalid_handle); |
| 546 | 458 |
| 547 channel()->Send(message.release()); | 459 channel()->Send(message.release()); |
| 548 base::RunLoop().Run(); | 460 base::RunLoop().Run(); |
| 549 channel()->Close(); | 461 channel()->Close(); |
| 550 | 462 |
| 551 EXPECT_TRUE(WaitForClientShutdown()); | 463 EXPECT_TRUE(WaitForClientShutdown()); |
| 552 DestroyChannel(); | 464 DestroyChannel(); |
| 553 } | 465 } |
| 554 | 466 |
| 555 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ParamTraitInvalidMessagePipeClient, | 467 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE( |
| 556 ParamTraitMessagePipeClient) { | 468 ParamTraitInvalidMessagePipeClient, |
| 469 ParamTraitMessagePipeClient) { |
| 557 RunTest(false); | 470 RunTest(false); |
| 558 } | 471 } |
| 559 | 472 |
| 560 TEST_F(IPCChannelMojoTest, SendFailAfterClose) { | 473 TEST_F(IPCChannelMojoTest, SendFailAfterClose) { |
| 561 InitWithMojo("IPCChannelMojoTestSendOkClient"); | 474 Init("IPCChannelMojoTestSendOkClient"); |
| 562 | 475 |
| 563 ListenerThatExpectsOK listener; | 476 ListenerThatExpectsOK listener; |
| 564 CreateChannel(&listener); | 477 CreateChannel(&listener); |
| 565 ASSERT_TRUE(ConnectChannel()); | 478 ASSERT_TRUE(ConnectChannel()); |
| 566 | 479 |
| 567 base::RunLoop().Run(); | 480 base::RunLoop().Run(); |
| 568 channel()->Close(); | 481 channel()->Close(); |
| 569 ASSERT_FALSE(channel()->Send(new IPC::Message())); | 482 ASSERT_FALSE(channel()->Send(new IPC::Message())); |
| 570 | 483 |
| 571 EXPECT_TRUE(WaitForClientShutdown()); | 484 EXPECT_TRUE(WaitForClientShutdown()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 582 ListenerThatExpectsOK::SendOK(sender_); | 495 ListenerThatExpectsOK::SendOK(sender_); |
| 583 base::MessageLoop::current()->QuitWhenIdle(); | 496 base::MessageLoop::current()->QuitWhenIdle(); |
| 584 } | 497 } |
| 585 | 498 |
| 586 void set_sender(IPC::Sender* sender) { sender_ = sender; } | 499 void set_sender(IPC::Sender* sender) { sender_ = sender; } |
| 587 | 500 |
| 588 private: | 501 private: |
| 589 IPC::Sender* sender_; | 502 IPC::Sender* sender_; |
| 590 }; | 503 }; |
| 591 | 504 |
| 592 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendOkClient, | 505 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendOkClient) { |
| 593 ChannelClient) { | |
| 594 ListenerSendingOneOk listener; | 506 ListenerSendingOneOk listener; |
| 595 Connect(&listener); | 507 Connect(&listener); |
| 596 listener.set_sender(channel()); | 508 listener.set_sender(channel()); |
| 597 | 509 |
| 598 base::RunLoop().Run(); | 510 base::RunLoop().Run(); |
| 599 | 511 |
| 600 Close(); | 512 Close(); |
| 601 } | 513 } |
| 602 | 514 |
| 603 class ListenerWithSimpleAssociatedInterface | 515 class ListenerWithSimpleAssociatedInterface |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 void set_channel(IPC::Channel* channel) { channel_ = channel; } | 600 void set_channel(IPC::Channel* channel) { channel_ = channel; } |
| 689 | 601 |
| 690 private: | 602 private: |
| 691 static void OnQuitAck() { base::MessageLoop::current()->QuitWhenIdle(); } | 603 static void OnQuitAck() { base::MessageLoop::current()->QuitWhenIdle(); } |
| 692 | 604 |
| 693 IPC::Channel* channel_ = nullptr; | 605 IPC::Channel* channel_ = nullptr; |
| 694 IPC::mojom::SimpleTestDriverAssociatedPtr driver_; | 606 IPC::mojom::SimpleTestDriverAssociatedPtr driver_; |
| 695 }; | 607 }; |
| 696 | 608 |
| 697 TEST_F(IPCChannelMojoTest, SimpleAssociatedInterface) { | 609 TEST_F(IPCChannelMojoTest, SimpleAssociatedInterface) { |
| 698 InitWithMojo("SimpleAssociatedInterfaceClient"); | 610 Init("SimpleAssociatedInterfaceClient"); |
| 699 | 611 |
| 700 ListenerWithSimpleAssociatedInterface listener; | 612 ListenerWithSimpleAssociatedInterface listener; |
| 701 CreateChannel(&listener); | 613 CreateChannel(&listener); |
| 702 ASSERT_TRUE(ConnectChannel()); | 614 ASSERT_TRUE(ConnectChannel()); |
| 703 | 615 |
| 704 listener.RegisterInterfaceFactory(channel()); | 616 listener.RegisterInterfaceFactory(channel()); |
| 705 | 617 |
| 706 base::RunLoop().Run(); | 618 base::RunLoop().Run(); |
| 707 channel()->Close(); | 619 channel()->Close(); |
| 708 | 620 |
| 709 EXPECT_TRUE(WaitForClientShutdown()); | 621 EXPECT_TRUE(WaitForClientShutdown()); |
| 710 DestroyChannel(); | 622 DestroyChannel(); |
| 711 } | 623 } |
| 712 | 624 |
| 713 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(SimpleAssociatedInterfaceClient, | 625 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(SimpleAssociatedInterfaceClient) { |
| 714 ChannelClient) { | |
| 715 ListenerSendingAssociatedMessages listener; | 626 ListenerSendingAssociatedMessages listener; |
| 716 Connect(&listener); | 627 Connect(&listener); |
| 717 listener.set_channel(channel()); | 628 listener.set_channel(channel()); |
| 718 | 629 |
| 719 base::RunLoop().Run(); | 630 base::RunLoop().Run(); |
| 720 | 631 |
| 721 Close(); | 632 Close(); |
| 722 } | 633 } |
| 723 | 634 |
| 724 class ChannelProxyRunner { | 635 class ChannelProxyRunner { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 mojo::ScopedMessagePipeHandle handle_; | 670 mojo::ScopedMessagePipeHandle handle_; |
| 760 base::Thread io_thread_; | 671 base::Thread io_thread_; |
| 761 std::unique_ptr<IPC::ChannelProxy> proxy_; | 672 std::unique_ptr<IPC::ChannelProxy> proxy_; |
| 762 base::WaitableEvent never_signaled_; | 673 base::WaitableEvent never_signaled_; |
| 763 | 674 |
| 764 DISALLOW_COPY_AND_ASSIGN(ChannelProxyRunner); | 675 DISALLOW_COPY_AND_ASSIGN(ChannelProxyRunner); |
| 765 }; | 676 }; |
| 766 | 677 |
| 767 class IPCChannelProxyMojoTest : public IPCChannelMojoTestBase { | 678 class IPCChannelProxyMojoTest : public IPCChannelMojoTestBase { |
| 768 public: | 679 public: |
| 769 void InitWithMojo(const std::string& client_name) { | 680 void Init(const std::string& client_name) { |
| 770 IPCChannelMojoTestBase::InitWithMojo(client_name); | 681 IPCChannelMojoTestBase::Init(client_name); |
| 771 runner_.reset(new ChannelProxyRunner(TakeHandle(), true)); | 682 runner_.reset(new ChannelProxyRunner(TakeHandle(), true)); |
| 772 } | 683 } |
| 773 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } | 684 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } |
| 774 void RunProxy() { | 685 void RunProxy() { |
| 775 runner_->RunProxy(); | 686 runner_->RunProxy(); |
| 776 } | 687 } |
| 777 void DestroyProxy() { | 688 void DestroyProxy() { |
| 778 runner_.reset(); | 689 runner_.reset(); |
| 779 base::RunLoop().RunUntilIdle(); | 690 base::RunLoop().RunUntilIdle(); |
| 780 } | 691 } |
| 781 | 692 |
| 782 IPC::ChannelProxy* proxy() { return runner_->proxy(); } | 693 IPC::ChannelProxy* proxy() { return runner_->proxy(); } |
| 783 | 694 |
| 784 private: | 695 private: |
| 785 base::MessageLoop message_loop_; | |
| 786 std::unique_ptr<ChannelProxyRunner> runner_; | 696 std::unique_ptr<ChannelProxyRunner> runner_; |
| 787 }; | 697 }; |
| 788 | 698 |
| 789 class ListenerWithSimpleProxyAssociatedInterface | 699 class ListenerWithSimpleProxyAssociatedInterface |
| 790 : public IPC::Listener, | 700 : public IPC::Listener, |
| 791 public IPC::mojom::SimpleTestDriver { | 701 public IPC::mojom::SimpleTestDriver { |
| 792 public: | 702 public: |
| 793 static const int kNumMessages; | 703 static const int kNumMessages; |
| 794 | 704 |
| 795 ListenerWithSimpleProxyAssociatedInterface() : binding_(this) {} | 705 ListenerWithSimpleProxyAssociatedInterface() : binding_(this) {} |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 int32_t next_expected_value_ = 0; | 761 int32_t next_expected_value_ = 0; |
| 852 int num_messages_received_ = 0; | 762 int num_messages_received_ = 0; |
| 853 bool received_quit_ = false; | 763 bool received_quit_ = false; |
| 854 | 764 |
| 855 mojo::AssociatedBinding<IPC::mojom::SimpleTestDriver> binding_; | 765 mojo::AssociatedBinding<IPC::mojom::SimpleTestDriver> binding_; |
| 856 }; | 766 }; |
| 857 | 767 |
| 858 const int ListenerWithSimpleProxyAssociatedInterface::kNumMessages = 1000; | 768 const int ListenerWithSimpleProxyAssociatedInterface::kNumMessages = 1000; |
| 859 | 769 |
| 860 TEST_F(IPCChannelProxyMojoTest, ProxyThreadAssociatedInterface) { | 770 TEST_F(IPCChannelProxyMojoTest, ProxyThreadAssociatedInterface) { |
| 861 InitWithMojo("ProxyThreadAssociatedInterfaceClient"); | 771 Init("ProxyThreadAssociatedInterfaceClient"); |
| 862 | 772 |
| 863 ListenerWithSimpleProxyAssociatedInterface listener; | 773 ListenerWithSimpleProxyAssociatedInterface listener; |
| 864 CreateProxy(&listener); | 774 CreateProxy(&listener); |
| 865 RunProxy(); | 775 RunProxy(); |
| 866 | 776 |
| 867 base::RunLoop().Run(); | 777 base::RunLoop().Run(); |
| 868 | 778 |
| 869 EXPECT_TRUE(WaitForClientShutdown()); | 779 EXPECT_TRUE(WaitForClientShutdown()); |
| 870 EXPECT_TRUE(listener.received_all_messages()); | 780 EXPECT_TRUE(listener.received_all_messages()); |
| 871 | 781 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 899 base::MessageLoop message_loop_; | 809 base::MessageLoop message_loop_; |
| 900 std::unique_ptr<ChannelProxyRunner> runner_; | 810 std::unique_ptr<ChannelProxyRunner> runner_; |
| 901 }; | 811 }; |
| 902 | 812 |
| 903 class DummyListener : public IPC::Listener { | 813 class DummyListener : public IPC::Listener { |
| 904 public: | 814 public: |
| 905 // IPC::Listener | 815 // IPC::Listener |
| 906 bool OnMessageReceived(const IPC::Message& message) override { return true; } | 816 bool OnMessageReceived(const IPC::Message& message) override { return true; } |
| 907 }; | 817 }; |
| 908 | 818 |
| 909 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ProxyThreadAssociatedInterfaceClient, | 819 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE( |
| 910 ChannelProxyClient) { | 820 ProxyThreadAssociatedInterfaceClient, |
| 821 ChannelProxyClient) { |
| 911 DummyListener listener; | 822 DummyListener listener; |
| 912 CreateProxy(&listener); | 823 CreateProxy(&listener); |
| 913 RunProxy(); | 824 RunProxy(); |
| 914 | 825 |
| 915 // Send a bunch of interleaved messages, alternating between the associated | 826 // Send a bunch of interleaved messages, alternating between the associated |
| 916 // interface and a legacy IPC::Message. | 827 // interface and a legacy IPC::Message. |
| 917 IPC::mojom::SimpleTestDriverAssociatedPtr driver; | 828 IPC::mojom::SimpleTestDriverAssociatedPtr driver; |
| 918 proxy()->GetRemoteAssociatedInterface(&driver); | 829 proxy()->GetRemoteAssociatedInterface(&driver); |
| 919 for (int i = 0; i < ListenerWithSimpleProxyAssociatedInterface::kNumMessages; | 830 for (int i = 0; i < ListenerWithSimpleProxyAssociatedInterface::kNumMessages; |
| 920 ++i) { | 831 ++i) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 mojo::AssociatedBinding<IPC::mojom::PingReceiver> ping_receiver_binding_; | 881 mojo::AssociatedBinding<IPC::mojom::PingReceiver> ping_receiver_binding_; |
| 971 | 882 |
| 972 base::Closure ping_handler_; | 883 base::Closure ping_handler_; |
| 973 }; | 884 }; |
| 974 | 885 |
| 975 TEST_F(IPCChannelProxyMojoTest, ProxyThreadAssociatedInterfaceIndirect) { | 886 TEST_F(IPCChannelProxyMojoTest, ProxyThreadAssociatedInterfaceIndirect) { |
| 976 // Tests that we can pipeline interface requests and subsequent messages | 887 // Tests that we can pipeline interface requests and subsequent messages |
| 977 // targeting proxy thread bindings, and the channel will still dispatch | 888 // targeting proxy thread bindings, and the channel will still dispatch |
| 978 // messages appropriately. | 889 // messages appropriately. |
| 979 | 890 |
| 980 InitWithMojo("ProxyThreadAssociatedInterfaceIndirectClient"); | 891 Init("ProxyThreadAssociatedInterfaceIndirectClient"); |
| 981 | 892 |
| 982 ListenerWithIndirectProxyAssociatedInterface listener; | 893 ListenerWithIndirectProxyAssociatedInterface listener; |
| 983 CreateProxy(&listener); | 894 CreateProxy(&listener); |
| 984 listener.RegisterInterfaceFactory(proxy()); | 895 listener.RegisterInterfaceFactory(proxy()); |
| 985 RunProxy(); | 896 RunProxy(); |
| 986 | 897 |
| 987 base::RunLoop loop; | 898 base::RunLoop loop; |
| 988 listener.set_ping_handler(loop.QuitClosure()); | 899 listener.set_ping_handler(loop.QuitClosure()); |
| 989 loop.Run(); | 900 loop.Run(); |
| 990 | 901 |
| 991 EXPECT_TRUE(WaitForClientShutdown()); | 902 EXPECT_TRUE(WaitForClientShutdown()); |
| 992 | 903 |
| 993 DestroyProxy(); | 904 DestroyProxy(); |
| 994 } | 905 } |
| 995 | 906 |
| 996 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT( | 907 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE( |
| 997 ProxyThreadAssociatedInterfaceIndirectClient, | 908 ProxyThreadAssociatedInterfaceIndirectClient, |
| 998 ChannelProxyClient) { | 909 ChannelProxyClient) { |
| 999 DummyListener listener; | 910 DummyListener listener; |
| 1000 CreateProxy(&listener); | 911 CreateProxy(&listener); |
| 1001 RunProxy(); | 912 RunProxy(); |
| 1002 | 913 |
| 1003 // Use an interface requested via another interface. On the remote end both | 914 // Use an interface requested via another interface. On the remote end both |
| 1004 // interfaces are bound on the proxy thread. This ensures that the Ping | 915 // interfaces are bound on the proxy thread. This ensures that the Ping |
| 1005 // message we send will still be dispatched properly even though the remote | 916 // message we send will still be dispatched properly even though the remote |
| 1006 // endpoint may not have been bound yet by the time the message is initially | 917 // endpoint may not have been bound yet by the time the message is initially |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 return false; | 1014 return false; |
| 1104 return true; | 1015 return true; |
| 1105 } | 1016 } |
| 1106 | 1017 |
| 1107 int32_t* storage_; | 1018 int32_t* storage_; |
| 1108 | 1019 |
| 1109 DISALLOW_COPY_AND_ASSIGN(SyncReplyReader); | 1020 DISALLOW_COPY_AND_ASSIGN(SyncReplyReader); |
| 1110 }; | 1021 }; |
| 1111 | 1022 |
| 1112 TEST_F(IPCChannelProxyMojoTest, SyncAssociatedInterface) { | 1023 TEST_F(IPCChannelProxyMojoTest, SyncAssociatedInterface) { |
| 1113 InitWithMojo("SyncAssociatedInterface"); | 1024 Init("SyncAssociatedInterface"); |
| 1114 | 1025 |
| 1115 ListenerWithSyncAssociatedInterface listener; | 1026 ListenerWithSyncAssociatedInterface listener; |
| 1116 CreateProxy(&listener); | 1027 CreateProxy(&listener); |
| 1117 listener.set_sync_sender(proxy()); | 1028 listener.set_sync_sender(proxy()); |
| 1118 listener.RegisterInterfaceFactory(proxy()); | 1029 listener.RegisterInterfaceFactory(proxy()); |
| 1119 RunProxy(); | 1030 RunProxy(); |
| 1120 | 1031 |
| 1121 // Run the client's simple sanity check to completion. | 1032 // Run the client's simple sanity check to completion. |
| 1122 listener.RunUntilQuitRequested(); | 1033 listener.RunUntilQuitRequested(); |
| 1123 | 1034 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 | 1120 |
| 1210 bool use_sync_sender_ = false; | 1121 bool use_sync_sender_ = false; |
| 1211 mojo::AssociatedBinding<IPC::mojom::SimpleTestClient> binding_; | 1122 mojo::AssociatedBinding<IPC::mojom::SimpleTestClient> binding_; |
| 1212 IPC::Sender* sync_sender_ = nullptr; | 1123 IPC::Sender* sync_sender_ = nullptr; |
| 1213 IPC::mojom::SimpleTestDriver* driver_ = nullptr; | 1124 IPC::mojom::SimpleTestDriver* driver_ = nullptr; |
| 1214 std::unique_ptr<base::RunLoop> run_loop_; | 1125 std::unique_ptr<base::RunLoop> run_loop_; |
| 1215 | 1126 |
| 1216 DISALLOW_COPY_AND_ASSIGN(SimpleTestClientImpl); | 1127 DISALLOW_COPY_AND_ASSIGN(SimpleTestClientImpl); |
| 1217 }; | 1128 }; |
| 1218 | 1129 |
| 1219 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(SyncAssociatedInterface, | 1130 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(SyncAssociatedInterface, |
| 1220 ChannelProxyClient) { | 1131 ChannelProxyClient) { |
| 1221 SimpleTestClientImpl client_impl; | 1132 SimpleTestClientImpl client_impl; |
| 1222 CreateProxy(&client_impl); | 1133 CreateProxy(&client_impl); |
| 1223 client_impl.set_sync_sender(proxy()); | 1134 client_impl.set_sync_sender(proxy()); |
| 1224 proxy()->AddAssociatedInterface(base::Bind(&SimpleTestClientImpl::BindRequest, | 1135 proxy()->AddAssociatedInterface(base::Bind(&SimpleTestClientImpl::BindRequest, |
| 1225 base::Unretained(&client_impl))); | 1136 base::Unretained(&client_impl))); |
| 1226 RunProxy(); | 1137 RunProxy(); |
| 1227 | 1138 |
| 1228 IPC::mojom::SimpleTestDriverAssociatedPtr driver; | 1139 IPC::mojom::SimpleTestDriverAssociatedPtr driver; |
| 1229 proxy()->GetRemoteAssociatedInterface(&driver); | 1140 proxy()->GetRemoteAssociatedInterface(&driver); |
| 1230 client_impl.set_driver(driver.get()); | 1141 client_impl.set_driver(driver.get()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 // Send(E) | 1180 // Send(E) |
| 1270 // Flush() | 1181 // Flush() |
| 1271 // | 1182 // |
| 1272 // must result in the other end receiving messages A, D, E, B, D; in that | 1183 // must result in the other end receiving messages A, D, E, B, D; in that |
| 1273 // order. | 1184 // order. |
| 1274 // | 1185 // |
| 1275 // This behavior is required by some consumers of IPC::Channel, and it is not | 1186 // This behavior is required by some consumers of IPC::Channel, and it is not |
| 1276 // sufficient to leave this up to the consumer to implement since associated | 1187 // sufficient to leave this up to the consumer to implement since associated |
| 1277 // interface requests and messages also need to be queued according to the | 1188 // interface requests and messages also need to be queued according to the |
| 1278 // same policy. | 1189 // same policy. |
| 1279 InitWithMojo("CreatePausedClient"); | 1190 Init("CreatePausedClient"); |
| 1280 | 1191 |
| 1281 DummyListener listener; | 1192 DummyListener listener; |
| 1282 CreateProxy(&listener); | 1193 CreateProxy(&listener); |
| 1283 RunProxy(); | 1194 RunProxy(); |
| 1284 | 1195 |
| 1285 // This message must be sent immediately since the channel is unpaused. | 1196 // This message must be sent immediately since the channel is unpaused. |
| 1286 SendValue(proxy(), 1); | 1197 SendValue(proxy(), 1); |
| 1287 | 1198 |
| 1288 proxy()->Pause(); | 1199 proxy()->Pause(); |
| 1289 | 1200 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 base::MessageLoop::current()->QuitWhenIdle(); | 1233 base::MessageLoop::current()->QuitWhenIdle(); |
| 1323 return true; | 1234 return true; |
| 1324 } | 1235 } |
| 1325 | 1236 |
| 1326 private: | 1237 private: |
| 1327 std::queue<int32_t>* expected_values_; | 1238 std::queue<int32_t>* expected_values_; |
| 1328 | 1239 |
| 1329 DISALLOW_COPY_AND_ASSIGN(ExpectValueSequenceListener); | 1240 DISALLOW_COPY_AND_ASSIGN(ExpectValueSequenceListener); |
| 1330 }; | 1241 }; |
| 1331 | 1242 |
| 1332 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(CreatePausedClient, ChannelProxyClient) { | 1243 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(CreatePausedClient, |
| 1244 ChannelProxyClient) { |
| 1333 std::queue<int32_t> expected_values; | 1245 std::queue<int32_t> expected_values; |
| 1334 ExpectValueSequenceListener listener(&expected_values); | 1246 ExpectValueSequenceListener listener(&expected_values); |
| 1335 CreateProxy(&listener); | 1247 CreateProxy(&listener); |
| 1336 expected_values.push(1); | 1248 expected_values.push(1); |
| 1337 expected_values.push(4); | 1249 expected_values.push(4); |
| 1338 expected_values.push(5); | 1250 expected_values.push(5); |
| 1339 expected_values.push(2); | 1251 expected_values.push(2); |
| 1340 expected_values.push(3); | 1252 expected_values.push(3); |
| 1341 RunProxy(); | 1253 RunProxy(); |
| 1342 base::RunLoop().Run(); | 1254 base::RunLoop().Run(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1363 base::MessageLoop::current()->QuitWhenIdle(); | 1275 base::MessageLoop::current()->QuitWhenIdle(); |
| 1364 } | 1276 } |
| 1365 | 1277 |
| 1366 void set_sender(IPC::Sender* sender) { sender_ = sender; } | 1278 void set_sender(IPC::Sender* sender) { sender_ = sender; } |
| 1367 | 1279 |
| 1368 private: | 1280 private: |
| 1369 IPC::Sender* sender_; | 1281 IPC::Sender* sender_; |
| 1370 }; | 1282 }; |
| 1371 | 1283 |
| 1372 TEST_F(IPCChannelMojoTest, SendPlatformHandle) { | 1284 TEST_F(IPCChannelMojoTest, SendPlatformHandle) { |
| 1373 InitWithMojo("IPCChannelMojoTestSendPlatformHandleClient"); | 1285 Init("IPCChannelMojoTestSendPlatformHandleClient"); |
| 1374 | 1286 |
| 1375 ListenerThatExpectsOK listener; | 1287 ListenerThatExpectsOK listener; |
| 1376 CreateChannel(&listener); | 1288 CreateChannel(&listener); |
| 1377 ASSERT_TRUE(ConnectChannel()); | 1289 ASSERT_TRUE(ConnectChannel()); |
| 1378 | 1290 |
| 1379 base::ScopedTempDir temp_dir; | 1291 base::ScopedTempDir temp_dir; |
| 1380 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1292 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1381 base::File file(HandleSendingHelper::GetSendingFilePath(temp_dir.GetPath()), | 1293 base::File file(HandleSendingHelper::GetSendingFilePath(temp_dir.GetPath()), |
| 1382 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | | 1294 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | |
| 1383 base::File::FLAG_READ); | 1295 base::File::FLAG_READ); |
| 1384 HandleSendingHelper::WriteFileThenSend(channel(), file); | 1296 HandleSendingHelper::WriteFileThenSend(channel(), file); |
| 1385 base::RunLoop().Run(); | 1297 base::RunLoop().Run(); |
| 1386 | 1298 |
| 1387 channel()->Close(); | 1299 channel()->Close(); |
| 1388 | 1300 |
| 1389 EXPECT_TRUE(WaitForClientShutdown()); | 1301 EXPECT_TRUE(WaitForClientShutdown()); |
| 1390 DestroyChannel(); | 1302 DestroyChannel(); |
| 1391 } | 1303 } |
| 1392 | 1304 |
| 1393 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendPlatformHandleClient, | 1305 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT( |
| 1394 ChannelClient) { | 1306 IPCChannelMojoTestSendPlatformHandleClient) { |
| 1395 ListenerThatExpectsFile listener; | 1307 ListenerThatExpectsFile listener; |
| 1396 Connect(&listener); | 1308 Connect(&listener); |
| 1397 listener.set_sender(channel()); | 1309 listener.set_sender(channel()); |
| 1398 | 1310 |
| 1399 base::RunLoop().Run(); | 1311 base::RunLoop().Run(); |
| 1400 | 1312 |
| 1401 Close(); | 1313 Close(); |
| 1402 } | 1314 } |
| 1403 | 1315 |
| 1404 class ListenerThatExpectsFileAndPipe : public IPC::Listener { | 1316 class ListenerThatExpectsFileAndPipe : public IPC::Listener { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1419 base::MessageLoop::current()->QuitWhenIdle(); | 1331 base::MessageLoop::current()->QuitWhenIdle(); |
| 1420 } | 1332 } |
| 1421 | 1333 |
| 1422 void set_sender(IPC::Sender* sender) { sender_ = sender; } | 1334 void set_sender(IPC::Sender* sender) { sender_ = sender; } |
| 1423 | 1335 |
| 1424 private: | 1336 private: |
| 1425 IPC::Sender* sender_; | 1337 IPC::Sender* sender_; |
| 1426 }; | 1338 }; |
| 1427 | 1339 |
| 1428 TEST_F(IPCChannelMojoTest, SendPlatformHandleAndPipe) { | 1340 TEST_F(IPCChannelMojoTest, SendPlatformHandleAndPipe) { |
| 1429 InitWithMojo("IPCChannelMojoTestSendPlatformHandleAndPipeClient"); | 1341 Init("IPCChannelMojoTestSendPlatformHandleAndPipeClient"); |
| 1430 | 1342 |
| 1431 ListenerThatExpectsOK listener; | 1343 ListenerThatExpectsOK listener; |
| 1432 CreateChannel(&listener); | 1344 CreateChannel(&listener); |
| 1433 ASSERT_TRUE(ConnectChannel()); | 1345 ASSERT_TRUE(ConnectChannel()); |
| 1434 | 1346 |
| 1435 base::ScopedTempDir temp_dir; | 1347 base::ScopedTempDir temp_dir; |
| 1436 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1348 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1437 base::File file(HandleSendingHelper::GetSendingFilePath(temp_dir.GetPath()), | 1349 base::File file(HandleSendingHelper::GetSendingFilePath(temp_dir.GetPath()), |
| 1438 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | | 1350 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | |
| 1439 base::File::FLAG_READ); | 1351 base::File::FLAG_READ); |
| 1440 TestingMessagePipe pipe; | 1352 TestingMessagePipe pipe; |
| 1441 HandleSendingHelper::WriteFileAndPipeThenSend(channel(), file, &pipe); | 1353 HandleSendingHelper::WriteFileAndPipeThenSend(channel(), file, &pipe); |
| 1442 | 1354 |
| 1443 base::RunLoop().Run(); | 1355 base::RunLoop().Run(); |
| 1444 channel()->Close(); | 1356 channel()->Close(); |
| 1445 | 1357 |
| 1446 EXPECT_TRUE(WaitForClientShutdown()); | 1358 EXPECT_TRUE(WaitForClientShutdown()); |
| 1447 DestroyChannel(); | 1359 DestroyChannel(); |
| 1448 } | 1360 } |
| 1449 | 1361 |
| 1450 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT( | 1362 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT( |
| 1451 IPCChannelMojoTestSendPlatformHandleAndPipeClient, | 1363 IPCChannelMojoTestSendPlatformHandleAndPipeClient) { |
| 1452 ChannelClient) { | |
| 1453 ListenerThatExpectsFileAndPipe listener; | 1364 ListenerThatExpectsFileAndPipe listener; |
| 1454 Connect(&listener); | 1365 Connect(&listener); |
| 1455 listener.set_sender(channel()); | 1366 listener.set_sender(channel()); |
| 1456 | 1367 |
| 1457 base::RunLoop().Run(); | 1368 base::RunLoop().Run(); |
| 1458 | 1369 |
| 1459 Close(); | 1370 Close(); |
| 1460 } | 1371 } |
| 1461 | 1372 |
| 1462 #endif // defined(OS_POSIX) | 1373 #endif // defined(OS_POSIX) |
| 1463 | 1374 |
| 1464 #if defined(OS_LINUX) | 1375 #if defined(OS_LINUX) |
| 1465 | 1376 |
| 1466 const base::ProcessId kMagicChildId = 54321; | 1377 const base::ProcessId kMagicChildId = 54321; |
| 1467 | 1378 |
| 1468 class ListenerThatVerifiesPeerPid : public IPC::Listener { | 1379 class ListenerThatVerifiesPeerPid : public IPC::Listener { |
| 1469 public: | 1380 public: |
| 1470 void OnChannelConnected(int32_t peer_pid) override { | 1381 void OnChannelConnected(int32_t peer_pid) override { |
| 1471 EXPECT_EQ(peer_pid, kMagicChildId); | 1382 EXPECT_EQ(peer_pid, kMagicChildId); |
| 1472 base::MessageLoop::current()->QuitWhenIdle(); | 1383 base::MessageLoop::current()->QuitWhenIdle(); |
| 1473 } | 1384 } |
| 1474 | 1385 |
| 1475 bool OnMessageReceived(const IPC::Message& message) override { | 1386 bool OnMessageReceived(const IPC::Message& message) override { |
| 1476 NOTREACHED(); | 1387 NOTREACHED(); |
| 1477 return true; | 1388 return true; |
| 1478 } | 1389 } |
| 1479 }; | 1390 }; |
| 1480 | 1391 |
| 1481 TEST_F(IPCChannelMojoTest, VerifyGlobalPid) { | 1392 TEST_F(IPCChannelMojoTest, VerifyGlobalPid) { |
| 1482 InitWithMojo("IPCChannelMojoTestVerifyGlobalPidClient"); | 1393 Init("IPCChannelMojoTestVerifyGlobalPidClient"); |
| 1483 | 1394 |
| 1484 ListenerThatVerifiesPeerPid listener; | 1395 ListenerThatVerifiesPeerPid listener; |
| 1485 CreateChannel(&listener); | 1396 CreateChannel(&listener); |
| 1486 ASSERT_TRUE(ConnectChannel()); | 1397 ASSERT_TRUE(ConnectChannel()); |
| 1487 | 1398 |
| 1488 base::RunLoop().Run(); | 1399 base::RunLoop().Run(); |
| 1489 channel()->Close(); | 1400 channel()->Close(); |
| 1490 | 1401 |
| 1491 EXPECT_TRUE(WaitForClientShutdown()); | 1402 EXPECT_TRUE(WaitForClientShutdown()); |
| 1492 DestroyChannel(); | 1403 DestroyChannel(); |
| 1493 } | 1404 } |
| 1494 | 1405 |
| 1495 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestVerifyGlobalPidClient, | 1406 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestVerifyGlobalPidClient) { |
| 1496 ChannelClient) { | |
| 1497 IPC::Channel::SetGlobalPid(kMagicChildId); | 1407 IPC::Channel::SetGlobalPid(kMagicChildId); |
| 1498 ListenerThatQuits listener; | 1408 ListenerThatQuits listener; |
| 1499 Connect(&listener); | 1409 Connect(&listener); |
| 1500 | 1410 |
| 1501 base::RunLoop().Run(); | 1411 base::RunLoop().Run(); |
| 1502 | 1412 |
| 1503 Close(); | 1413 Close(); |
| 1504 } | 1414 } |
| 1505 | 1415 |
| 1506 #endif // OS_LINUX | 1416 #endif // OS_LINUX |
| 1507 | 1417 |
| 1508 } // namespace | 1418 } // namespace |
| OLD | NEW |