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

Side by Side Diff: remoting/host/it2me/it2me_native_messaging_host_unittest.cc

Issue 887853002: Shutdown the It2Me host cleanly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@it2me_host_dcheck
Patch Set: Created 5 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "remoting/host/it2me/it2me_native_messaging_host.h" 5 #include "remoting/host/it2me/it2me_native_messaging_host.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 // The Host process should shut down when it receives a malformed request. 184 // The Host process should shut down when it receives a malformed request.
185 // This is tested by sending a known-good request, followed by |message|, 185 // This is tested by sending a known-good request, followed by |message|,
186 // followed by the known-good request again. The response file should only 186 // followed by the known-good request again. The response file should only
187 // contain a single response from the first good request. 187 // contain a single response from the first good request.
188 void TestBadRequest(const base::Value& message, bool expect_error_response); 188 void TestBadRequest(const base::Value& message, bool expect_error_response);
189 void TestConnect(); 189 void TestConnect();
190 190
191 private: 191 private:
192 void StartHost(); 192 void StartHost();
193 void StopHost();
194 void ExitTest(); 193 void ExitTest();
195 194
196 // Each test creates two unidirectional pipes: "input" and "output". 195 // Each test creates two unidirectional pipes: "input" and "output".
197 // It2MeNativeMessagingHost reads from input_read_file and writes to 196 // It2MeNativeMessagingHost reads from input_read_file and writes to
198 // output_write_file. The unittest supplies data to input_write_handle, and 197 // output_write_file. The unittest supplies data to input_write_handle, and
199 // verifies output from output_read_handle. 198 // verifies output from output_read_handle.
200 // 199 //
201 // unittest -> [input] -> It2MeNativeMessagingHost -> [output] -> unittest 200 // unittest -> [input] -> It2MeNativeMessagingHost -> [output] -> unittest
202 base::File input_write_file_; 201 base::File input_write_file_;
203 base::File output_read_file_; 202 base::File output_read_file_;
(...skipping 28 matching lines...) Expand all
232 host_task_runner_->PostTask( 231 host_task_runner_->PostTask(
233 FROM_HERE, 232 FROM_HERE,
234 base::Bind(&It2MeNativeMessagingHostTest::StartHost, 233 base::Bind(&It2MeNativeMessagingHostTest::StartHost,
235 base::Unretained(this))); 234 base::Unretained(this)));
236 235
237 // Wait until the host finishes starting. 236 // Wait until the host finishes starting.
238 test_run_loop_->Run(); 237 test_run_loop_->Run();
239 } 238 }
240 239
241 void It2MeNativeMessagingHostTest::TearDown() { 240 void It2MeNativeMessagingHostTest::TearDown() {
241 // Release reference to AutoThreadTaskRunner, so the host thread can be shut
242 // down.
243 host_task_runner_ = nullptr;
244
242 // Closing the write-end of the input will send an EOF to the native 245 // Closing the write-end of the input will send an EOF to the native
243 // messaging reader. This will trigger a host shutdown. 246 // messaging reader. This will trigger a host shutdown.
244 input_write_file_.Close(); 247 input_write_file_.Close();
245 248
246 // Start a new RunLoop and Wait until the host finishes shutting down. 249 // Start a new RunLoop and Wait until the host finishes shutting down.
247 test_run_loop_.reset(new base::RunLoop()); 250 test_run_loop_.reset(new base::RunLoop());
248 test_run_loop_->Run(); 251 test_run_loop_->Run();
249 252
250 // Verify there are no more message in the output pipe. 253 // Verify there are no more message in the output pipe.
251 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 254 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 new PipeMessagingChannel(input_read_file.Pass(), 439 new PipeMessagingChannel(input_read_file.Pass(),
437 output_write_file.Pass())); 440 output_write_file.Pass()));
438 441
439 // Creating a native messaging host with a mock It2MeHostFactory. 442 // Creating a native messaging host with a mock It2MeHostFactory.
440 scoped_ptr<extensions::NativeMessageHost> it2me_host( 443 scoped_ptr<extensions::NativeMessageHost> it2me_host(
441 new It2MeNativeMessagingHost( 444 new It2MeNativeMessagingHost(
442 ChromotingHostContext::Create(host_task_runner_), 445 ChromotingHostContext::Create(host_task_runner_),
443 make_scoped_ptr(new MockIt2MeHostFactory()))); 446 make_scoped_ptr(new MockIt2MeHostFactory())));
444 it2me_host->Start(pipe_.get()); 447 it2me_host->Start(pipe_.get());
445 448
446 pipe_->Start(it2me_host.Pass(), 449 pipe_->Start(it2me_host.Pass(), channel.Pass());
447 channel.Pass(),
448 base::Bind(&It2MeNativeMessagingHostTest::StopHost,
449 base::Unretained(this)));
450 450
451 // Notify the test that the host has finished starting up. 451 // Notify the test that the host has finished starting up.
452 test_message_loop_->message_loop_proxy()->PostTask( 452 test_message_loop_->message_loop_proxy()->PostTask(
453 FROM_HERE, test_run_loop_->QuitClosure()); 453 FROM_HERE, test_run_loop_->QuitClosure());
454 } 454 }
455 455
456 void It2MeNativeMessagingHostTest::StopHost() {
457 DCHECK(host_task_runner_->RunsTasksOnCurrentThread());
458
459 pipe_.reset();
460
461 // Wait till all shutdown tasks have completed.
462 base::RunLoop().RunUntilIdle();
463
464 // Trigger a test shutdown via ExitTest().
465 host_task_runner_ = nullptr;
466 }
467
468 void It2MeNativeMessagingHostTest::ExitTest() { 456 void It2MeNativeMessagingHostTest::ExitTest() {
469 if (!test_message_loop_->message_loop_proxy()->RunsTasksOnCurrentThread()) { 457 if (!test_message_loop_->message_loop_proxy()->RunsTasksOnCurrentThread()) {
470 test_message_loop_->message_loop_proxy()->PostTask( 458 test_message_loop_->message_loop_proxy()->PostTask(
471 FROM_HERE, 459 FROM_HERE,
472 base::Bind(&It2MeNativeMessagingHostTest::ExitTest, 460 base::Bind(&It2MeNativeMessagingHostTest::ExitTest,
473 base::Unretained(this))); 461 base::Unretained(this)));
474 return; 462 return;
475 } 463 }
476 test_run_loop_->Quit(); 464 test_run_loop_->Quit();
477 } 465 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 541
554 // Verify rejection if type is unrecognized. 542 // Verify rejection if type is unrecognized.
555 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { 543 TEST_F(It2MeNativeMessagingHostTest, InvalidType) {
556 base::DictionaryValue message; 544 base::DictionaryValue message;
557 message.SetString("type", "xxx"); 545 message.SetString("type", "xxx");
558 TestBadRequest(message, true); 546 TestBadRequest(message, true);
559 } 547 }
560 548
561 } // namespace remoting 549 } // namespace remoting
562 550
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host_main.cc ('k') | remoting/host/native_messaging/native_messaging_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698