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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/process/process.h" | 11 #include "base/process/process.h" |
12 #include "ipc/attachment_broker_messages.h" | 12 #include "ipc/attachment_broker_messages.h" |
13 #include "ipc/attachment_broker_win.h" | 13 #include "ipc/attachment_broker_unprivileged_win.h" |
14 #include "ipc/handle_attachment_win.h" | 14 #include "ipc/handle_attachment_win.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace IPC { | 17 namespace IPC { |
18 | 18 |
19 TEST(AttachmentBrokerWinTest, ReceiveValidMessage) { | 19 TEST(AttachmentBrokerUnprivilegedWinTest, ReceiveValidMessage) { |
20 HANDLE handle = LongToHandle(8); | 20 HANDLE handle = LongToHandle(8); |
21 base::ProcessId destination = base::Process::Current().Pid(); | 21 base::ProcessId destination = base::Process::Current().Pid(); |
22 scoped_refptr<internal::HandleAttachmentWin> attachment( | 22 scoped_refptr<internal::HandleAttachmentWin> attachment( |
23 new internal::HandleAttachmentWin(handle)); | 23 new internal::HandleAttachmentWin(handle)); |
24 AttachmentBrokerMsg_WinHandleHasBeenDuplicated msg( | 24 AttachmentBrokerMsg_WinHandleHasBeenDuplicated msg( |
25 attachment->GetWireFormat(destination)); | 25 attachment->GetWireFormat(destination)); |
26 AttachmentBrokerWin attachment_broker; | 26 AttachmentBrokerUnprivilegedWin attachment_broker; |
27 EXPECT_TRUE(attachment_broker.OnMessageReceived(msg)); | 27 EXPECT_TRUE(attachment_broker.OnMessageReceived(msg)); |
28 EXPECT_EQ(1u, attachment_broker.attachments_.size()); | 28 EXPECT_EQ(1u, attachment_broker.attachments_.size()); |
29 | 29 |
30 scoped_refptr<BrokerableAttachment> received_attachment = | 30 scoped_refptr<BrokerableAttachment> received_attachment = |
31 attachment_broker.attachments_.front(); | 31 attachment_broker.attachments_.front(); |
32 EXPECT_EQ(BrokerableAttachment::WIN_HANDLE, | 32 EXPECT_EQ(BrokerableAttachment::WIN_HANDLE, |
33 received_attachment->GetBrokerableType()); | 33 received_attachment->GetBrokerableType()); |
34 internal::HandleAttachmentWin* received_handle_attachment = | 34 internal::HandleAttachmentWin* received_handle_attachment = |
35 static_cast<internal::HandleAttachmentWin*>(received_attachment.get()); | 35 static_cast<internal::HandleAttachmentWin*>(received_attachment.get()); |
36 EXPECT_EQ(handle, received_handle_attachment->get_handle()); | 36 EXPECT_EQ(handle, received_handle_attachment->get_handle()); |
37 } | 37 } |
38 | 38 |
39 TEST(AttachmentBrokerWinTest, ReceiveInvalidMessage) { | 39 TEST(AttachmentBrokerUnprivilegedWinTest, ReceiveInvalidMessage) { |
40 HANDLE handle = LongToHandle(8); | 40 HANDLE handle = LongToHandle(8); |
41 base::ProcessId destination = base::Process::Current().Pid() + 1; | 41 base::ProcessId destination = base::Process::Current().Pid() + 1; |
42 scoped_refptr<internal::HandleAttachmentWin> attachment( | 42 scoped_refptr<internal::HandleAttachmentWin> attachment( |
43 new internal::HandleAttachmentWin(handle)); | 43 new internal::HandleAttachmentWin(handle)); |
44 AttachmentBrokerMsg_WinHandleHasBeenDuplicated msg( | 44 AttachmentBrokerMsg_WinHandleHasBeenDuplicated msg( |
45 attachment->GetWireFormat(destination)); | 45 attachment->GetWireFormat(destination)); |
46 AttachmentBrokerWin attachment_broker; | 46 AttachmentBrokerUnprivilegedWin attachment_broker; |
47 EXPECT_TRUE(attachment_broker.OnMessageReceived(msg)); | 47 EXPECT_TRUE(attachment_broker.OnMessageReceived(msg)); |
48 EXPECT_EQ(0u, attachment_broker.attachments_.size()); | 48 EXPECT_EQ(0u, attachment_broker.attachments_.size()); |
49 } | 49 } |
50 | 50 |
51 } // namespace IPC | 51 } // namespace IPC |
OLD | NEW |