OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_host.h" | 5 #include "remoting/host/it2me/it2me_host.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/callback_helpers.h" |
13 #include "base/location.h" | 14 #include "base/location.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/weak_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
18 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
20 #include "components/policy/policy_constants.h" | 22 #include "components/policy/policy_constants.h" |
21 #include "remoting/base/auto_thread_task_runner.h" | 23 #include "remoting/base/auto_thread_task_runner.h" |
22 #include "remoting/host/chromoting_host_context.h" | 24 #include "remoting/host/chromoting_host_context.h" |
23 #include "remoting/host/it2me/it2me_confirmation_dialog.h" | 25 #include "remoting/host/it2me/it2me_confirmation_dialog.h" |
24 #include "remoting/host/policy_watcher.h" | 26 #include "remoting/host/policy_watcher.h" |
25 #include "remoting/signaling/fake_signal_strategy.h" | 27 #include "remoting/signaling/fake_signal_strategy.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 FakeIt2MeConfirmationDialog::~FakeIt2MeConfirmationDialog() {} | 74 FakeIt2MeConfirmationDialog::~FakeIt2MeConfirmationDialog() {} |
73 | 75 |
74 void FakeIt2MeConfirmationDialog::Show(const std::string& remote_user_email, | 76 void FakeIt2MeConfirmationDialog::Show(const std::string& remote_user_email, |
75 const ResultCallback& callback) { | 77 const ResultCallback& callback) { |
76 remote_user_email_ = remote_user_email; | 78 remote_user_email_ = remote_user_email; |
77 | 79 |
78 base::ThreadTaskRunnerHandle::Get()->PostTask( | 80 base::ThreadTaskRunnerHandle::Get()->PostTask( |
79 FROM_HERE, base::Bind(callback, dialog_result_)); | 81 FROM_HERE, base::Bind(callback, dialog_result_)); |
80 } | 82 } |
81 | 83 |
82 class It2MeHostTest : public testing::Test { | 84 class It2MeHostTest : public testing::Test, public It2MeHost::Observer { |
83 public: | 85 public: |
84 It2MeHostTest() {} | 86 It2MeHostTest(); |
85 ~It2MeHostTest() override {} | 87 ~It2MeHostTest() override; |
86 | 88 |
87 // testing::Test interface. | 89 // testing::Test interface. |
88 void SetUp() override; | 90 void SetUp() override; |
89 void TearDown() override; | 91 void TearDown() override; |
90 | 92 |
91 void OnValidationComplete(const base::Closure& resume_callback, | 93 void OnValidationComplete(const base::Closure& resume_callback, |
92 ValidationResult validation_result); | 94 ValidationResult validation_result); |
93 | 95 |
94 protected: | 96 protected: |
| 97 // It2MeHost::Observer interface. |
| 98 void OnClientAuthenticated(const std::string& client_username) override; |
| 99 void OnStoreAccessCode(const std::string& access_code, |
| 100 base::TimeDelta access_code_lifetime) override; |
| 101 void OnNatPolicyChanged(bool nat_traversal_enabled) override; |
| 102 void OnStateChanged(It2MeHostState state, |
| 103 const std::string& error_message) override; |
| 104 |
95 void SetClientDomainPolicy(const std::string& policy_value); | 105 void SetClientDomainPolicy(const std::string& policy_value); |
96 | 106 |
| 107 void RunUntilStateChanged(It2MeHostState expected_state); |
| 108 |
| 109 void SimulateHostConnected(); |
| 110 |
97 void RunValidationCallback(const std::string& remote_jid); | 111 void RunValidationCallback(const std::string& remote_jid); |
98 | 112 |
| 113 void DisconnectFromHost(); |
| 114 |
99 ValidationResult validation_result_ = ValidationResult::SUCCESS; | 115 ValidationResult validation_result_ = ValidationResult::SUCCESS; |
100 std::string remote_user_email_; | 116 std::string remote_user_email_; |
101 | 117 |
| 118 base::Closure state_change_callback_; |
| 119 |
| 120 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected; |
| 121 |
102 // Used to set ConfirmationDialog behavior. | 122 // Used to set ConfirmationDialog behavior. |
103 FakeIt2MeConfirmationDialog* dialog_ = nullptr; | 123 FakeIt2MeConfirmationDialog* dialog_ = nullptr; |
104 | 124 |
105 private: | 125 private: |
106 std::unique_ptr<base::MessageLoop> message_loop_; | 126 std::unique_ptr<base::MessageLoop> message_loop_; |
107 std::unique_ptr<base::RunLoop> run_loop_; | 127 std::unique_ptr<base::RunLoop> run_loop_; |
108 | 128 |
109 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | 129 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
110 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 130 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
111 | 131 |
112 scoped_refptr<It2MeHost> it2me_host_; | 132 scoped_refptr<It2MeHost> it2me_host_; |
113 | 133 |
| 134 base::WeakPtrFactory<It2MeHostTest> weak_factory_; |
| 135 |
114 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); | 136 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); |
115 }; | 137 }; |
116 | 138 |
| 139 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {} |
| 140 |
| 141 It2MeHostTest::~It2MeHostTest() {} |
| 142 |
117 void It2MeHostTest::SetUp() { | 143 void It2MeHostTest::SetUp() { |
118 message_loop_.reset(new base::MessageLoop()); | 144 message_loop_.reset(new base::MessageLoop()); |
119 run_loop_.reset(new base::RunLoop()); | 145 run_loop_.reset(new base::RunLoop()); |
120 | 146 |
121 std::unique_ptr<ChromotingHostContext> host_context( | 147 std::unique_ptr<ChromotingHostContext> host_context( |
122 ChromotingHostContext::Create(new AutoThreadTaskRunner( | 148 ChromotingHostContext::Create(new AutoThreadTaskRunner( |
123 base::ThreadTaskRunnerHandle::Get(), run_loop_->QuitClosure()))); | 149 base::ThreadTaskRunnerHandle::Get(), run_loop_->QuitClosure()))); |
124 network_task_runner_ = host_context->network_task_runner(); | 150 network_task_runner_ = host_context->network_task_runner(); |
125 ui_task_runner_ = host_context->ui_task_runner(); | 151 ui_task_runner_ = host_context->ui_task_runner(); |
126 | 152 |
127 dialog_ = new FakeIt2MeConfirmationDialog(); | 153 dialog_ = new FakeIt2MeConfirmationDialog(); |
128 it2me_host_ = | 154 it2me_host_ = |
129 new It2MeHost(std::move(host_context), | 155 new It2MeHost(std::move(host_context), |
130 /*policy_watcher=*/nullptr, base::WrapUnique(dialog_), | 156 /*policy_watcher=*/nullptr, base::WrapUnique(dialog_), |
131 /*observer=*/nullptr, | 157 weak_factory_.GetWeakPtr(), |
132 base::WrapUnique(new FakeSignalStrategy("fake_local_jid")), | 158 base::WrapUnique(new FakeSignalStrategy("fake_local_jid")), |
133 "fake_user_name", "fake_bot_jid"); | 159 "fake_user_name", "fake_bot_jid"); |
134 } | 160 } |
135 | 161 |
136 void It2MeHostTest::TearDown() { | 162 void It2MeHostTest::TearDown() { |
137 network_task_runner_ = nullptr; | 163 network_task_runner_ = nullptr; |
138 ui_task_runner_ = nullptr; | 164 ui_task_runner_ = nullptr; |
139 it2me_host_ = nullptr; | 165 it2me_host_ = nullptr; |
140 run_loop_->Run(); | 166 run_loop_->Run(); |
141 } | 167 } |
142 | 168 |
143 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, | 169 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, |
144 ValidationResult validation_result) { | 170 ValidationResult validation_result) { |
145 validation_result_ = validation_result; | 171 validation_result_ = validation_result; |
146 remote_user_email_ = dialog_->get_remote_user_email(); | 172 remote_user_email_ = dialog_->get_remote_user_email(); |
147 | 173 |
148 ui_task_runner_->PostTask(FROM_HERE, resume_callback); | 174 ui_task_runner_->PostTask(FROM_HERE, resume_callback); |
149 } | 175 } |
150 | 176 |
151 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) { | 177 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) { |
152 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue()); | 178 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue()); |
153 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value); | 179 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value); |
154 | 180 |
155 base::RunLoop run_loop; | 181 base::RunLoop run_loop; |
156 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure()); | 182 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure()); |
157 run_loop.Run(); | 183 run_loop.Run(); |
158 } | 184 } |
159 | 185 |
160 void It2MeHostTest::RunValidationCallback(const std::string& remote_jid) { | 186 void It2MeHostTest::RunUntilStateChanged(It2MeHostState expected_state) { |
| 187 if (last_host_state_ == expected_state) { |
| 188 // Bail out early if the state is already correct. |
| 189 return; |
| 190 } |
| 191 |
161 base::RunLoop run_loop; | 192 base::RunLoop run_loop; |
| 193 state_change_callback_ = run_loop.QuitClosure(); |
| 194 run_loop.Run(); |
| 195 } |
162 | 196 |
| 197 void It2MeHostTest::SimulateHostConnected() { |
163 network_task_runner_->PostTask( | 198 network_task_runner_->PostTask( |
164 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(), | 199 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(), |
165 It2MeHostState::kStarting, std::string())); | 200 It2MeHostState::kStarting, std::string())); |
166 | 201 |
167 network_task_runner_->PostTask( | 202 network_task_runner_->PostTask( |
168 FROM_HERE, | 203 FROM_HERE, |
169 base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(), | 204 base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(), |
170 It2MeHostState::kRequestedAccessCode, std::string())); | 205 It2MeHostState::kRequestedAccessCode, std::string())); |
171 | 206 |
172 network_task_runner_->PostTask( | 207 network_task_runner_->PostTask( |
173 FROM_HERE, | 208 FROM_HERE, |
174 base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(), | 209 base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(), |
175 It2MeHostState::kReceivedAccessCode, std::string())); | 210 It2MeHostState::kReceivedAccessCode, std::string())); |
| 211 } |
| 212 |
| 213 void It2MeHostTest::RunValidationCallback(const std::string& remote_jid) { |
| 214 base::RunLoop run_loop; |
176 | 215 |
177 network_task_runner_->PostTask( | 216 network_task_runner_->PostTask( |
178 FROM_HERE, | 217 FROM_HERE, |
179 base::Bind(it2me_host_->GetValidationCallbackForTesting(), remote_jid, | 218 base::Bind(it2me_host_->GetValidationCallbackForTesting(), remote_jid, |
180 base::Bind(&It2MeHostTest::OnValidationComplete, | 219 base::Bind(&It2MeHostTest::OnValidationComplete, |
181 base::Unretained(this), run_loop.QuitClosure()))); | 220 base::Unretained(this), run_loop.QuitClosure()))); |
182 | 221 |
183 run_loop.Run(); | 222 run_loop.Run(); |
| 223 } |
184 | 224 |
185 it2me_host_->Disconnect(); | 225 void It2MeHostTest::OnClientAuthenticated(const std::string& client_username) {} |
| 226 |
| 227 void It2MeHostTest::OnStoreAccessCode(const std::string& access_code, |
| 228 base::TimeDelta access_code_lifetime) {} |
| 229 |
| 230 void It2MeHostTest::OnNatPolicyChanged(bool nat_traversal_enabled) {} |
| 231 |
| 232 void It2MeHostTest::OnStateChanged(It2MeHostState state, |
| 233 const std::string& error_message) { |
| 234 last_host_state_ = state; |
| 235 |
| 236 if (state_change_callback_) { |
| 237 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 238 FROM_HERE, base::ResetAndReturn(&state_change_callback_)); |
| 239 } |
| 240 } |
| 241 |
| 242 void It2MeHostTest::DisconnectFromHost() { |
| 243 if (it2me_host_) { |
| 244 it2me_host_->Disconnect(); |
| 245 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 246 } |
186 } | 247 } |
187 | 248 |
188 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ValidJid) { | 249 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ValidJid) { |
| 250 SimulateHostConnected(); |
189 RunValidationCallback(kTestClientJid); | 251 RunValidationCallback(kTestClientJid); |
190 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 252 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 253 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 254 DisconnectFromHost(); |
| 255 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
191 } | 256 } |
192 | 257 |
193 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_InvalidJid) { | 258 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_InvalidJid) { |
| 259 SimulateHostConnected(); |
194 RunValidationCallback(kTestClientUsernameNoJid); | 260 RunValidationCallback(kTestClientUsernameNoJid); |
195 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 261 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 262 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 263 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
196 } | 264 } |
197 | 265 |
198 TEST_F(It2MeHostTest, | 266 TEST_F(It2MeHostTest, |
199 ConnectionValidation_NoClientDomainPolicy_InvalidUsername) { | 267 ConnectionValidation_NoClientDomainPolicy_InvalidUsername) { |
| 268 SimulateHostConnected(); |
200 RunValidationCallback(kTestClientJidWithSlash); | 269 RunValidationCallback(kTestClientJidWithSlash); |
201 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 270 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 271 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 272 DisconnectFromHost(); |
| 273 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
202 } | 274 } |
203 | 275 |
204 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ResourceOnly) { | 276 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ResourceOnly) { |
| 277 SimulateHostConnected(); |
205 RunValidationCallback(kResourceOnly); | 278 RunValidationCallback(kResourceOnly); |
206 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 279 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 280 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 281 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
207 } | 282 } |
208 | 283 |
209 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_MatchingDomain) { | 284 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_MatchingDomain) { |
210 SetClientDomainPolicy(kMatchingDomain); | 285 SetClientDomainPolicy(kMatchingDomain); |
| 286 SimulateHostConnected(); |
211 RunValidationCallback(kTestClientJid); | 287 RunValidationCallback(kTestClientJid); |
212 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 288 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 289 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 290 DisconnectFromHost(); |
| 291 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
213 } | 292 } |
214 | 293 |
215 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_InvalidUserName) { | 294 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_InvalidUserName) { |
216 SetClientDomainPolicy(kMatchingDomain); | 295 SetClientDomainPolicy(kMatchingDomain); |
| 296 SimulateHostConnected(); |
217 RunValidationCallback(kTestClientJidWithSlash); | 297 RunValidationCallback(kTestClientJidWithSlash); |
218 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 298 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 299 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 300 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
219 } | 301 } |
220 | 302 |
221 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_NoJid) { | 303 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_NoJid) { |
222 SetClientDomainPolicy(kMatchingDomain); | 304 SetClientDomainPolicy(kMatchingDomain); |
| 305 SimulateHostConnected(); |
223 RunValidationCallback(kTestClientUsernameNoJid); | 306 RunValidationCallback(kTestClientUsernameNoJid); |
| 307 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 308 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
224 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 309 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
225 } | 310 } |
226 | 311 |
227 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_NoMatch) { | 312 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_NoMatch) { |
228 SetClientDomainPolicy(kMismatchedDomain3); | 313 SetClientDomainPolicy(kMismatchedDomain3); |
| 314 SimulateHostConnected(); |
229 RunValidationCallback(kTestClientJid); | 315 RunValidationCallback(kTestClientJid); |
230 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 316 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 317 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 318 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
231 } | 319 } |
232 | 320 |
233 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchStart) { | 321 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchStart) { |
234 SetClientDomainPolicy(kMismatchedDomain2); | 322 SetClientDomainPolicy(kMismatchedDomain2); |
| 323 SimulateHostConnected(); |
235 RunValidationCallback(kTestClientJid); | 324 RunValidationCallback(kTestClientJid); |
236 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 325 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 326 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 327 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
237 } | 328 } |
238 | 329 |
239 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) { | 330 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) { |
240 SetClientDomainPolicy(kMismatchedDomain1); | 331 SetClientDomainPolicy(kMismatchedDomain1); |
| 332 SimulateHostConnected(); |
241 RunValidationCallback(kTestClientJid); | 333 RunValidationCallback(kTestClientJid); |
242 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 334 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 335 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 336 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
243 } | 337 } |
244 | 338 |
245 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { | 339 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { |
| 340 SimulateHostConnected(); |
246 RunValidationCallback(kTestClientJid); | 341 RunValidationCallback(kTestClientJid); |
247 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 342 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
248 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str()); | 343 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str()); |
| 344 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 345 DisconnectFromHost(); |
| 346 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
249 } | 347 } |
250 | 348 |
251 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { | 349 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { |
252 dialog_->set_dialog_result(DialogResult::CANCEL); | 350 dialog_->set_dialog_result(DialogResult::CANCEL); |
| 351 SimulateHostConnected(); |
253 RunValidationCallback(kTestClientJid); | 352 RunValidationCallback(kTestClientJid); |
254 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); | 353 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); |
| 354 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 355 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
255 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str()); | 356 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str()); |
256 } | 357 } |
257 | 358 |
| 359 TEST_F(It2MeHostTest, MultipleConnectionsTriggerDisconnect) { |
| 360 SimulateHostConnected(); |
| 361 RunValidationCallback(kTestClientJid); |
| 362 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 363 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 364 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str()); |
| 365 RunValidationCallback(kTestClientJid); |
| 366 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_); |
| 367 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 368 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 369 } |
| 370 |
258 } // namespace remoting | 371 } // namespace remoting |
OLD | NEW |