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

Unified Diff: ipc/attachment_broker_win_unittest.cc

Issue 1205713002: Make attachment broker a subclass of IPC::Listener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@attachment_broker3_listener_base
Patch Set: Update copyright date. Created 5 years, 5 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/attachment_broker_win.cc ('k') | ipc/brokerable_attachment.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/attachment_broker_win_unittest.cc
diff --git a/ipc/attachment_broker_win_unittest.cc b/ipc/attachment_broker_win_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1e7db65f2e403176b54e2e658bf766a76c67ff31
--- /dev/null
+++ b/ipc/attachment_broker_win_unittest.cc
@@ -0,0 +1,51 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "build/build_config.h"
+
+#include <windows.h>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/process/process.h"
+#include "ipc/attachment_broker_messages.h"
+#include "ipc/attachment_broker_win.h"
+#include "ipc/handle_attachment_win.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace IPC {
+
+TEST(AttachmentBrokerWinTest, ReceiveValidMessage) {
+ HANDLE handle = LongToHandle(8);
+ base::ProcessId destination = base::Process::Current().Pid();
+ scoped_refptr<internal::HandleAttachmentWin> attachment(
+ new internal::HandleAttachmentWin(handle));
+ AttachmentBrokerMsg_WinHandleHasBeenDuplicated msg(
+ attachment->GetWireFormat(destination));
+ AttachmentBrokerWin attachment_broker;
+ EXPECT_TRUE(attachment_broker.OnMessageReceived(msg));
+ EXPECT_EQ(1u, attachment_broker.attachments_.size());
+
+ scoped_refptr<BrokerableAttachment> received_attachment =
+ attachment_broker.attachments_.front();
+ EXPECT_EQ(BrokerableAttachment::WIN_HANDLE,
+ received_attachment->GetBrokerableType());
+ internal::HandleAttachmentWin* received_handle_attachment =
+ static_cast<internal::HandleAttachmentWin*>(received_attachment.get());
+ EXPECT_EQ(handle, received_handle_attachment->get_handle());
+}
+
+TEST(AttachmentBrokerWinTest, ReceiveInvalidMessage) {
+ HANDLE handle = LongToHandle(8);
+ base::ProcessId destination = base::Process::Current().Pid() + 1;
+ scoped_refptr<internal::HandleAttachmentWin> attachment(
+ new internal::HandleAttachmentWin(handle));
+ AttachmentBrokerMsg_WinHandleHasBeenDuplicated msg(
+ attachment->GetWireFormat(destination));
+ AttachmentBrokerWin attachment_broker;
+ EXPECT_TRUE(attachment_broker.OnMessageReceived(msg));
+ EXPECT_EQ(0u, attachment_broker.attachments_.size());
+}
+
+} // namespace IPC
« no previous file with comments | « ipc/attachment_broker_win.cc ('k') | ipc/brokerable_attachment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698