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

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

Issue 637463002: Revert "Remote Assistance on Chrome OS Part III - NativeMessageHost" (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 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"
21 #include "remoting/host/native_messaging/pipe_messaging_channel.h" 20 #include "remoting/host/native_messaging/pipe_messaging_channel.h"
22 #include "remoting/host/setup/test_util.h" 21 #include "remoting/host/setup/test_util.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 23
25 namespace remoting { 24 namespace remoting {
26 25
27 namespace { 26 namespace {
28 27
29 const char kTestAccessCode[] = "888888"; 28 const char kTestAccessCode[] = "888888";
30 const int kTestAccessCodeLifetimeInSeconds = 666; 29 const int kTestAccessCodeLifetimeInSeconds = 666;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 base::WeakPtr<It2MeHost::Observer> observer, 71 base::WeakPtr<It2MeHost::Observer> observer,
73 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 72 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
74 const std::string& directory_bot_jid) 73 const std::string& directory_bot_jid)
75 : It2MeHost(context, 74 : It2MeHost(context,
76 task_runner, 75 task_runner,
77 observer, 76 observer,
78 xmpp_server_config, 77 xmpp_server_config,
79 directory_bot_jid) {} 78 directory_bot_jid) {}
80 79
81 // It2MeHost overrides 80 // It2MeHost overrides
82 virtual void Connect() override; 81 virtual void Connect() OVERRIDE;
83 virtual void Disconnect() override; 82 virtual void Disconnect() OVERRIDE;
84 virtual void RequestNatPolicy() override; 83 virtual void RequestNatPolicy() OVERRIDE;
85 84
86 private: 85 private:
87 virtual ~MockIt2MeHost() {} 86 virtual ~MockIt2MeHost() {}
88 87
89 void RunSetState(It2MeHostState state); 88 void RunSetState(It2MeHostState state);
90 89
91 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHost); 90 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHost);
92 }; 91 };
93 92
94 void MockIt2MeHost::Connect() { 93 void MockIt2MeHost::Connect() {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 146 }
148 147
149 class MockIt2MeHostFactory : public It2MeHostFactory { 148 class MockIt2MeHostFactory : public It2MeHostFactory {
150 public: 149 public:
151 MockIt2MeHostFactory() {} 150 MockIt2MeHostFactory() {}
152 virtual scoped_refptr<It2MeHost> CreateIt2MeHost( 151 virtual scoped_refptr<It2MeHost> CreateIt2MeHost(
153 ChromotingHostContext* context, 152 ChromotingHostContext* context,
154 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 153 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
155 base::WeakPtr<It2MeHost::Observer> observer, 154 base::WeakPtr<It2MeHost::Observer> observer,
156 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 155 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
157 const std::string& directory_bot_jid) override { 156 const std::string& directory_bot_jid) OVERRIDE {
158 return new MockIt2MeHost( 157 return new MockIt2MeHost(
159 context, task_runner, observer, xmpp_server_config, directory_bot_jid); 158 context, task_runner, observer, xmpp_server_config, directory_bot_jid);
160 } 159 }
161 160
162 private: 161 private:
163 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory); 162 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory);
164 }; // MockIt2MeHostFactory 163 }; // MockIt2MeHostFactory
165 164
166 class It2MeNativeMessagingHostTest : public testing::Test { 165 class It2MeNativeMessagingHostTest : public testing::Test {
167 public: 166 public:
168 It2MeNativeMessagingHostTest() {} 167 It2MeNativeMessagingHostTest() {}
169 virtual ~It2MeNativeMessagingHostTest() {} 168 virtual ~It2MeNativeMessagingHostTest() {}
170 169
171 virtual void SetUp() override; 170 virtual void SetUp() OVERRIDE;
172 virtual void TearDown() override; 171 virtual void TearDown() OVERRIDE;
173 172
174 protected: 173 protected:
175 scoped_ptr<base::DictionaryValue> ReadMessageFromOutputPipe(); 174 scoped_ptr<base::DictionaryValue> ReadMessageFromOutputPipe();
176 void WriteMessageToInputPipe(const base::Value& message); 175 void WriteMessageToInputPipe(const base::Value& message);
177 176
178 void VerifyHelloResponse(int request_id); 177 void VerifyHelloResponse(int request_id);
179 void VerifyErrorResponse(); 178 void VerifyErrorResponse();
180 void VerifyConnectResponses(int request_id); 179 void VerifyConnectResponses(int request_id);
181 void VerifyDisconnectResponses(int request_id); 180 void VerifyDisconnectResponses(int request_id);
182 181
(...skipping 20 matching lines...) Expand all
203 202
204 // Message loop of the test thread. 203 // Message loop of the test thread.
205 scoped_ptr<base::MessageLoop> test_message_loop_; 204 scoped_ptr<base::MessageLoop> test_message_loop_;
206 scoped_ptr<base::RunLoop> test_run_loop_; 205 scoped_ptr<base::RunLoop> test_run_loop_;
207 206
208 scoped_ptr<base::Thread> host_thread_; 207 scoped_ptr<base::Thread> host_thread_;
209 scoped_ptr<base::RunLoop> host_run_loop_; 208 scoped_ptr<base::RunLoop> host_run_loop_;
210 209
211 // Task runner of the host thread. 210 // Task runner of the host thread.
212 scoped_refptr<AutoThreadTaskRunner> host_task_runner_; 211 scoped_refptr<AutoThreadTaskRunner> host_task_runner_;
213 scoped_ptr<remoting::NativeMessagingPipe> pipe_; 212 scoped_ptr<remoting::It2MeNativeMessagingHost> host_;
214 213
215 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHostTest); 214 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHostTest);
216 }; 215 };
217 216
218 void It2MeNativeMessagingHostTest::SetUp() { 217 void It2MeNativeMessagingHostTest::SetUp() {
219 test_message_loop_.reset(new base::MessageLoop()); 218 test_message_loop_.reset(new base::MessageLoop());
220 test_run_loop_.reset(new base::RunLoop()); 219 test_run_loop_.reset(new base::RunLoop());
221 220
222 // Run the host on a dedicated thread. 221 // Run the host on a dedicated thread.
223 host_thread_.reset(new base::Thread("host_thread")); 222 host_thread_.reset(new base::Thread("host_thread"));
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 424
426 base::File input_read_file; 425 base::File input_read_file;
427 base::File output_write_file; 426 base::File output_write_file;
428 427
429 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); 428 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_));
430 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); 429 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file));
431 430
432 // Creating a native messaging host with a mock It2MeHostFactory. 431 // Creating a native messaging host with a mock It2MeHostFactory.
433 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); 432 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory());
434 433
435 pipe_.reset(new NativeMessagingPipe());
436
437 scoped_ptr<extensions::NativeMessagingChannel> channel( 434 scoped_ptr<extensions::NativeMessagingChannel> channel(
438 new PipeMessagingChannel(input_read_file.Pass(), 435 new PipeMessagingChannel(input_read_file.Pass(),
439 output_write_file.Pass())); 436 output_write_file.Pass()));
440 437
441 scoped_ptr<extensions::NativeMessageHost> it2me_host( 438 host_.reset(new It2MeNativeMessagingHost(
442 new It2MeNativeMessagingHost( 439 host_task_runner_,
443 host_task_runner_, 440 channel.Pass(),
444 factory.Pass())); 441 factory.Pass()));
445 it2me_host->Start(pipe_.get()); 442 host_->Start(base::Bind(&It2MeNativeMessagingHostTest::StopHost,
446
447 pipe_->Start(it2me_host.Pass(),
448 channel.Pass(),
449 base::Bind(&It2MeNativeMessagingHostTest::StopHost,
450 base::Unretained(this))); 443 base::Unretained(this)));
451 444
452 // Notify the test that the host has finished starting up. 445 // Notify the test that the host has finished starting up.
453 test_message_loop_->message_loop_proxy()->PostTask( 446 test_message_loop_->message_loop_proxy()->PostTask(
454 FROM_HERE, test_run_loop_->QuitClosure()); 447 FROM_HERE, test_run_loop_->QuitClosure());
455 } 448 }
456 449
457 void It2MeNativeMessagingHostTest::StopHost() { 450 void It2MeNativeMessagingHostTest::StopHost() {
458 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); 451 DCHECK(host_task_runner_->RunsTasksOnCurrentThread());
459 452
460 pipe_.reset(); 453 host_.reset();
461 454
462 // Wait till all shutdown tasks have completed. 455 // Wait till all shutdown tasks have completed.
463 base::RunLoop().RunUntilIdle(); 456 base::RunLoop().RunUntilIdle();
464 457
465 // Trigger a test shutdown via ExitTest(). 458 // Trigger a test shutdown via ExitTest().
466 host_task_runner_ = NULL; 459 host_task_runner_ = NULL;
467 } 460 }
468 461
469 void It2MeNativeMessagingHostTest::ExitTest() { 462 void It2MeNativeMessagingHostTest::ExitTest() {
470 if (!test_message_loop_->message_loop_proxy()->RunsTasksOnCurrentThread()) { 463 if (!test_message_loop_->message_loop_proxy()->RunsTasksOnCurrentThread()) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 547
555 // Verify rejection if type is unrecognized. 548 // Verify rejection if type is unrecognized.
556 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { 549 TEST_F(It2MeNativeMessagingHostTest, InvalidType) {
557 base::DictionaryValue message; 550 base::DictionaryValue message;
558 message.SetString("type", "xxx"); 551 message.SetString("type", "xxx");
559 TestBadRequest(message, true); 552 TestBadRequest(message, true);
560 } 553 }
561 554
562 } // namespace remoting 555 } // namespace remoting
563 556
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