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

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

Issue 654113002: ChannelMojo: Fail when GetFileHandleForProcess() failed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated 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
« no previous file with comments | « no previous file | ipc/mojo/ipc_mojo_bootstrap.h » ('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 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 base::MessageLoop::current()->Run(); 252 base::MessageLoop::current()->Run();
253 253
254 this->channel()->Close(); 254 this->channel()->Close();
255 255
256 EXPECT_TRUE(WaitForClientShutdown()); 256 EXPECT_TRUE(WaitForClientShutdown());
257 EXPECT_TRUE(listener.has_error()); 257 EXPECT_TRUE(listener.has_error());
258 258
259 DestroyChannel(); 259 DestroyChannel();
260 } 260 }
261 261
262 #if defined(OS_WIN)
263 class IPCChannelMojoDeadHandleTest : public IPCTestBase {
264 protected:
265 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
266 const IPC::ChannelHandle& handle,
267 base::TaskRunner* runner) override {
268 host_.reset(new IPC::ChannelMojoHost(task_runner()));
269 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
270 handle);
271 }
272
273 virtual bool DidStartClient() override {
274 IPCTestBase::DidStartClient();
275 base::ProcessHandle client = client_process();
276 // Forces GetFileHandleForProcess() fail. It happens occasionally
277 // in production, so we should exercise it somehow.
278 ::CloseHandle(client);
279 host_->OnClientLaunched(client);
280 return true;
281 }
282
283 private:
284 scoped_ptr<IPC::ChannelMojoHost> host_;
285 };
286
287 TEST_F(IPCChannelMojoDeadHandleTest, InvalidClientHandle) {
288 // Any client type is fine as it is going to be killed anyway.
289 Init("IPCChannelMojoTestDoNothingClient");
290
291 // Set up IPC channel and start client.
292 ListenerExpectingErrors listener;
293 CreateChannel(&listener);
294 ASSERT_TRUE(ConnectChannel());
295
296 ASSERT_TRUE(StartClient());
297 base::MessageLoop::current()->Run();
298
299 this->channel()->Close();
300
301 // WaitForClientShutdown() fails as client_hanadle() is already
302 // closed.
303 EXPECT_FALSE(WaitForClientShutdown());
304 EXPECT_TRUE(listener.has_error());
305
306 DestroyChannel();
307 }
308
309 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestDoNothingClient) {
310 ListenerThatQuits listener;
311 ChannelClient client(&listener, "IPCChannelMojoTestDoNothingClient");
312 client.Connect();
313
314 // Quits without running the message loop as this client won't
315 // receive any messages from the server.
316
317 return 0;
318 }
319 #endif
262 320
263 #if defined(OS_POSIX) 321 #if defined(OS_POSIX)
264 class ListenerThatExpectsFile : public IPC::Listener { 322 class ListenerThatExpectsFile : public IPC::Listener {
265 public: 323 public:
266 ListenerThatExpectsFile() 324 ListenerThatExpectsFile()
267 : sender_(NULL) {} 325 : sender_(NULL) {}
268 326
269 virtual ~ListenerThatExpectsFile() {} 327 virtual ~ListenerThatExpectsFile() {}
270 328
271 virtual bool OnMessageReceived(const IPC::Message& message) override { 329 virtual bool OnMessageReceived(const IPC::Message& message) override {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 client.Connect(); 399 client.Connect();
342 listener.set_sender(client.channel()); 400 listener.set_sender(client.channel());
343 401
344 base::MessageLoop::current()->Run(); 402 base::MessageLoop::current()->Run();
345 403
346 return 0; 404 return 0;
347 } 405 }
348 #endif 406 #endif
349 407
350 } // namespace 408 } // namespace
OLDNEW
« no previous file with comments | « no previous file | ipc/mojo/ipc_mojo_bootstrap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698