OLD | NEW |
---|---|
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/task.h" | 6 #include "base/task.h" |
6 #include "remoting/host/capturer_fake.h" | 7 #include "remoting/host/capturer_fake.h" |
7 #include "remoting/host/chromoting_host.h" | 8 #include "remoting/host/chromoting_host.h" |
8 #include "remoting/host/chromoting_host_context.h" | 9 #include "remoting/host/chromoting_host_context.h" |
9 #include "remoting/host/host_mock_objects.h" | 10 #include "remoting/host/host_mock_objects.h" |
10 #include "remoting/host/in_memory_host_config.h" | 11 #include "remoting/host/in_memory_host_config.h" |
12 #include "remoting/host/user_authenticator_fake.h" | |
11 #include "remoting/proto/video.pb.h" | 13 #include "remoting/proto/video.pb.h" |
12 #include "remoting/protocol/protocol_mock_objects.h" | 14 #include "remoting/protocol/protocol_mock_objects.h" |
13 #include "remoting/protocol/session_config.h" | 15 #include "remoting/protocol/session_config.h" |
14 #include "testing/gmock_mutant.h" | 16 #include "testing/gmock_mutant.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 | 19 |
18 using ::remoting::protocol::LocalLoginCredentials; | 20 using ::remoting::protocol::LocalLoginCredentials; |
19 using ::remoting::protocol::MockClientStub; | 21 using ::remoting::protocol::MockClientStub; |
20 using ::remoting::protocol::MockConnectionToClient; | 22 using ::remoting::protocol::MockConnectionToClient; |
(...skipping 10 matching lines...) Expand all Loading... | |
31 using testing::DeleteArg; | 33 using testing::DeleteArg; |
32 using testing::DoAll; | 34 using testing::DoAll; |
33 using testing::InSequence; | 35 using testing::InSequence; |
34 using testing::InvokeWithoutArgs; | 36 using testing::InvokeWithoutArgs; |
35 using testing::Return; | 37 using testing::Return; |
36 | 38 |
37 namespace remoting { | 39 namespace remoting { |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
43 UserAuthenticator* MakeUserAuthenticator() { | |
44 return new UserAuthenticatorFake(); | |
45 } | |
46 | |
41 void PostQuitTask(MessageLoop* message_loop) { | 47 void PostQuitTask(MessageLoop* message_loop) { |
42 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 48 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
43 } | 49 } |
44 | 50 |
45 // Run the task and delete it afterwards. This action is used to deal with | 51 // Run the task and delete it afterwards. This action is used to deal with |
46 // done callbacks. | 52 // done callbacks. |
47 ACTION(RunDoneTask) { | 53 ACTION(RunDoneTask) { |
48 arg1->Run(); | 54 arg1->Run(); |
49 delete arg1; | 55 delete arg1; |
50 } | 56 } |
51 | 57 |
52 ACTION_P(QuitMainMessageLoop, message_loop) { | 58 ACTION_P(QuitMainMessageLoop, message_loop) { |
53 PostQuitTask(message_loop); | 59 PostQuitTask(message_loop); |
54 } | 60 } |
55 | 61 |
62 // A task that does nothing. | |
63 class DummyTask : public Task { | |
Alpha Left Google
2011/03/28 16:22:26
Alternatively you can also do:
void DummyTask() {
simonmorris
2011/03/29 17:07:51
Done.
| |
64 public: | |
65 void Run() {} | |
66 }; | |
67 | |
56 } // namespace | 68 } // namespace |
57 | 69 |
58 class ChromotingHostTest : public testing::Test { | 70 class ChromotingHostTest : public testing::Test { |
59 public: | 71 public: |
60 ChromotingHostTest() { | 72 ChromotingHostTest() { |
61 } | 73 } |
62 | 74 |
63 virtual void SetUp() { | 75 virtual void SetUp() { |
64 config_ = new InMemoryHostConfig(); | 76 config_ = new InMemoryHostConfig(); |
65 ON_CALL(context_, main_message_loop()) | 77 ON_CALL(context_, main_message_loop()) |
(...skipping 10 matching lines...) Expand all Loading... | |
76 .Times(AnyNumber()); | 88 .Times(AnyNumber()); |
77 | 89 |
78 Capturer* capturer = new CapturerFake(context_.main_message_loop()); | 90 Capturer* capturer = new CapturerFake(context_.main_message_loop()); |
79 host_stub_ = new MockHostStub(); | 91 host_stub_ = new MockHostStub(); |
80 host_stub2_ = new MockHostStub(); | 92 host_stub2_ = new MockHostStub(); |
81 input_stub_ = new MockInputStub(); | 93 input_stub_ = new MockInputStub(); |
82 input_stub2_ = new MockInputStub(); | 94 input_stub2_ = new MockInputStub(); |
83 DesktopEnvironment* desktop = | 95 DesktopEnvironment* desktop = |
84 new DesktopEnvironment(capturer, input_stub_); | 96 new DesktopEnvironment(capturer, input_stub_); |
85 host_ = ChromotingHost::Create(&context_, config_, desktop); | 97 host_ = ChromotingHost::Create(&context_, config_, desktop); |
98 credentials_.set_type(protocol::PASSWORD); | |
99 credentials_.set_username("user"); | |
100 credentials_.set_credential("password"); | |
86 connection_ = new MockConnectionToClient( | 101 connection_ = new MockConnectionToClient( |
87 &message_loop_, &handler_, host_stub_, input_stub_); | 102 &message_loop_, &handler_, host_stub_, input_stub_); |
88 connection2_ = new MockConnectionToClient( | 103 connection2_ = new MockConnectionToClient( |
89 &message_loop_, &handler_, host_stub2_, input_stub2_); | 104 &message_loop_, &handler_, host_stub2_, input_stub2_); |
90 session_ = new MockSession(); | 105 session_ = new MockSession(); |
91 session2_ = new MockSession(); | 106 session2_ = new MockSession(); |
92 session_config_.reset(SessionConfig::CreateDefault()); | 107 session_config_.reset(SessionConfig::CreateDefault()); |
93 session_config2_.reset(SessionConfig::CreateDefault()); | 108 session_config2_.reset(SessionConfig::CreateDefault()); |
94 | 109 |
95 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) | 110 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 | 148 |
134 } | 149 } |
135 | 150 |
136 virtual void TearDown() { | 151 virtual void TearDown() { |
137 } | 152 } |
138 | 153 |
139 // Helper method to pretend a client is connected to ChromotingHost. | 154 // Helper method to pretend a client is connected to ChromotingHost. |
140 void SimulateClientConnection(int connection_index) { | 155 void SimulateClientConnection(int connection_index) { |
141 scoped_refptr<MockConnectionToClient> connection = | 156 scoped_refptr<MockConnectionToClient> connection = |
142 (connection_index == 0) ? connection_ : connection2_; | 157 (connection_index == 0) ? connection_ : connection2_; |
143 scoped_refptr<ClientSession> client = new ClientSession(host_.get(), | 158 scoped_refptr<ClientSession> client = new ClientSession( |
144 connection); | 159 host_.get(), |
160 base::Bind(MakeUserAuthenticator), | |
161 connection, | |
162 input_stub_); | |
145 connection->set_host_stub(client.get()); | 163 connection->set_host_stub(client.get()); |
146 | 164 |
147 context_.network_message_loop()->PostTask( | 165 context_.network_message_loop()->PostTask( |
148 FROM_HERE, | 166 FROM_HERE, |
149 NewRunnableMethod(host_.get(), | 167 NewRunnableMethod(host_.get(), |
150 &ChromotingHost::AddClient, | 168 &ChromotingHost::AddClient, |
151 client)); | 169 client)); |
152 context_.network_message_loop()->PostTask( | 170 context_.network_message_loop()->PostTask( |
153 FROM_HERE, | 171 FROM_HERE, |
154 NewRunnableMethod(host_.get(), | 172 NewRunnableMethod(host_.get(), |
155 &ChromotingHost::OnClientConnected, | 173 &ChromotingHost::OnClientConnected, |
156 connection)); | 174 connection)); |
157 context_.network_message_loop()->PostTask( | 175 context_.network_message_loop()->PostTask( |
158 FROM_HERE, | 176 FROM_HERE, |
159 NewRunnableMethod(host_.get(), | 177 NewRunnableMethod(client.get(), |
160 &ChromotingHost::LocalLoginSucceeded, | 178 &ClientSession::BeginSessionRequest, |
161 connection)); | 179 &credentials_, |
180 new DummyTask())); | |
162 } | 181 } |
163 | 182 |
164 // Helper method to remove a client connection from ChromotingHost. | 183 // Helper method to remove a client connection from ChromotingHost. |
165 void RemoveClientConnection() { | 184 void RemoveClientConnection() { |
166 context_.network_message_loop()->PostTask( | 185 context_.network_message_loop()->PostTask( |
167 FROM_HERE, | 186 FROM_HERE, |
168 NewRunnableMethod(host_.get(), | 187 NewRunnableMethod(host_.get(), |
169 &ChromotingHost::OnClientDisconnected, | 188 &ChromotingHost::OnClientDisconnected, |
170 connection_)); | 189 connection_)); |
171 } | 190 } |
172 | 191 |
173 protected: | 192 protected: |
174 MessageLoop message_loop_; | 193 MessageLoop message_loop_; |
175 MockConnectionToClientEventHandler handler_; | 194 MockConnectionToClientEventHandler handler_; |
176 scoped_refptr<ChromotingHost> host_; | 195 scoped_refptr<ChromotingHost> host_; |
177 scoped_refptr<InMemoryHostConfig> config_; | 196 scoped_refptr<InMemoryHostConfig> config_; |
178 MockChromotingHostContext context_; | 197 MockChromotingHostContext context_; |
198 protocol::LocalLoginCredentials credentials_; | |
179 scoped_refptr<MockConnectionToClient> connection_; | 199 scoped_refptr<MockConnectionToClient> connection_; |
180 scoped_refptr<MockSession> session_; | 200 scoped_refptr<MockSession> session_; |
181 scoped_ptr<SessionConfig> session_config_; | 201 scoped_ptr<SessionConfig> session_config_; |
182 MockVideoStub video_stub_; | 202 MockVideoStub video_stub_; |
183 MockClientStub client_stub_; | 203 MockClientStub client_stub_; |
184 MockHostStub* host_stub_; | 204 MockHostStub* host_stub_; |
185 MockInputStub* input_stub_; | 205 MockInputStub* input_stub_; |
186 scoped_refptr<MockConnectionToClient> connection2_; | 206 scoped_refptr<MockConnectionToClient> connection2_; |
187 scoped_refptr<MockSession> session2_; | 207 scoped_refptr<MockSession> session2_; |
188 scoped_ptr<SessionConfig> session_config2_; | 208 scoped_ptr<SessionConfig> session_config2_; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 EXPECT_CALL(*connection_.get(), Disconnect()) | 327 EXPECT_CALL(*connection_.get(), Disconnect()) |
308 .RetiresOnSaturation(); | 328 .RetiresOnSaturation(); |
309 EXPECT_CALL(*connection2_.get(), Disconnect()) | 329 EXPECT_CALL(*connection2_.get(), Disconnect()) |
310 .RetiresOnSaturation(); | 330 .RetiresOnSaturation(); |
311 | 331 |
312 SimulateClientConnection(0); | 332 SimulateClientConnection(0); |
313 message_loop_.Run(); | 333 message_loop_.Run(); |
314 } | 334 } |
315 | 335 |
316 } // namespace remoting | 336 } // namespace remoting |
OLD | NEW |