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

Side by Side Diff: ipc/ipc_message_unittest.cc

Issue 283623002: Add support for passing an arbitrary parameter to an IPC message handler. The motivation is for Web… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ppapi/proxy/resource_message_test_sink.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ipc/ipc_message.h" 5 #include "ipc/ipc_message.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "ipc/ipc_message_utils.h" 11 #include "ipc/ipc_message_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 // IPC messages for testing ----------------------------------------------------
15
16 #define IPC_MESSAGE_IMPL
17 #include "ipc/ipc_message_macros.h"
18
19 #define IPC_MESSAGE_START TestMsgStart
20
21 IPC_MESSAGE_CONTROL0(TestMsgClassEmpty)
22
23 IPC_MESSAGE_CONTROL1(TestMsgClassI, int)
24
25 IPC_SYNC_MESSAGE_CONTROL1_1(TestMsgClassIS, int, std::string)
26
14 namespace { 27 namespace {
15 28
16 TEST(IPCMessageTest, ListValue) { 29 TEST(IPCMessageTest, ListValue) {
17 base::ListValue input; 30 base::ListValue input;
18 input.Set(0, new base::FundamentalValue(42.42)); 31 input.Set(0, new base::FundamentalValue(42.42));
19 input.Set(1, new base::StringValue("forty")); 32 input.Set(1, new base::StringValue("forty"));
20 input.Set(2, base::Value::CreateNullValue()); 33 input.Set(2, base::Value::CreateNullValue());
21 34
22 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 35 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
23 IPC::WriteParam(&msg, input); 36 IPC::WriteParam(&msg, input);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 76
64 EXPECT_TRUE(input.Equals(&output)); 77 EXPECT_TRUE(input.Equals(&output));
65 78
66 // Also test the corrupt case. 79 // Also test the corrupt case.
67 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); 80 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
68 bad_msg.WriteInt(99); 81 bad_msg.WriteInt(99);
69 iter = PickleIterator(bad_msg); 82 iter = PickleIterator(bad_msg);
70 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); 83 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
71 } 84 }
72 85
86 class IPCMessageParameterTest : public testing::Test {
87 public:
88 IPCMessageParameterTest() : extra_param_("extra_param"), called_(false) {}
89
90 bool OnMessageReceived(const IPC::Message& message) {
91 bool msg_is_ok = true;
92 bool handled = true;
93 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(IPCMessageParameterTest, message,
94 msg_is_ok, std::string, &extra_param_)
95 IPC_MESSAGE_HANDLER(TestMsgClassEmpty, OnEmpty)
96 IPC_MESSAGE_HANDLER(TestMsgClassI, OnInt)
97 //IPC_MESSAGE_HANDLER(TestMsgClassIS, OnSync)
98 IPC_MESSAGE_UNHANDLED(handled = false)
99 IPC_END_MESSAGE_MAP()
100
101 return handled;
102 }
103
104 void OnEmpty(std::string* extra_param) {
105 EXPECT_EQ(extra_param, &extra_param_);
106 called_ = true;
107 }
108
109 void OnInt(std::string* extra_param, int foo) {
110 EXPECT_EQ(extra_param, &extra_param_);
111 EXPECT_EQ(foo, 42);
112 called_ = true;
113 }
114
115 /* TODO: handle sync IPCs
116 void OnSync(std::string* extra_param, int foo, std::string* out) {
117 EXPECT_EQ(extra_param, &extra_param_);
118 EXPECT_EQ(foo, 42);
119 called_ = true;
120 *out = std::string("out");
121 }
122
123 bool Send(IPC::Message* reply) {
124 delete reply;
125 return true;
126 }*/
127
128 std::string extra_param_;
129 bool called_;
130 };
131
132 TEST_F(IPCMessageParameterTest, EmptyDispatcherWithParam) {
133 TestMsgClassEmpty message;
134 EXPECT_TRUE(OnMessageReceived(message));
135 EXPECT_TRUE(called_);
136 }
137
138 TEST_F(IPCMessageParameterTest, OneIntegerWithParam) {
139 TestMsgClassI message(42);
140 EXPECT_TRUE(OnMessageReceived(message));
141 EXPECT_TRUE(called_);
142 }
143
144 /* TODO: handle sync IPCs
145 TEST_F(IPCMessageParameterTest, Sync) {
146 std::string output;
147 TestMsgClassIS message(42, &output);
148 EXPECT_TRUE(OnMessageReceived(message));
149 EXPECT_TRUE(called_);
150 EXPECT_EQ(output, std::string("out"));
151 }*/
152
73 } // namespace 153 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ppapi/proxy/resource_message_test_sink.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698