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

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

Issue 2650443002: Webapp share dialog is not closed when client end of the connection is closed (Closed)
Patch Set: Merging changes from dependent CL Created 3 years, 9 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
« no previous file with comments | « remoting/host/it2me/it2me_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const char kResourceOnly[] = "/jid_resource"; 43 const char kResourceOnly[] = "/jid_resource";
44 const char kMatchingDomain[] = "gmail.com"; 44 const char kMatchingDomain[] = "gmail.com";
45 const char kMismatchedDomain1[] = "similar_to_gmail.com"; 45 const char kMismatchedDomain1[] = "similar_to_gmail.com";
46 const char kMismatchedDomain2[] = "gmail_at_the_beginning.com"; 46 const char kMismatchedDomain2[] = "gmail_at_the_beginning.com";
47 const char kMismatchedDomain3[] = "not_even_close.com"; 47 const char kMismatchedDomain3[] = "not_even_close.com";
48 48
49 } // namespace 49 } // namespace
50 50
51 class FakeIt2MeConfirmationDialog : public It2MeConfirmationDialog { 51 class FakeIt2MeConfirmationDialog : public It2MeConfirmationDialog {
52 public: 52 public:
53 FakeIt2MeConfirmationDialog(); 53 FakeIt2MeConfirmationDialog(const std::string& remote_user_email,
54 DialogResult dialog_result);
54 ~FakeIt2MeConfirmationDialog() override; 55 ~FakeIt2MeConfirmationDialog() override;
55 56
56 // It2MeConfirmationDialog implementation. 57 // It2MeConfirmationDialog implementation.
57 void Show(const std::string& remote_user_email, 58 void Show(const std::string& remote_user_email,
58 const ResultCallback& callback) override; 59 const ResultCallback& callback) override;
59 60
60 void set_dialog_result(DialogResult dialog_result) { 61 private:
61 dialog_result_ = dialog_result; 62 FakeIt2MeConfirmationDialog();
62 }
63 63
64 const std::string& get_remote_user_email() { return remote_user_email_; }
65
66 private:
67 std::string remote_user_email_; 64 std::string remote_user_email_;
68 DialogResult dialog_result_ = DialogResult::OK; 65 DialogResult dialog_result_ = DialogResult::OK;
69 66
70 DISALLOW_COPY_AND_ASSIGN(FakeIt2MeConfirmationDialog); 67 DISALLOW_COPY_AND_ASSIGN(FakeIt2MeConfirmationDialog);
71 }; 68 };
72 69
73 FakeIt2MeConfirmationDialog::FakeIt2MeConfirmationDialog() {} 70 FakeIt2MeConfirmationDialog::FakeIt2MeConfirmationDialog() {}
74 71
72 FakeIt2MeConfirmationDialog::FakeIt2MeConfirmationDialog(
73 const std::string& remote_user_email,
74 DialogResult dialog_result)
75 : remote_user_email_(remote_user_email), dialog_result_(dialog_result) {}
76
75 FakeIt2MeConfirmationDialog::~FakeIt2MeConfirmationDialog() {} 77 FakeIt2MeConfirmationDialog::~FakeIt2MeConfirmationDialog() {}
76 78
77 void FakeIt2MeConfirmationDialog::Show(const std::string& remote_user_email, 79 void FakeIt2MeConfirmationDialog::Show(const std::string& remote_user_email,
78 const ResultCallback& callback) { 80 const ResultCallback& callback) {
79 remote_user_email_ = remote_user_email; 81 EXPECT_STREQ(remote_user_email_.c_str(), remote_user_email.c_str());
80 82
81 base::ThreadTaskRunnerHandle::Get()->PostTask( 83 base::ThreadTaskRunnerHandle::Get()->PostTask(
82 FROM_HERE, base::Bind(callback, dialog_result_)); 84 FROM_HERE, base::Bind(callback, dialog_result_));
83 } 85 }
84 86
87 class FakeIt2MeDialogFactory : public It2MeConfirmationDialogFactory {
88 public:
89 FakeIt2MeDialogFactory();
90 ~FakeIt2MeDialogFactory() override;
91
92 std::unique_ptr<It2MeConfirmationDialog> Create() override;
93
94 void set_dialog_result(DialogResult dialog_result) {
95 dialog_result_ = dialog_result;
96 }
97
98 void set_remote_user_email(const std::string& remote_user_email) {
99 remote_user_email_ = remote_user_email;
100 }
101
102 private:
103 std::string remote_user_email_;
104 DialogResult dialog_result_ = DialogResult::OK;
105
106 DISALLOW_COPY_AND_ASSIGN(FakeIt2MeDialogFactory);
107 };
108
109 FakeIt2MeDialogFactory::FakeIt2MeDialogFactory()
110 : remote_user_email_(kTestClientUserName) {}
111
112 FakeIt2MeDialogFactory::~FakeIt2MeDialogFactory() {}
113
114 std::unique_ptr<It2MeConfirmationDialog> FakeIt2MeDialogFactory::Create() {
115 EXPECT_FALSE(remote_user_email_.empty());
116 return base::MakeUnique<FakeIt2MeConfirmationDialog>(remote_user_email_,
117 dialog_result_);
118 }
119
85 class It2MeHostTest : public testing::Test, public It2MeHost::Observer { 120 class It2MeHostTest : public testing::Test, public It2MeHost::Observer {
86 public: 121 public:
87 It2MeHostTest(); 122 It2MeHostTest();
88 ~It2MeHostTest() override; 123 ~It2MeHostTest() override;
89 124
90 // testing::Test interface. 125 // testing::Test interface.
91 void SetUp() override; 126 void SetUp() override;
92 void TearDown() override; 127 void TearDown() override;
93 128
94 void OnValidationComplete(const base::Closure& resume_callback, 129 void OnValidationComplete(const base::Closure& resume_callback,
(...skipping 12 matching lines...) Expand all
107 142
108 void RunUntilStateChanged(It2MeHostState expected_state); 143 void RunUntilStateChanged(It2MeHostState expected_state);
109 144
110 void SimulateClientConnection(); 145 void SimulateClientConnection();
111 146
112 void RunValidationCallback(const std::string& remote_jid); 147 void RunValidationCallback(const std::string& remote_jid);
113 148
114 void DisconnectClient(); 149 void DisconnectClient();
115 150
116 ValidationResult validation_result_ = ValidationResult::SUCCESS; 151 ValidationResult validation_result_ = ValidationResult::SUCCESS;
117 std::string remote_user_email_;
118 152
119 base::Closure state_change_callback_; 153 base::Closure state_change_callback_;
120 154
121 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected; 155 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected;
122 156
123 // Used to set ConfirmationDialog behavior. 157 // Used to set ConfirmationDialog behavior.
124 FakeIt2MeConfirmationDialog* dialog_ = nullptr; 158 FakeIt2MeDialogFactory* dialog_factory_ = nullptr;
125 159
126 private: 160 private:
127 std::unique_ptr<base::MessageLoop> message_loop_; 161 std::unique_ptr<base::MessageLoop> message_loop_;
128 std::unique_ptr<base::RunLoop> run_loop_; 162 std::unique_ptr<base::RunLoop> run_loop_;
129 163
130 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; 164 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
131 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; 165 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
132 166
133 scoped_refptr<It2MeHost> it2me_host_; 167 scoped_refptr<It2MeHost> it2me_host_;
134 168
135 base::WeakPtrFactory<It2MeHostTest> weak_factory_; 169 base::WeakPtrFactory<It2MeHostTest> weak_factory_;
136 170
137 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); 171 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest);
138 }; 172 };
139 173
140 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {} 174 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {}
141 175
142 It2MeHostTest::~It2MeHostTest() {} 176 It2MeHostTest::~It2MeHostTest() {}
143 177
144 void It2MeHostTest::SetUp() { 178 void It2MeHostTest::SetUp() {
145 message_loop_.reset(new base::MessageLoop()); 179 message_loop_.reset(new base::MessageLoop());
146 run_loop_.reset(new base::RunLoop()); 180 run_loop_.reset(new base::RunLoop());
147 181
148 std::unique_ptr<ChromotingHostContext> host_context( 182 std::unique_ptr<ChromotingHostContext> host_context(
149 ChromotingHostContext::Create(new AutoThreadTaskRunner( 183 ChromotingHostContext::Create(new AutoThreadTaskRunner(
150 base::ThreadTaskRunnerHandle::Get(), run_loop_->QuitClosure()))); 184 base::ThreadTaskRunnerHandle::Get(), run_loop_->QuitClosure())));
151 network_task_runner_ = host_context->network_task_runner(); 185 network_task_runner_ = host_context->network_task_runner();
152 ui_task_runner_ = host_context->ui_task_runner(); 186 ui_task_runner_ = host_context->ui_task_runner();
153 187
154 dialog_ = new FakeIt2MeConfirmationDialog(); 188 std::unique_ptr<FakeIt2MeDialogFactory> dialog_factory(
189 new FakeIt2MeDialogFactory());
190 dialog_factory_ = dialog_factory.get();
155 it2me_host_ = 191 it2me_host_ =
156 new It2MeHost(std::move(host_context), 192 new It2MeHost(std::move(host_context), /*policy_watcher=*/nullptr,
157 /*policy_watcher=*/nullptr, base::WrapUnique(dialog_), 193 std::move(dialog_factory), weak_factory_.GetWeakPtr(),
158 weak_factory_.GetWeakPtr(),
159 base::WrapUnique(new FakeSignalStrategy("fake_local_jid")), 194 base::WrapUnique(new FakeSignalStrategy("fake_local_jid")),
160 "fake_user_name", "fake_bot_jid"); 195 "fake_user_name", "fake_bot_jid");
161 } 196 }
162 197
163 void It2MeHostTest::TearDown() { 198 void It2MeHostTest::TearDown() {
164 network_task_runner_ = nullptr; 199 network_task_runner_ = nullptr;
165 ui_task_runner_ = nullptr; 200 ui_task_runner_ = nullptr;
166 it2me_host_ = nullptr; 201 it2me_host_ = nullptr;
167 run_loop_->Run(); 202 run_loop_->Run();
168 } 203 }
169 204
170 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, 205 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback,
171 ValidationResult validation_result) { 206 ValidationResult validation_result) {
172 validation_result_ = validation_result; 207 validation_result_ = validation_result;
173 remote_user_email_ = dialog_->get_remote_user_email();
174 208
175 ui_task_runner_->PostTask(FROM_HERE, resume_callback); 209 ui_task_runner_->PostTask(FROM_HERE, resume_callback);
176 } 210 }
177 211
178 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) { 212 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) {
179 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue()); 213 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue());
180 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value); 214 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value);
181 215
182 base::RunLoop run_loop; 216 base::RunLoop run_loop;
183 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure()); 217 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 SimulateClientConnection(); 294 SimulateClientConnection();
261 RunValidationCallback(kTestClientUsernameNoJid); 295 RunValidationCallback(kTestClientUsernameNoJid);
262 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); 296 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
263 RunUntilStateChanged(It2MeHostState::kDisconnected); 297 RunUntilStateChanged(It2MeHostState::kDisconnected);
264 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 298 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
265 } 299 }
266 300
267 TEST_F(It2MeHostTest, 301 TEST_F(It2MeHostTest,
268 ConnectionValidation_NoClientDomainPolicy_InvalidUsername) { 302 ConnectionValidation_NoClientDomainPolicy_InvalidUsername) {
269 SimulateClientConnection(); 303 SimulateClientConnection();
304 dialog_factory_->set_remote_user_email("fake");
270 RunValidationCallback(kTestClientJidWithSlash); 305 RunValidationCallback(kTestClientJidWithSlash);
271 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 306 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
272 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); 307 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_);
273 DisconnectClient(); 308 DisconnectClient();
274 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 309 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
275 } 310 }
276 311
277 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ResourceOnly) { 312 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ResourceOnly) {
278 SimulateClientConnection(); 313 SimulateClientConnection();
279 RunValidationCallback(kResourceOnly); 314 RunValidationCallback(kResourceOnly);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 RunValidationCallback(kTestClientJid); 369 RunValidationCallback(kTestClientJid);
335 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); 370 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
336 RunUntilStateChanged(It2MeHostState::kDisconnected); 371 RunUntilStateChanged(It2MeHostState::kDisconnected);
337 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 372 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
338 } 373 }
339 374
340 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { 375 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) {
341 SimulateClientConnection(); 376 SimulateClientConnection();
342 RunValidationCallback(kTestClientJid); 377 RunValidationCallback(kTestClientJid);
343 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 378 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
344 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
345 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); 379 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_);
346 DisconnectClient(); 380 DisconnectClient();
347 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 381 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
348 } 382 }
349 383
350 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { 384 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) {
351 dialog_->set_dialog_result(DialogResult::CANCEL); 385 dialog_factory_->set_dialog_result(DialogResult::CANCEL);
352 SimulateClientConnection(); 386 SimulateClientConnection();
353 RunValidationCallback(kTestClientJid); 387 RunValidationCallback(kTestClientJid);
354 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); 388 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_);
355 RunUntilStateChanged(It2MeHostState::kDisconnected); 389 RunUntilStateChanged(It2MeHostState::kDisconnected);
356 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 390 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
357 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
358 } 391 }
359 392
360 TEST_F(It2MeHostTest, MultipleConnectionsTriggerDisconnect) { 393 TEST_F(It2MeHostTest, MultipleConnectionsTriggerDisconnect) {
361 SimulateClientConnection(); 394 SimulateClientConnection();
362 RunValidationCallback(kTestClientJid); 395 RunValidationCallback(kTestClientJid);
363 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 396 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
364 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); 397 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_);
365 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
366 398
367 RunValidationCallback(kTestClientJid2); 399 RunValidationCallback(kTestClientJid2);
368 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_); 400 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_);
369 RunUntilStateChanged(It2MeHostState::kDisconnected); 401 RunUntilStateChanged(It2MeHostState::kDisconnected);
370 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 402 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
371 } 403 }
372 404
373 } // namespace remoting 405 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698