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

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

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build error on ozone Created 6 years, 1 month 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/native_messaging_pipe.h"
21 #include "remoting/host/native_messaging/pipe_messaging_channel.h" 21 #include "remoting/host/native_messaging/pipe_messaging_channel.h"
22 #include "remoting/host/policy_hack/policy_watcher.h"
22 #include "remoting/host/setup/test_util.h" 23 #include "remoting/host/setup/test_util.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace remoting { 26 namespace remoting {
26 27
27 namespace { 28 namespace {
28 29
29 const char kTestAccessCode[] = "888888"; 30 const char kTestAccessCode[] = "888888";
30 const int kTestAccessCodeLifetimeInSeconds = 666; 31 const int kTestAccessCodeLifetimeInSeconds = 666;
31 const char kTestClientUsername[] = "some_user@gmail.com"; 32 const char kTestClientUsername[] = "some_user@gmail.com";
(...skipping 28 matching lines...) Expand all
60 61
61 int int_value; 62 int int_value;
62 EXPECT_TRUE(response->GetInteger("id", &int_value)); 63 EXPECT_TRUE(response->GetInteger("id", &int_value));
63 EXPECT_EQ(id, int_value); 64 EXPECT_EQ(id, int_value);
64 } 65 }
65 66
66 } // namespace 67 } // namespace
67 68
68 class MockIt2MeHost : public It2MeHost { 69 class MockIt2MeHost : public It2MeHost {
69 public: 70 public:
70 MockIt2MeHost(ChromotingHostContext* context, 71 MockIt2MeHost(scoped_ptr<ChromotingHostContext> context,
71 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 72 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher,
72 base::WeakPtr<It2MeHost::Observer> observer, 73 base::WeakPtr<It2MeHost::Observer> observer,
73 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 74 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
74 const std::string& directory_bot_jid) 75 const std::string& directory_bot_jid)
75 : It2MeHost(context, 76 : It2MeHost(context.Pass(),
76 task_runner, 77 policy_watcher.Pass(),
77 observer, 78 observer,
78 xmpp_server_config, 79 xmpp_server_config,
79 directory_bot_jid) {} 80 directory_bot_jid) {}
80 81
81 // It2MeHost overrides 82 // It2MeHost overrides
82 void Connect() override; 83 void Connect() override;
83 void Disconnect() override; 84 void Disconnect() override;
84 void RequestNatPolicy() override; 85 void RequestNatPolicy() override;
85 86
86 private: 87 private:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) { 142 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) {
142 host_context()->network_task_runner()->PostTask( 143 host_context()->network_task_runner()->PostTask(
143 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state)); 144 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state));
144 } else { 145 } else {
145 SetStateForTesting(state); 146 SetStateForTesting(state);
146 } 147 }
147 } 148 }
148 149
149 class MockIt2MeHostFactory : public It2MeHostFactory { 150 class MockIt2MeHostFactory : public It2MeHostFactory {
150 public: 151 public:
151 MockIt2MeHostFactory() {} 152 MockIt2MeHostFactory() : It2MeHostFactory() {}
152 scoped_refptr<It2MeHost> CreateIt2MeHost( 153 scoped_refptr<It2MeHost> CreateIt2MeHost(
153 ChromotingHostContext* context, 154 scoped_ptr<ChromotingHostContext> context,
154 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
155 base::WeakPtr<It2MeHost::Observer> observer, 155 base::WeakPtr<It2MeHost::Observer> observer,
156 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 156 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
157 const std::string& directory_bot_jid) override { 157 const std::string& directory_bot_jid) override {
158 return new MockIt2MeHost( 158 return new MockIt2MeHost(context.Pass(), nullptr, observer,
159 context, task_runner, observer, xmpp_server_config, directory_bot_jid); 159 xmpp_server_config, directory_bot_jid);
160 } 160 }
161 161
162 private: 162 private:
163 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory); 163 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory);
164 }; // MockIt2MeHostFactory 164 }; // MockIt2MeHostFactory
165 165
166 class It2MeNativeMessagingHostTest : public testing::Test { 166 class It2MeNativeMessagingHostTest : public testing::Test {
167 public: 167 public:
168 It2MeNativeMessagingHostTest() {} 168 It2MeNativeMessagingHostTest() {}
169 ~It2MeNativeMessagingHostTest() override {} 169 ~It2MeNativeMessagingHostTest() override {}
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 422
423 void It2MeNativeMessagingHostTest::StartHost() { 423 void It2MeNativeMessagingHostTest::StartHost() {
424 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); 424 DCHECK(host_task_runner_->RunsTasksOnCurrentThread());
425 425
426 base::File input_read_file; 426 base::File input_read_file;
427 base::File output_write_file; 427 base::File output_write_file;
428 428
429 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); 429 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_));
430 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); 430 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file));
431 431
432 // Creating a native messaging host with a mock It2MeHostFactory.
433 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory());
434
435 pipe_.reset(new NativeMessagingPipe()); 432 pipe_.reset(new NativeMessagingPipe());
436 433
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
438 // Creating a native messaging host with a mock It2MeHostFactory.
441 scoped_ptr<extensions::NativeMessageHost> it2me_host( 439 scoped_ptr<extensions::NativeMessageHost> it2me_host(
442 new It2MeNativeMessagingHost( 440 new It2MeNativeMessagingHost(
443 host_task_runner_, 441 ChromotingHostContext::Create(host_task_runner_),
444 factory.Pass())); 442 make_scoped_ptr(new MockIt2MeHostFactory())));
445 it2me_host->Start(pipe_.get()); 443 it2me_host->Start(pipe_.get());
446 444
447 pipe_->Start(it2me_host.Pass(), 445 pipe_->Start(it2me_host.Pass(),
448 channel.Pass(), 446 channel.Pass(),
449 base::Bind(&It2MeNativeMessagingHostTest::StopHost, 447 base::Bind(&It2MeNativeMessagingHostTest::StopHost,
450 base::Unretained(this))); 448 base::Unretained(this)));
451 449
452 // Notify the test that the host has finished starting up. 450 // Notify the test that the host has finished starting up.
453 test_message_loop_->message_loop_proxy()->PostTask( 451 test_message_loop_->message_loop_proxy()->PostTask(
454 FROM_HERE, test_run_loop_->QuitClosure()); 452 FROM_HERE, test_run_loop_->QuitClosure());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 552
555 // Verify rejection if type is unrecognized. 553 // Verify rejection if type is unrecognized.
556 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { 554 TEST_F(It2MeNativeMessagingHostTest, InvalidType) {
557 base::DictionaryValue message; 555 base::DictionaryValue message;
558 message.SetString("type", "xxx"); 556 message.SetString("type", "xxx");
559 TestBadRequest(message, true); 557 TestBadRequest(message, true);
560 } 558 }
561 559
562 } // namespace remoting 560 } // namespace remoting
563 561
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host_main.cc ('k') | remoting/host/policy_hack/policy_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698