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

Side by Side Diff: ipc/mojo/ipc_channel_mojo_unittest.cc

Issue 598093006: Fix IPCChannelMojoErrorTest.SendFailWithPendingMessages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ipc/mojo/ipc_channel_mojo.h" 5 #include "ipc/mojo/ipc_channel_mojo.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 IPC::TestChannelListener::SendOneMessage( 152 IPC::TestChannelListener::SendOneMessage(
153 client.channel(), "hello from child"); 153 client.channel(), "hello from child");
154 base::MessageLoop::current()->Run(); 154 base::MessageLoop::current()->Run();
155 EXPECT_TRUE(listener.is_connected_called()); 155 EXPECT_TRUE(listener.is_connected_called());
156 EXPECT_TRUE(listener.HasSentAll()); 156 EXPECT_TRUE(listener.HasSentAll());
157 157
158 return 0; 158 return 0;
159 } 159 }
160 160
161 // Close given handle before use to simulate an error.
162 class ErraticChannelMojo : public IPC::ChannelMojo {
163 public:
164 ErraticChannelMojo(IPC::ChannelMojoHost* host,
165 const IPC::ChannelHandle& channel_handle,
166 IPC::Channel::Mode mode,
167 IPC::Listener* listener,
168 scoped_refptr<base::TaskRunner> runner)
169 : ChannelMojo(host, channel_handle, mode, listener) {}
170
171 virtual void OnConnected(mojo::ScopedMessagePipeHandle pipe) {
172 MojoClose(pipe.get().value());
173 OnConnected(pipe.Pass());
174 }
175 };
176
177 // Exists to create ErraticChannelMojo.
178 class ErraticChannelFactory : public IPC::ChannelFactory {
179 public:
180 explicit ErraticChannelFactory(IPC::ChannelMojoHost* host,
181 const IPC::ChannelHandle& handle,
182 base::TaskRunner* runner)
183 : host_(host), handle_(handle), runner_(runner) {}
184
185 virtual std::string GetName() const OVERRIDE {
186 return "";
187 }
188
189 virtual scoped_ptr<IPC::Channel> BuildChannel(
190 IPC::Listener* listener) OVERRIDE {
191 return scoped_ptr<IPC::Channel>(new ErraticChannelMojo(
192 host_, handle_, IPC::Channel::MODE_SERVER, listener, runner_));
193 }
194
195 private:
196 IPC::ChannelMojoHost* host_;
197 IPC::ChannelHandle handle_;
198 scoped_refptr<base::TaskRunner> runner_;
199 };
200
201 class ListenerExpectingErrors : public IPC::Listener { 161 class ListenerExpectingErrors : public IPC::Listener {
202 public: 162 public:
203 ListenerExpectingErrors() 163 ListenerExpectingErrors()
204 : has_error_(false) { 164 : has_error_(false) {
205 } 165 }
206 166
167 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE {
168 base::MessageLoop::current()->Quit();
169 }
170
207 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { 171 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
208 return true; 172 return true;
209 } 173 }
210 174
211 virtual void OnChannelError() OVERRIDE { 175 virtual void OnChannelError() OVERRIDE {
212 has_error_ = true; 176 has_error_ = true;
213 base::MessageLoop::current()->Quit(); 177 base::MessageLoop::current()->Quit();
214 } 178 }
215 179
216 bool has_error() const { return has_error_; } 180 bool has_error() const { return has_error_; }
217 181
218 private: 182 private:
219 bool has_error_; 183 bool has_error_;
220 }; 184 };
221 185
222 186
223 class IPCChannelMojoErrorTest : public IPCTestBase { 187 class IPCChannelMojoErrorTest : public IPCTestBase {
224 protected: 188 protected:
225 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( 189 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
226 const IPC::ChannelHandle& handle, 190 const IPC::ChannelHandle& handle,
227 base::TaskRunner* runner) OVERRIDE { 191 base::TaskRunner* runner) OVERRIDE {
228 host_.reset(new IPC::ChannelMojoHost(task_runner())); 192 host_.reset(new IPC::ChannelMojoHost(task_runner()));
229 return scoped_ptr<IPC::ChannelFactory>( 193 return IPC::ChannelMojo::CreateServerFactory(host_.get(), handle);
230 new ErraticChannelFactory(host_.get(), handle, runner));
231 } 194 }
232 195
233 virtual bool DidStartClient() OVERRIDE { 196 virtual bool DidStartClient() OVERRIDE {
234 bool ok = IPCTestBase::DidStartClient(); 197 bool ok = IPCTestBase::DidStartClient();
235 DCHECK(ok); 198 DCHECK(ok);
236 host_->OnClientLaunched(client_process()); 199 host_->OnClientLaunched(client_process());
237 return ok; 200 return ok;
238 } 201 }
239 202
240 private: 203 private:
(...skipping 18 matching lines...) Expand all
259 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoErraticTestClient) { 222 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoErraticTestClient) {
260 ListenerThatQuits listener; 223 ListenerThatQuits listener;
261 ChannelClient client(&listener, "IPCChannelMojoErraticTestClient"); 224 ChannelClient client(&listener, "IPCChannelMojoErraticTestClient");
262 client.Connect(); 225 client.Connect();
263 226
264 base::MessageLoop::current()->Run(); 227 base::MessageLoop::current()->Run();
265 228
266 return 0; 229 return 0;
267 } 230 }
268 231
269 // https://crbug.com/417439 232 TEST_F(IPCChannelMojoErrorTest, SendFailWithPendingMessages) {
270 TEST_F(IPCChannelMojoErrorTest, DISABLED_SendFailWithPendingMessages) {
271 Init("IPCChannelMojoErraticTestClient"); 233 Init("IPCChannelMojoErraticTestClient");
272 234
273 // Set up IPC channel and start client. 235 // Set up IPC channel and start client.
274 ListenerExpectingErrors listener; 236 ListenerExpectingErrors listener;
275 CreateChannel(&listener); 237 CreateChannel(&listener);
276 ASSERT_TRUE(ConnectChannel()); 238 ASSERT_TRUE(ConnectChannel());
277 239
240 // This matches a value in mojo/system/constants.h
241 const int kMaxMessageNumBytes = 4 * 1024 * 1024;
242 std::string overly_large_data(kMaxMessageNumBytes, '*');
278 // This messages are queued as pending. 243 // This messages are queued as pending.
279 for (size_t i = 0; i < 2; ++i) { 244 for (size_t i = 0; i < 10; ++i) {
280 IPC::TestChannelListener::SendOneMessage( 245 IPC::TestChannelListener::SendOneMessage(
281 sender(), "hello from parent"); 246 sender(), overly_large_data.c_str());
282 } 247 }
283 248
284 ASSERT_TRUE(StartClient()); 249 ASSERT_TRUE(StartClient());
285 base::MessageLoop::current()->Run(); 250 base::MessageLoop::current()->Run();
286 251
287 this->channel()->Close(); 252 this->channel()->Close();
288 253
289 EXPECT_TRUE(WaitForClientShutdown()); 254 EXPECT_TRUE(WaitForClientShutdown());
290 EXPECT_TRUE(listener.has_error()); 255 EXPECT_TRUE(listener.has_error());
291 256
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 client.Connect(); 339 client.Connect();
375 listener.set_sender(client.channel()); 340 listener.set_sender(client.channel());
376 341
377 base::MessageLoop::current()->Run(); 342 base::MessageLoop::current()->Run();
378 343
379 return 0; 344 return 0;
380 } 345 }
381 #endif 346 #endif
382 347
383 } // namespace 348 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698