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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 258 } |
259 | 259 |
260 void TearDown() override { IPCTestBase::TearDown(); } | 260 void TearDown() override { IPCTestBase::TearDown(); } |
261 | 261 |
262 // Takes ownership of |broker|. Has no effect if called after CommonSetUp(). | 262 // Takes ownership of |broker|. Has no effect if called after CommonSetUp(). |
263 void set_broker(IPC::AttachmentBrokerUnprivilegedWin* broker) { | 263 void set_broker(IPC::AttachmentBrokerUnprivilegedWin* broker) { |
264 broker_.reset(broker); | 264 broker_.reset(broker); |
265 } | 265 } |
266 | 266 |
267 void CommonSetUp() { | 267 void CommonSetUp() { |
| 268 PreConnectSetUp(); |
| 269 PostConnectSetUp(); |
| 270 } |
| 271 |
| 272 // All of setup before the channel is connected. |
| 273 void PreConnectSetUp() { |
268 if (!broker_.get()) | 274 if (!broker_.get()) |
269 set_broker(new IPC::AttachmentBrokerUnprivilegedWin); | 275 set_broker(new IPC::AttachmentBrokerUnprivilegedWin); |
270 broker_->AddObserver(&observer_, task_runner()); | 276 broker_->AddObserver(&observer_, task_runner()); |
271 CreateChannel(&proxy_listener_); | 277 CreateChannel(&proxy_listener_); |
272 broker_->RegisterBrokerCommunicationChannel(channel()); | 278 broker_->RegisterBrokerCommunicationChannel(channel()); |
| 279 } |
| 280 |
| 281 // All of setup including the connection and everything after. |
| 282 void PostConnectSetUp() { |
273 ASSERT_TRUE(ConnectChannel()); | 283 ASSERT_TRUE(ConnectChannel()); |
274 ASSERT_TRUE(StartClient()); | 284 ASSERT_TRUE(StartClient()); |
275 | 285 |
276 handle_count_ = GetCurrentProcessHandleCount(); | 286 handle_count_ = GetCurrentProcessHandleCount(); |
277 EXPECT_NE(handle_count_, 0u); | 287 EXPECT_NE(handle_count_, 0u); |
278 } | 288 } |
279 | 289 |
280 void CommonTearDown() { | 290 void CommonTearDown() { |
281 EXPECT_EQ(handle_count_, handle_count_); | 291 EXPECT_EQ(handle_count_, handle_count_); |
282 | 292 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 CommonTearDown(); | 393 CommonTearDown(); |
384 } | 394 } |
385 | 395 |
386 // Similar to SendHandle, except the attachment's destination process is this | 396 // Similar to SendHandle, except the attachment's destination process is this |
387 // process. This is an unrealistic scenario, but simulates an unprivileged | 397 // process. This is an unrealistic scenario, but simulates an unprivileged |
388 // process sending an attachment to another unprivileged process. | 398 // process sending an attachment to another unprivileged process. |
389 TEST_F(IPCAttachmentBrokerPrivilegedWinTest, SendHandleToSelf) { | 399 TEST_F(IPCAttachmentBrokerPrivilegedWinTest, SendHandleToSelf) { |
390 Init("SendHandleToSelf"); | 400 Init("SendHandleToSelf"); |
391 | 401 |
392 set_broker(new MockBroker); | 402 set_broker(new MockBroker); |
393 CommonSetUp(); | 403 |
| 404 PreConnectSetUp(); |
394 // Technically, the channel is an endpoint, but we need the proxy listener to | 405 // Technically, the channel is an endpoint, but we need the proxy listener to |
395 // receive the messages so that it can quit the message loop. | 406 // receive the messages so that it can quit the message loop. |
396 channel()->SetAttachmentBrokerEndpoint(false); | 407 channel()->SetAttachmentBrokerEndpoint(false); |
| 408 PostConnectSetUp(); |
397 get_proxy_listener()->set_listener(get_broker()); | 409 get_proxy_listener()->set_listener(get_broker()); |
398 | 410 |
399 HANDLE h = CreateTempFile(); | 411 HANDLE h = CreateTempFile(); |
400 SendMessageWithAttachment(h); | 412 SendMessageWithAttachment(h); |
401 base::MessageLoop::current()->Run(); | 413 base::MessageLoop::current()->Run(); |
402 | 414 |
403 // Get the received attachment. | 415 // Get the received attachment. |
404 IPC::BrokerableAttachment::AttachmentId* id = get_observer()->get_id(); | 416 IPC::BrokerableAttachment::AttachmentId* id = get_observer()->get_id(); |
405 scoped_refptr<IPC::BrokerableAttachment> received_attachment; | 417 scoped_refptr<IPC::BrokerableAttachment> received_attachment; |
406 get_broker()->GetAttachmentWithId(*id, &received_attachment); | 418 get_broker()->GetAttachmentWithId(*id, &received_attachment); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 memcmp(shared_memory->memory(), kDataBuffer, strlen(kDataBuffer)) == 0; | 657 memcmp(shared_memory->memory(), kDataBuffer, strlen(kDataBuffer)) == 0; |
646 SendControlMessage(sender, success); | 658 SendControlMessage(sender, success); |
647 } | 659 } |
648 | 660 |
649 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) { | 661 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) { |
650 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback, | 662 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback, |
651 "SendSharedMemoryHandle"); | 663 "SendSharedMemoryHandle"); |
652 } | 664 } |
653 | 665 |
654 } // namespace | 666 } // namespace |
OLD | NEW |