| 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 "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 void set_broker(IPC::AttachmentBrokerUnprivilegedWin* broker) { | 154 void set_broker(IPC::AttachmentBrokerUnprivilegedWin* broker) { |
| 155 broker_.reset(broker); | 155 broker_.reset(broker); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void CommonSetUp() { | 158 void CommonSetUp() { |
| 159 if (!broker_.get()) | 159 if (!broker_.get()) |
| 160 set_broker(new IPC::AttachmentBrokerUnprivilegedWin); | 160 set_broker(new IPC::AttachmentBrokerUnprivilegedWin); |
| 161 broker_->AddObserver(&observer_); | 161 broker_->AddObserver(&observer_); |
| 162 set_attachment_broker(broker_.get()); | 162 set_attachment_broker(broker_.get()); |
| 163 CreateChannel(&proxy_listener_); | 163 CreateChannel(&proxy_listener_); |
| 164 broker_->set_sender(channel()); | 164 broker_->DesignateBrokerCommunicationChannel(channel()); |
| 165 ASSERT_TRUE(ConnectChannel()); | 165 ASSERT_TRUE(ConnectChannel()); |
| 166 ASSERT_TRUE(StartClient()); | 166 ASSERT_TRUE(StartClient()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void CommonTearDown() { | 169 void CommonTearDown() { |
| 170 // Close the channel so the client's OnChannelError() gets fired. | 170 // Close the channel so the client's OnChannelError() gets fired. |
| 171 channel()->Close(); | 171 channel()->Close(); |
| 172 | 172 |
| 173 EXPECT_TRUE(WaitForClientShutdown()); | 173 EXPECT_TRUE(WaitForClientShutdown()); |
| 174 DestroyChannel(); | 174 DestroyChannel(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 271 } |
| 272 | 272 |
| 273 // Similar to SendHandle, except the attachment's destination process is this | 273 // Similar to SendHandle, except the attachment's destination process is this |
| 274 // process. This is an unrealistic scenario, but simulates an unprivileged | 274 // process. This is an unrealistic scenario, but simulates an unprivileged |
| 275 // process sending an attachment to another unprivileged process. | 275 // process sending an attachment to another unprivileged process. |
| 276 TEST_F(IPCAttachmentBrokerPrivilegedWinTest, SendHandleToSelf) { | 276 TEST_F(IPCAttachmentBrokerPrivilegedWinTest, SendHandleToSelf) { |
| 277 Init("SendHandleToSelf"); | 277 Init("SendHandleToSelf"); |
| 278 | 278 |
| 279 set_broker(new MockBroker); | 279 set_broker(new MockBroker); |
| 280 CommonSetUp(); | 280 CommonSetUp(); |
| 281 // Technically, the channel is an endpoint, but we need the proxy listener to |
| 282 // receive the messages so that it can quit the message loop. |
| 283 channel()->set_attachment_broker_endpoint(false); |
| 281 get_proxy_listener()->set_listener(get_broker()); | 284 get_proxy_listener()->set_listener(get_broker()); |
| 282 | 285 |
| 283 HANDLE h = CreateTempFile(); | 286 HANDLE h = CreateTempFile(); |
| 284 SendMessageWithAttachment(h); | 287 SendMessageWithAttachment(h); |
| 285 base::MessageLoop::current()->Run(); | 288 base::MessageLoop::current()->Run(); |
| 286 | 289 |
| 287 // Get the received attachment. | 290 // Get the received attachment. |
| 288 IPC::BrokerableAttachment::AttachmentId* id = get_observer()->get_id(); | 291 IPC::BrokerableAttachment::AttachmentId* id = get_observer()->get_id(); |
| 289 scoped_refptr<IPC::BrokerableAttachment> received_attachment; | 292 scoped_refptr<IPC::BrokerableAttachment> received_attachment; |
| 290 get_broker()->GetAttachmentWithId(*id, &received_attachment); | 293 get_broker()->GetAttachmentWithId(*id, &received_attachment); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // Do nothing special. The default behavior already runs the | 393 // Do nothing special. The default behavior already runs the |
| 391 // AttachmentBrokerPrivilegedWin. | 394 // AttachmentBrokerPrivilegedWin. |
| 392 } | 395 } |
| 393 | 396 |
| 394 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendHandleToSelf) { | 397 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendHandleToSelf) { |
| 395 return CommonPrivilegedProcessMain(&SendHandleToSelfCallback, | 398 return CommonPrivilegedProcessMain(&SendHandleToSelfCallback, |
| 396 "SendHandleToSelf"); | 399 "SendHandleToSelf"); |
| 397 } | 400 } |
| 398 | 401 |
| 399 } // namespace | 402 } // namespace |
| OLD | NEW |