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

Side by Side Diff: ipc/ipc_channel_proxy_unittest.cc

Issue 645623006: Standardize usage of virtual/override/final in ipc/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "ipc/ipc_message.h" 10 #include "ipc/ipc_message.h"
(...skipping 29 matching lines...) Expand all
40 namespace IPC { 40 namespace IPC {
41 #include "ipc/ipc_channel_proxy_unittest_messages.h" 41 #include "ipc/ipc_channel_proxy_unittest_messages.h"
42 } // namespace IPC 42 } // namespace IPC
43 43
44 44
45 namespace { 45 namespace {
46 46
47 class QuitListener : public IPC::Listener { 47 class QuitListener : public IPC::Listener {
48 public: 48 public:
49 QuitListener() : bad_message_received_(false) {} 49 QuitListener() : bad_message_received_(false) {}
50 virtual ~QuitListener() {} 50 ~QuitListener() override {}
51 51
52 virtual bool OnMessageReceived(const IPC::Message& message) override { 52 bool OnMessageReceived(const IPC::Message& message) override {
53 IPC_BEGIN_MESSAGE_MAP(QuitListener, message) 53 IPC_BEGIN_MESSAGE_MAP(QuitListener, message)
54 IPC_MESSAGE_HANDLER(WorkerMsg_Quit, OnQuit) 54 IPC_MESSAGE_HANDLER(WorkerMsg_Quit, OnQuit)
55 IPC_MESSAGE_HANDLER(TestMsg_BadMessage, OnBadMessage) 55 IPC_MESSAGE_HANDLER(TestMsg_BadMessage, OnBadMessage)
56 IPC_END_MESSAGE_MAP() 56 IPC_END_MESSAGE_MAP()
57 return true; 57 return true;
58 } 58 }
59 59
60 virtual void OnBadMessageReceived(const IPC::Message& message) override { 60 void OnBadMessageReceived(const IPC::Message& message) override {
61 bad_message_received_ = true; 61 bad_message_received_ = true;
62 } 62 }
63 63
64 void OnQuit() { 64 void OnQuit() {
65 base::MessageLoop::current()->QuitWhenIdle(); 65 base::MessageLoop::current()->QuitWhenIdle();
66 } 66 }
67 67
68 void OnBadMessage(const BadType& bad_type) { 68 void OnBadMessage(const BadType& bad_type) {
69 // Should never be called since IPC wouldn't be deserialized correctly. 69 // Should never be called since IPC wouldn't be deserialized correctly.
70 CHECK(false); 70 CHECK(false);
71 } 71 }
72 72
73 bool bad_message_received_; 73 bool bad_message_received_;
74 }; 74 };
75 75
76 class ChannelReflectorListener : public IPC::Listener { 76 class ChannelReflectorListener : public IPC::Listener {
77 public: 77 public:
78 ChannelReflectorListener() : channel_(NULL) {} 78 ChannelReflectorListener() : channel_(NULL) {}
79 virtual ~ChannelReflectorListener() {} 79 ~ChannelReflectorListener() override {}
80 80
81 void Init(IPC::Channel* channel) { 81 void Init(IPC::Channel* channel) {
82 DCHECK(!channel_); 82 DCHECK(!channel_);
83 channel_ = channel; 83 channel_ = channel;
84 } 84 }
85 85
86 virtual bool OnMessageReceived(const IPC::Message& message) override { 86 bool OnMessageReceived(const IPC::Message& message) override {
87 IPC_BEGIN_MESSAGE_MAP(ChannelReflectorListener, message) 87 IPC_BEGIN_MESSAGE_MAP(ChannelReflectorListener, message)
88 IPC_MESSAGE_HANDLER(TestMsg_Bounce, OnTestBounce) 88 IPC_MESSAGE_HANDLER(TestMsg_Bounce, OnTestBounce)
89 IPC_MESSAGE_HANDLER(TestMsg_SendBadMessage, OnSendBadMessage) 89 IPC_MESSAGE_HANDLER(TestMsg_SendBadMessage, OnSendBadMessage)
90 IPC_MESSAGE_HANDLER(UtilityMsg_Bounce, OnUtilityBounce) 90 IPC_MESSAGE_HANDLER(UtilityMsg_Bounce, OnUtilityBounce)
91 IPC_MESSAGE_HANDLER(WorkerMsg_Bounce, OnBounce) 91 IPC_MESSAGE_HANDLER(WorkerMsg_Bounce, OnBounce)
92 IPC_MESSAGE_HANDLER(WorkerMsg_Quit, OnQuit) 92 IPC_MESSAGE_HANDLER(WorkerMsg_Quit, OnQuit)
93 IPC_END_MESSAGE_MAP() 93 IPC_END_MESSAGE_MAP()
94 return true; 94 return true;
95 } 95 }
96 96
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 last_filter_event_(NONE), 136 last_filter_event_(NONE),
137 message_filtering_enabled_(false) {} 137 message_filtering_enabled_(false) {}
138 138
139 MessageCountFilter(uint32 supported_message_class) 139 MessageCountFilter(uint32 supported_message_class)
140 : messages_received_(0), 140 : messages_received_(0),
141 supported_message_class_(supported_message_class), 141 supported_message_class_(supported_message_class),
142 is_global_filter_(false), 142 is_global_filter_(false),
143 last_filter_event_(NONE), 143 last_filter_event_(NONE),
144 message_filtering_enabled_(false) {} 144 message_filtering_enabled_(false) {}
145 145
146 virtual void OnFilterAdded(IPC::Sender* sender) override { 146 void OnFilterAdded(IPC::Sender* sender) override {
147 EXPECT_TRUE(sender); 147 EXPECT_TRUE(sender);
148 EXPECT_EQ(NONE, last_filter_event_); 148 EXPECT_EQ(NONE, last_filter_event_);
149 last_filter_event_ = FILTER_ADDED; 149 last_filter_event_ = FILTER_ADDED;
150 } 150 }
151 151
152 virtual void OnChannelConnected(int32_t peer_pid) override { 152 void OnChannelConnected(int32_t peer_pid) override {
153 EXPECT_EQ(FILTER_ADDED, last_filter_event_); 153 EXPECT_EQ(FILTER_ADDED, last_filter_event_);
154 EXPECT_NE(static_cast<int32_t>(base::kNullProcessId), peer_pid); 154 EXPECT_NE(static_cast<int32_t>(base::kNullProcessId), peer_pid);
155 last_filter_event_ = CHANNEL_CONNECTED; 155 last_filter_event_ = CHANNEL_CONNECTED;
156 } 156 }
157 157
158 virtual void OnChannelError() override { 158 void OnChannelError() override {
159 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); 159 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_);
160 last_filter_event_ = CHANNEL_ERROR; 160 last_filter_event_ = CHANNEL_ERROR;
161 } 161 }
162 162
163 virtual void OnChannelClosing() override { 163 void OnChannelClosing() override {
164 // We may or may not have gotten OnChannelError; if not, the last event has 164 // We may or may not have gotten OnChannelError; if not, the last event has
165 // to be OnChannelConnected. 165 // to be OnChannelConnected.
166 if (last_filter_event_ != CHANNEL_ERROR) 166 if (last_filter_event_ != CHANNEL_ERROR)
167 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); 167 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_);
168 last_filter_event_ = CHANNEL_CLOSING; 168 last_filter_event_ = CHANNEL_CLOSING;
169 } 169 }
170 170
171 virtual void OnFilterRemoved() override { 171 void OnFilterRemoved() override {
172 // If the channel didn't get a chance to connect, we might see the 172 // If the channel didn't get a chance to connect, we might see the
173 // OnFilterRemoved event with no other events preceding it. We still want 173 // OnFilterRemoved event with no other events preceding it. We still want
174 // OnFilterRemoved to be called to allow for deleting the Filter. 174 // OnFilterRemoved to be called to allow for deleting the Filter.
175 if (last_filter_event_ != NONE) 175 if (last_filter_event_ != NONE)
176 EXPECT_EQ(CHANNEL_CLOSING, last_filter_event_); 176 EXPECT_EQ(CHANNEL_CLOSING, last_filter_event_);
177 last_filter_event_ = FILTER_REMOVED; 177 last_filter_event_ = FILTER_REMOVED;
178 } 178 }
179 179
180 virtual bool OnMessageReceived(const IPC::Message& message) override { 180 bool OnMessageReceived(const IPC::Message& message) override {
181 // We should always get the OnFilterAdded and OnChannelConnected events 181 // We should always get the OnFilterAdded and OnChannelConnected events
182 // prior to any messages. 182 // prior to any messages.
183 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); 183 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_);
184 184
185 if (!is_global_filter_) { 185 if (!is_global_filter_) {
186 EXPECT_EQ(supported_message_class_, IPC_MESSAGE_CLASS(message)); 186 EXPECT_EQ(supported_message_class_, IPC_MESSAGE_CLASS(message));
187 } 187 }
188 ++messages_received_; 188 ++messages_received_;
189 189
190 if (!message_filtering_enabled_) 190 if (!message_filtering_enabled_)
191 return false; 191 return false;
192 192
193 bool handled = true; 193 bool handled = true;
194 IPC_BEGIN_MESSAGE_MAP(MessageCountFilter, message) 194 IPC_BEGIN_MESSAGE_MAP(MessageCountFilter, message)
195 IPC_MESSAGE_HANDLER(TestMsg_BadMessage, OnBadMessage) 195 IPC_MESSAGE_HANDLER(TestMsg_BadMessage, OnBadMessage)
196 IPC_MESSAGE_UNHANDLED(handled = false) 196 IPC_MESSAGE_UNHANDLED(handled = false)
197 IPC_END_MESSAGE_MAP() 197 IPC_END_MESSAGE_MAP()
198 return handled; 198 return handled;
199 } 199 }
200 200
201 void OnBadMessage(const BadType& bad_type) { 201 void OnBadMessage(const BadType& bad_type) {
202 // Should never be called since IPC wouldn't be deserialized correctly. 202 // Should never be called since IPC wouldn't be deserialized correctly.
203 CHECK(false); 203 CHECK(false);
204 } 204 }
205 205
206 virtual bool GetSupportedMessageClasses( 206 bool GetSupportedMessageClasses(
207 std::vector<uint32>* supported_message_classes) const override { 207 std::vector<uint32>* supported_message_classes) const override {
208 if (is_global_filter_) 208 if (is_global_filter_)
209 return false; 209 return false;
210 supported_message_classes->push_back(supported_message_class_); 210 supported_message_classes->push_back(supported_message_class_);
211 return true; 211 return true;
212 } 212 }
213 213
214 void set_message_filtering_enabled(bool enabled) { 214 void set_message_filtering_enabled(bool enabled) {
215 message_filtering_enabled_ = enabled; 215 message_filtering_enabled_ = enabled;
216 } 216 }
217 217
218 size_t messages_received() const { return messages_received_; } 218 size_t messages_received() const { return messages_received_; }
219 FilterEvent last_filter_event() const { return last_filter_event_; } 219 FilterEvent last_filter_event() const { return last_filter_event_; }
220 220
221 private: 221 private:
222 virtual ~MessageCountFilter() {} 222 ~MessageCountFilter() override {}
223 223
224 size_t messages_received_; 224 size_t messages_received_;
225 uint32 supported_message_class_; 225 uint32 supported_message_class_;
226 bool is_global_filter_; 226 bool is_global_filter_;
227 227
228 FilterEvent last_filter_event_; 228 FilterEvent last_filter_event_;
229 bool message_filtering_enabled_; 229 bool message_filtering_enabled_;
230 }; 230 };
231 231
232 class IPCChannelProxyTest : public IPCTestBase { 232 class IPCChannelProxyTest : public IPCTestBase {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 IPCTestBase::GetChannelName("ChannelProxyClient"), 432 IPCTestBase::GetChannelName("ChannelProxyClient"),
433 &listener)); 433 &listener));
434 CHECK(channel->Connect()); 434 CHECK(channel->Connect());
435 listener.Init(channel.get()); 435 listener.Init(channel.get());
436 436
437 base::MessageLoop::current()->Run(); 437 base::MessageLoop::current()->Run();
438 return 0; 438 return 0;
439 } 439 }
440 440
441 } // namespace 441 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_channel_proxy.h ('k') | ipc/ipc_channel_unittest.cc » ('j') | ipc/ipc_message_macros.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698