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

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

Issue 591463003: Remote Assistance on Chrome OS Part III - NativeMessageHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@native_messaging
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 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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/stringize_macros.h" 14 #include "base/strings/stringize_macros.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "net/base/file_stream.h" 16 #include "net/base/file_stream.h"
17 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
18 #include "remoting/base/auto_thread_task_runner.h" 18 #include "remoting/base/auto_thread_task_runner.h"
19 #include "remoting/host/chromoting_host_context.h" 19 #include "remoting/host/chromoting_host_context.h"
20 #include "remoting/host/native_messaging/native_messaging_pipe.h"
20 #include "remoting/host/native_messaging/pipe_messaging_channel.h" 21 #include "remoting/host/native_messaging/pipe_messaging_channel.h"
21 #include "remoting/host/setup/test_util.h" 22 #include "remoting/host/setup/test_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 namespace remoting { 25 namespace remoting {
25 26
26 namespace { 27 namespace {
27 28
28 const char kTestAccessCode[] = "888888"; 29 const char kTestAccessCode[] = "888888";
29 const int kTestAccessCodeLifetimeInSeconds = 666; 30 const int kTestAccessCodeLifetimeInSeconds = 666;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 203
203 // Message loop of the test thread. 204 // Message loop of the test thread.
204 scoped_ptr<base::MessageLoop> test_message_loop_; 205 scoped_ptr<base::MessageLoop> test_message_loop_;
205 scoped_ptr<base::RunLoop> test_run_loop_; 206 scoped_ptr<base::RunLoop> test_run_loop_;
206 207
207 scoped_ptr<base::Thread> host_thread_; 208 scoped_ptr<base::Thread> host_thread_;
208 scoped_ptr<base::RunLoop> host_run_loop_; 209 scoped_ptr<base::RunLoop> host_run_loop_;
209 210
210 // Task runner of the host thread. 211 // Task runner of the host thread.
211 scoped_refptr<AutoThreadTaskRunner> host_task_runner_; 212 scoped_refptr<AutoThreadTaskRunner> host_task_runner_;
212 scoped_ptr<remoting::It2MeNativeMessagingHost> host_; 213 scoped_ptr<remoting::NativeMessagingPipe> pipe_;
213 214
214 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHostTest); 215 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHostTest);
215 }; 216 };
216 217
217 void It2MeNativeMessagingHostTest::SetUp() { 218 void It2MeNativeMessagingHostTest::SetUp() {
218 test_message_loop_.reset(new base::MessageLoop()); 219 test_message_loop_.reset(new base::MessageLoop());
219 test_run_loop_.reset(new base::RunLoop()); 220 test_run_loop_.reset(new base::RunLoop());
220 221
221 // Run the host on a dedicated thread. 222 // Run the host on a dedicated thread.
222 host_thread_.reset(new base::Thread("host_thread")); 223 host_thread_.reset(new base::Thread("host_thread"));
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 425
425 base::File input_read_file; 426 base::File input_read_file;
426 base::File output_write_file; 427 base::File output_write_file;
427 428
428 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); 429 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_));
429 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); 430 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file));
430 431
431 // Creating a native messaging host with a mock It2MeHostFactory. 432 // Creating a native messaging host with a mock It2MeHostFactory.
432 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); 433 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory());
433 434
435 pipe_.reset(new NativeMessagingPipe());
436
434 scoped_ptr<extensions::NativeMessagingChannel> channel( 437 scoped_ptr<extensions::NativeMessagingChannel> channel(
435 new PipeMessagingChannel(input_read_file.Pass(), 438 new PipeMessagingChannel(input_read_file.Pass(),
436 output_write_file.Pass())); 439 output_write_file.Pass()));
437 440
438 host_.reset(new It2MeNativeMessagingHost( 441 scoped_ptr<extensions::NativeMessageHost> it2me_host(
439 host_task_runner_, 442 new It2MeNativeMessagingHost(
440 channel.Pass(), 443 host_task_runner_,
441 factory.Pass())); 444 factory.Pass()));
442 host_->Start(base::Bind(&It2MeNativeMessagingHostTest::StopHost, 445 it2me_host->Start(pipe_.get());
446
447 pipe_->Start(it2me_host.Pass(),
448 channel.Pass(),
449 base::Bind(&It2MeNativeMessagingHostTest::StopHost,
443 base::Unretained(this))); 450 base::Unretained(this)));
444 451
445 // Notify the test that the host has finished starting up. 452 // Notify the test that the host has finished starting up.
446 test_message_loop_->message_loop_proxy()->PostTask( 453 test_message_loop_->message_loop_proxy()->PostTask(
447 FROM_HERE, test_run_loop_->QuitClosure()); 454 FROM_HERE, test_run_loop_->QuitClosure());
448 } 455 }
449 456
450 void It2MeNativeMessagingHostTest::StopHost() { 457 void It2MeNativeMessagingHostTest::StopHost() {
451 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); 458 DCHECK(host_task_runner_->RunsTasksOnCurrentThread());
452 459
453 host_.reset(); 460 pipe_.reset();
454 461
455 // Wait till all shutdown tasks have completed. 462 // Wait till all shutdown tasks have completed.
456 base::RunLoop().RunUntilIdle(); 463 base::RunLoop().RunUntilIdle();
457 464
458 // Trigger a test shutdown via ExitTest(). 465 // Trigger a test shutdown via ExitTest().
459 host_task_runner_ = NULL; 466 host_task_runner_ = NULL;
460 } 467 }
461 468
462 void It2MeNativeMessagingHostTest::ExitTest() { 469 void It2MeNativeMessagingHostTest::ExitTest() {
463 if (!test_message_loop_->message_loop_proxy()->RunsTasksOnCurrentThread()) { 470 if (!test_message_loop_->message_loop_proxy()->RunsTasksOnCurrentThread()) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 554
548 // Verify rejection if type is unrecognized. 555 // Verify rejection if type is unrecognized.
549 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { 556 TEST_F(It2MeNativeMessagingHostTest, InvalidType) {
550 base::DictionaryValue message; 557 base::DictionaryValue message;
551 message.SetString("type", "xxx"); 558 message.SetString("type", "xxx");
552 TestBadRequest(message, true); 559 TestBadRequest(message, true);
553 } 560 }
554 561
555 } // namespace remoting 562 } // namespace remoting
556 563
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698