| 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" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "ipc/attachment_broker_privileged_win.h" | 13 #include "ipc/attachment_broker_privileged_win.h" |
| 14 #include "ipc/attachment_broker_win.h" | 14 #include "ipc/attachment_broker_unprivileged_win.h" |
| 15 #include "ipc/handle_attachment_win.h" | 15 #include "ipc/handle_attachment_win.h" |
| 16 #include "ipc/ipc_listener.h" | 16 #include "ipc/ipc_listener.h" |
| 17 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
| 18 #include "ipc/ipc_test_base.h" | 18 #include "ipc/ipc_test_base.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const char kDataBuffer[] = "This is some test data to write to the file."; | 22 const char kDataBuffer[] = "This is some test data to write to the file."; |
| 23 | 23 |
| 24 // Returns the contents of the file represented by |h| as a std::string. | 24 // Returns the contents of the file represented by |h| as a std::string. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 void SetUp() override { | 145 void SetUp() override { |
| 146 IPCTestBase::SetUp(); | 146 IPCTestBase::SetUp(); |
| 147 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 147 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 148 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &temp_path_)); | 148 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &temp_path_)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void TearDown() override { IPCTestBase::TearDown(); } | 151 void TearDown() override { IPCTestBase::TearDown(); } |
| 152 | 152 |
| 153 // Takes ownership of |broker|. Has no effect if called after CommonSetUp(). | 153 // Takes ownership of |broker|. Has no effect if called after CommonSetUp(). |
| 154 void set_broker(IPC::AttachmentBrokerWin* broker) { broker_.reset(broker); } | 154 void set_broker(IPC::AttachmentBrokerUnprivilegedWin* broker) { |
| 155 broker_.reset(broker); |
| 156 } |
| 155 | 157 |
| 156 void CommonSetUp() { | 158 void CommonSetUp() { |
| 157 if (!broker_.get()) | 159 if (!broker_.get()) |
| 158 set_broker(new IPC::AttachmentBrokerWin); | 160 set_broker(new IPC::AttachmentBrokerUnprivilegedWin); |
| 159 broker_->AddObserver(&observer_); | 161 broker_->AddObserver(&observer_); |
| 160 set_attachment_broker(broker_.get()); | 162 set_attachment_broker(broker_.get()); |
| 161 CreateChannel(&proxy_listener_); | 163 CreateChannel(&proxy_listener_); |
| 162 broker_->set_sender(channel()); | 164 broker_->set_sender(channel()); |
| 163 ASSERT_TRUE(ConnectChannel()); | 165 ASSERT_TRUE(ConnectChannel()); |
| 164 ASSERT_TRUE(StartClient()); | 166 ASSERT_TRUE(StartClient()); |
| 165 } | 167 } |
| 166 | 168 |
| 167 void CommonTearDown() { | 169 void CommonTearDown() { |
| 168 // Close the channel so the client's OnChannelError() gets fired. | 170 // Close the channel so the client's OnChannelError() gets fired. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 188 IPC::Message* message = | 190 IPC::Message* message = |
| 189 new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL); | 191 new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL); |
| 190 message->WriteInt(message_index_++); | 192 message->WriteInt(message_index_++); |
| 191 scoped_refptr<IPC::internal::HandleAttachmentWin> attachment( | 193 scoped_refptr<IPC::internal::HandleAttachmentWin> attachment( |
| 192 new IPC::internal::HandleAttachmentWin(h)); | 194 new IPC::internal::HandleAttachmentWin(h)); |
| 193 ASSERT_TRUE(message->WriteAttachment(attachment)); | 195 ASSERT_TRUE(message->WriteAttachment(attachment)); |
| 194 sender()->Send(message); | 196 sender()->Send(message); |
| 195 } | 197 } |
| 196 | 198 |
| 197 ProxyListener* get_proxy_listener() { return &proxy_listener_; } | 199 ProxyListener* get_proxy_listener() { return &proxy_listener_; } |
| 198 IPC::AttachmentBrokerWin* get_broker() { return broker_.get(); } | 200 IPC::AttachmentBrokerUnprivilegedWin* get_broker() { return broker_.get(); } |
| 199 MockObserver* get_observer() { return &observer_; } | 201 MockObserver* get_observer() { return &observer_; } |
| 200 | 202 |
| 201 private: | 203 private: |
| 202 base::ScopedTempDir temp_dir_; | 204 base::ScopedTempDir temp_dir_; |
| 203 base::FilePath temp_path_; | 205 base::FilePath temp_path_; |
| 204 int message_index_; | 206 int message_index_; |
| 205 ProxyListener proxy_listener_; | 207 ProxyListener proxy_listener_; |
| 206 scoped_ptr<IPC::AttachmentBrokerWin> broker_; | 208 scoped_ptr<IPC::AttachmentBrokerUnprivilegedWin> broker_; |
| 207 MockObserver observer_; | 209 MockObserver observer_; |
| 208 }; | 210 }; |
| 209 | 211 |
| 210 // A broker which always sets the current process as the destination process | 212 // A broker which always sets the current process as the destination process |
| 211 // for attachments. | 213 // for attachments. |
| 212 class MockBroker : public IPC::AttachmentBrokerWin { | 214 class MockBroker : public IPC::AttachmentBrokerUnprivilegedWin { |
| 213 public: | 215 public: |
| 214 MockBroker() {} | 216 MockBroker() {} |
| 215 ~MockBroker() override {} | 217 ~MockBroker() override {} |
| 216 bool SendAttachmentToProcess(const IPC::BrokerableAttachment* attachment, | 218 bool SendAttachmentToProcess(const IPC::BrokerableAttachment* attachment, |
| 217 base::ProcessId destination_process) override { | 219 base::ProcessId destination_process) override { |
| 218 return IPC::AttachmentBrokerWin::SendAttachmentToProcess( | 220 return IPC::AttachmentBrokerUnprivilegedWin::SendAttachmentToProcess( |
| 219 attachment, base::Process::Current().Pid()); | 221 attachment, base::Process::Current().Pid()); |
| 220 } | 222 } |
| 221 }; | 223 }; |
| 222 | 224 |
| 223 // An unprivileged process makes a file HANDLE, and writes a string to it. The | 225 // An unprivileged process makes a file HANDLE, and writes a string to it. The |
| 224 // file HANDLE is sent to the privileged process using the attachment broker. | 226 // file HANDLE is sent to the privileged process using the attachment broker. |
| 225 // The privileged process dups the HANDLE into its own HANDLE table. This test | 227 // The privileged process dups the HANDLE into its own HANDLE table. This test |
| 226 // checks that the file has the same contents in the privileged process. | 228 // checks that the file has the same contents in the privileged process. |
| 227 TEST_F(IPCAttachmentBrokerPrivilegedWinTest, SendHandle) { | 229 TEST_F(IPCAttachmentBrokerPrivilegedWinTest, SendHandle) { |
| 228 Init("SendHandle"); | 230 Init("SendHandle"); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // Do nothing special. The default behavior already runs the | 390 // Do nothing special. The default behavior already runs the |
| 389 // AttachmentBrokerPrivilegedWin. | 391 // AttachmentBrokerPrivilegedWin. |
| 390 } | 392 } |
| 391 | 393 |
| 392 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendHandleToSelf) { | 394 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendHandleToSelf) { |
| 393 return CommonPrivilegedProcessMain(&SendHandleToSelfCallback, | 395 return CommonPrivilegedProcessMain(&SendHandleToSelfCallback, |
| 394 "SendHandleToSelf"); | 396 "SendHandleToSelf"); |
| 395 } | 397 } |
| 396 | 398 |
| 397 } // namespace | 399 } // namespace |
| OLD | NEW |