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

Side by Side Diff: remoting/host/chromoting_host_unittest.cc

Issue 6724033: Remove authenticated_ fields from stubs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove redundant comment. Created 9 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/client_session.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h"
5 #include "base/scoped_ptr.h" 6 #include "base/scoped_ptr.h"
6 #include "base/task.h" 7 #include "base/task.h"
7 #include "remoting/host/capturer_fake.h" 8 #include "remoting/host/capturer_fake.h"
8 #include "remoting/host/chromoting_host.h" 9 #include "remoting/host/chromoting_host.h"
9 #include "remoting/host/chromoting_host_context.h" 10 #include "remoting/host/chromoting_host_context.h"
10 #include "remoting/host/host_mock_objects.h" 11 #include "remoting/host/host_mock_objects.h"
11 #include "remoting/host/in_memory_host_config.h" 12 #include "remoting/host/in_memory_host_config.h"
13 #include "remoting/host/user_authenticator_fake.h"
12 #include "remoting/proto/video.pb.h" 14 #include "remoting/proto/video.pb.h"
13 #include "remoting/protocol/protocol_mock_objects.h" 15 #include "remoting/protocol/protocol_mock_objects.h"
14 #include "remoting/protocol/session_config.h" 16 #include "remoting/protocol/session_config.h"
15 #include "testing/gmock_mutant.h" 17 #include "testing/gmock_mutant.h"
16 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
19 using ::remoting::protocol::LocalLoginCredentials; 21 using ::remoting::protocol::LocalLoginCredentials;
20 using ::remoting::protocol::MockClientStub; 22 using ::remoting::protocol::MockClientStub;
21 using ::remoting::protocol::MockConnectionToClient; 23 using ::remoting::protocol::MockConnectionToClient;
(...skipping 12 matching lines...) Expand all
34 using testing::DoAll; 36 using testing::DoAll;
35 using testing::InSequence; 37 using testing::InSequence;
36 using testing::InvokeWithoutArgs; 38 using testing::InvokeWithoutArgs;
37 using testing::Return; 39 using testing::Return;
38 using testing::Sequence; 40 using testing::Sequence;
39 41
40 namespace remoting { 42 namespace remoting {
41 43
42 namespace { 44 namespace {
43 45
46 UserAuthenticator* MakeUserAuthenticator() {
47 return new UserAuthenticatorFake();
48 }
49
44 void PostQuitTask(MessageLoop* message_loop) { 50 void PostQuitTask(MessageLoop* message_loop) {
45 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 51 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
46 } 52 }
47 53
48 // Run the task and delete it afterwards. This action is used to deal with 54 // Run the task and delete it afterwards. This action is used to deal with
49 // done callbacks. 55 // done callbacks.
50 ACTION(RunDoneTask) { 56 ACTION(RunDoneTask) {
51 arg1->Run(); 57 arg1->Run();
52 delete arg1; 58 delete arg1;
53 } 59 }
54 60
55 ACTION_P(QuitMainMessageLoop, message_loop) { 61 ACTION_P(QuitMainMessageLoop, message_loop) {
56 PostQuitTask(message_loop); 62 PostQuitTask(message_loop);
57 } 63 }
58 64
65 void DummyFunction() {}
Jamie 2011/03/31 11:31:25 Can we rename this |DummyDoneTask| or something th
simonmorris 2011/03/31 12:23:43 Done.
66
59 } // namespace 67 } // namespace
60 68
61 class ChromotingHostTest : public testing::Test { 69 class ChromotingHostTest : public testing::Test {
62 public: 70 public:
63 ChromotingHostTest() { 71 ChromotingHostTest() {
64 } 72 }
65 73
66 virtual void SetUp() { 74 virtual void SetUp() {
67 config_ = new InMemoryHostConfig(); 75 config_ = new InMemoryHostConfig();
68 ON_CALL(context_, main_message_loop()) 76 ON_CALL(context_, main_message_loop())
(...skipping 11 matching lines...) Expand all
80 88
81 Capturer* capturer = new CapturerFake(); 89 Capturer* capturer = new CapturerFake();
82 host_stub_ = new MockHostStub(); 90 host_stub_ = new MockHostStub();
83 host_stub2_ = new MockHostStub(); 91 host_stub2_ = new MockHostStub();
84 input_stub_ = new MockInputStub(); 92 input_stub_ = new MockInputStub();
85 input_stub2_ = new MockInputStub(); 93 input_stub2_ = new MockInputStub();
86 curtain_ = new MockCurtain(); 94 curtain_ = new MockCurtain();
87 DesktopEnvironment* desktop = 95 DesktopEnvironment* desktop =
88 new DesktopEnvironment(capturer, input_stub_, curtain_); 96 new DesktopEnvironment(capturer, input_stub_, curtain_);
89 host_ = ChromotingHost::Create(&context_, config_, desktop); 97 host_ = ChromotingHost::Create(&context_, config_, desktop);
98 credentials_good_.set_type(protocol::PASSWORD);
99 credentials_good_.set_username("user");
100 credentials_good_.set_credential("password");
101 credentials_bad_.set_type(protocol::PASSWORD);
102 credentials_bad_.set_username(UserAuthenticatorFake::fail_username());
103 credentials_bad_.set_credential(UserAuthenticatorFake::fail_password());
90 connection_ = new MockConnectionToClient( 104 connection_ = new MockConnectionToClient(
91 &message_loop_, &handler_, host_stub_, input_stub_); 105 &message_loop_, &handler_, host_stub_, input_stub_);
92 connection2_ = new MockConnectionToClient( 106 connection2_ = new MockConnectionToClient(
93 &message_loop_, &handler_, host_stub2_, input_stub2_); 107 &message_loop_, &handler_, host_stub2_, input_stub2_);
94 session_ = new MockSession(); 108 session_ = new MockSession();
95 session2_ = new MockSession(); 109 session2_ = new MockSession();
96 session_config_.reset(SessionConfig::CreateDefault()); 110 session_config_.reset(SessionConfig::CreateDefault());
97 session_config2_.reset(SessionConfig::CreateDefault()); 111 session_config2_.reset(SessionConfig::CreateDefault());
98 112
99 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) 113 ON_CALL(video_stub_, ProcessVideoPacket(_, _))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 .Times(AnyNumber()); 150 .Times(AnyNumber());
137 } 151 }
138 152
139 virtual void TearDown() { 153 virtual void TearDown() {
140 } 154 }
141 155
142 // Helper method to pretend a client is connected to ChromotingHost. 156 // Helper method to pretend a client is connected to ChromotingHost.
143 void SimulateClientConnection(int connection_index, bool authenticate) { 157 void SimulateClientConnection(int connection_index, bool authenticate) {
144 scoped_refptr<MockConnectionToClient> connection = 158 scoped_refptr<MockConnectionToClient> connection =
145 (connection_index == 0) ? connection_ : connection2_; 159 (connection_index == 0) ? connection_ : connection2_;
146 scoped_refptr<ClientSession> client = new ClientSession(host_.get(), 160 protocol::LocalLoginCredentials& credentials =
147 connection); 161 authenticate ? credentials_good_ : credentials_bad_;
162 scoped_refptr<ClientSession> client = new ClientSession(
163 host_.get(),
164 base::Bind(MakeUserAuthenticator),
165 connection,
166 input_stub_);
148 connection->set_host_stub(client.get()); 167 connection->set_host_stub(client.get());
149 168
150 context_.network_message_loop()->PostTask( 169 context_.network_message_loop()->PostTask(
151 FROM_HERE, 170 FROM_HERE,
152 NewRunnableMethod(host_.get(), 171 NewRunnableMethod(host_.get(),
153 &ChromotingHost::AddClient, 172 &ChromotingHost::AddClient,
154 client)); 173 client));
155 context_.network_message_loop()->PostTask( 174 context_.network_message_loop()->PostTask(
156 FROM_HERE, 175 FROM_HERE,
157 NewRunnableMethod(host_.get(), 176 NewRunnableMethod(host_.get(),
158 &ChromotingHost::OnClientConnected, 177 &ChromotingHost::OnClientConnected,
159 connection)); 178 connection));
160 if (authenticate) { 179 context_.network_message_loop()->PostTask(
161 context_.network_message_loop()->PostTask( 180 FROM_HERE,
162 FROM_HERE, 181 NewRunnableMethod(client.get(),
163 NewRunnableMethod(host_.get(), 182 &ClientSession::BeginSessionRequest,
164 &ChromotingHost::LocalLoginSucceeded, 183 &credentials,
165 connection)); 184 NewRunnableFunction(&DummyFunction)));
166 } else {
167 context_.network_message_loop()->PostTask(
168 FROM_HERE,
169 NewRunnableMethod(host_.get(),
170 &ChromotingHost::LocalLoginFailed,
171 connection));
172 }
173 } 185 }
174 186
175 // Helper method to remove a client connection from ChromotingHost. 187 // Helper method to remove a client connection from ChromotingHost.
176 void RemoveClientConnection() { 188 void RemoveClientConnection() {
177 context_.network_message_loop()->PostTask( 189 context_.network_message_loop()->PostTask(
178 FROM_HERE, 190 FROM_HERE,
179 NewRunnableMethod(host_.get(), 191 NewRunnableMethod(host_.get(),
180 &ChromotingHost::OnClientDisconnected, 192 &ChromotingHost::OnClientDisconnected,
181 connection_)); 193 connection_));
182 } 194 }
183 195
184 protected: 196 protected:
185 MessageLoop message_loop_; 197 MessageLoop message_loop_;
186 MockConnectionToClientEventHandler handler_; 198 MockConnectionToClientEventHandler handler_;
187 scoped_refptr<ChromotingHost> host_; 199 scoped_refptr<ChromotingHost> host_;
188 scoped_refptr<InMemoryHostConfig> config_; 200 scoped_refptr<InMemoryHostConfig> config_;
189 MockChromotingHostContext context_; 201 MockChromotingHostContext context_;
202 protocol::LocalLoginCredentials credentials_good_;
203 protocol::LocalLoginCredentials credentials_bad_;
190 scoped_refptr<MockConnectionToClient> connection_; 204 scoped_refptr<MockConnectionToClient> connection_;
191 scoped_refptr<MockSession> session_; 205 scoped_refptr<MockSession> session_;
192 scoped_ptr<SessionConfig> session_config_; 206 scoped_ptr<SessionConfig> session_config_;
193 MockVideoStub video_stub_; 207 MockVideoStub video_stub_;
194 MockClientStub client_stub_; 208 MockClientStub client_stub_;
195 MockHostStub* host_stub_; 209 MockHostStub* host_stub_;
196 MockInputStub* input_stub_; 210 MockInputStub* input_stub_;
197 MockCurtain* curtain_; 211 MockCurtain* curtain_;
198 scoped_refptr<MockConnectionToClient> connection2_; 212 scoped_refptr<MockConnectionToClient> connection2_;
199 scoped_refptr<MockSession> session2_; 213 scoped_refptr<MockSession> session2_;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 .Times(AnyNumber()); 408 .Times(AnyNumber());
395 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _)) 409 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _))
396 .Times(0); 410 .Times(0);
397 } 411 }
398 412
399 SimulateClientConnection(0, true); 413 SimulateClientConnection(0, true);
400 message_loop_.Run(); 414 message_loop_.Run();
401 } 415 }
402 416
403 } // namespace remoting 417 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/client_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698