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

Side by Side Diff: ipc/ipc_channel_mojo_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698