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

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: Comment tweaks 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
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 14 matching lines...) Expand all
109 144
110 void SimulateClientConnection(); 145 void SimulateClientConnection();
111 146
112 void RunIncomingConnectionCallback(const std::string& remote_jid); 147 void RunIncomingConnectionCallback(const std::string& remote_jid);
113 148
114 void RunAcceptedConnectionCallback(const std::string& remote_jid); 149 void RunAcceptedConnectionCallback(const std::string& remote_jid);
115 150
116 void DisconnectClient(); 151 void DisconnectClient();
117 152
118 ValidationResult validation_result_ = ValidationResult::SUCCESS; 153 ValidationResult validation_result_ = ValidationResult::SUCCESS;
119 std::string remote_user_email_;
120 154
121 base::Closure state_change_callback_; 155 base::Closure state_change_callback_;
122 156
123 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected; 157 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected;
124 158
125 // Used to set ConfirmationDialog behavior. 159 // Used to set ConfirmationDialog behavior.
126 FakeIt2MeConfirmationDialog* dialog_ = nullptr; 160 FakeIt2MeDialogFactory* dialog_factory_ = nullptr;
127 161
128 private: 162 private:
129 std::unique_ptr<base::MessageLoop> message_loop_; 163 std::unique_ptr<base::MessageLoop> message_loop_;
130 std::unique_ptr<base::RunLoop> run_loop_; 164 std::unique_ptr<base::RunLoop> run_loop_;
131 165
132 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; 166 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
133 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; 167 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
134 168
135 scoped_refptr<It2MeHost> it2me_host_; 169 scoped_refptr<It2MeHost> it2me_host_;
136 170
137 base::WeakPtrFactory<It2MeHostTest> weak_factory_; 171 base::WeakPtrFactory<It2MeHostTest> weak_factory_;
138 172
139 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); 173 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest);
140 }; 174 };
141 175
142 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {} 176 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {}
143 177
144 It2MeHostTest::~It2MeHostTest() {} 178 It2MeHostTest::~It2MeHostTest() {}
145 179
146 void It2MeHostTest::SetUp() { 180 void It2MeHostTest::SetUp() {
147 message_loop_.reset(new base::MessageLoop()); 181 message_loop_.reset(new base::MessageLoop());
148 run_loop_.reset(new base::RunLoop()); 182 run_loop_.reset(new base::RunLoop());
149 183
150 std::unique_ptr<ChromotingHostContext> host_context( 184 std::unique_ptr<ChromotingHostContext> host_context(
151 ChromotingHostContext::Create(new AutoThreadTaskRunner( 185 ChromotingHostContext::Create(new AutoThreadTaskRunner(
152 base::ThreadTaskRunnerHandle::Get(), run_loop_->QuitClosure()))); 186 base::ThreadTaskRunnerHandle::Get(), run_loop_->QuitClosure())));
153 network_task_runner_ = host_context->network_task_runner(); 187 network_task_runner_ = host_context->network_task_runner();
154 ui_task_runner_ = host_context->ui_task_runner(); 188 ui_task_runner_ = host_context->ui_task_runner();
155 189
156 dialog_ = new FakeIt2MeConfirmationDialog(); 190 std::unique_ptr<FakeIt2MeDialogFactory> dialog_factory(
191 new FakeIt2MeDialogFactory());
192 dialog_factory_ = dialog_factory.get();
157 it2me_host_ = 193 it2me_host_ =
158 new It2MeHost(std::move(host_context), 194 new It2MeHost(std::move(host_context), /*policy_watcher=*/nullptr,
159 /*policy_watcher=*/nullptr, base::WrapUnique(dialog_), 195 std::move(dialog_factory), weak_factory_.GetWeakPtr(),
160 weak_factory_.GetWeakPtr(),
161 base::WrapUnique(new FakeSignalStrategy("fake_local_jid")), 196 base::WrapUnique(new FakeSignalStrategy("fake_local_jid")),
162 "fake_user_name", "fake_bot_jid"); 197 "fake_user_name", "fake_bot_jid");
163 } 198 }
164 199
165 void It2MeHostTest::TearDown() { 200 void It2MeHostTest::TearDown() {
166 network_task_runner_ = nullptr; 201 network_task_runner_ = nullptr;
167 ui_task_runner_ = nullptr; 202 ui_task_runner_ = nullptr;
168 it2me_host_ = nullptr; 203 it2me_host_ = nullptr;
169 run_loop_->Run(); 204 run_loop_->Run();
170 } 205 }
171 206
172 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, 207 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback,
173 ValidationResult validation_result) { 208 ValidationResult validation_result) {
174 validation_result_ = validation_result; 209 validation_result_ = validation_result;
175 remote_user_email_ = dialog_->get_remote_user_email();
176 210
177 ui_task_runner_->PostTask(FROM_HERE, resume_callback); 211 ui_task_runner_->PostTask(FROM_HERE, resume_callback);
178 } 212 }
179 213
180 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) { 214 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) {
181 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue()); 215 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue());
182 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value); 216 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value);
183 217
184 base::RunLoop run_loop; 218 base::RunLoop run_loop;
185 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure()); 219 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure());
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 390 }
357 391
358 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { 392 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) {
359 SimulateClientConnection(); 393 SimulateClientConnection();
360 RunIncomingConnectionCallback(kTestClientJid); 394 RunIncomingConnectionCallback(kTestClientJid);
361 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 395 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
362 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_); 396 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_);
363 397
364 RunAcceptedConnectionCallback(kTestClientJid); 398 RunAcceptedConnectionCallback(kTestClientJid);
365 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 399 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
366 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
367 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); 400 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_);
368 401
369 DisconnectClient(); 402 DisconnectClient();
370 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 403 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
371 } 404 }
372 405
373 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { 406 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) {
374 dialog_->set_dialog_result(DialogResult::CANCEL); 407 dialog_factory_->set_dialog_result(DialogResult::CANCEL);
375 SimulateClientConnection(); 408 SimulateClientConnection();
376 409
377 RunIncomingConnectionCallback(kTestClientJid); 410 RunIncomingConnectionCallback(kTestClientJid);
378 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 411 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
379 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_); 412 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_);
380 413
381 RunAcceptedConnectionCallback(kTestClientJid); 414 RunAcceptedConnectionCallback(kTestClientJid);
382 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); 415 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_);
383 RunUntilStateChanged(It2MeHostState::kDisconnected); 416 RunUntilStateChanged(It2MeHostState::kDisconnected);
384 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 417 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
385 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
386 } 418 }
387 419
388 TEST_F(It2MeHostTest, MultipleConnectionsTriggerDisconnect) { 420 TEST_F(It2MeHostTest, MultipleConnectionsTriggerDisconnect) {
389 SimulateClientConnection(); 421 SimulateClientConnection();
390 RunIncomingConnectionCallback(kTestClientJid); 422 RunIncomingConnectionCallback(kTestClientJid);
391 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 423 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
392 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_); 424 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_);
393 425
394 RunAcceptedConnectionCallback(kTestClientJid); 426 RunAcceptedConnectionCallback(kTestClientJid);
395 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 427 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
396 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); 428 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_);
397 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
398 429
399 RunIncomingConnectionCallback(kTestClientJid2); 430 RunIncomingConnectionCallback(kTestClientJid2);
400 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 431 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
401 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); 432 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_);
402 433
403 RunAcceptedConnectionCallback(kTestClientJid2); 434 RunAcceptedConnectionCallback(kTestClientJid2);
404 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_); 435 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_);
405 RunUntilStateChanged(It2MeHostState::kDisconnected); 436 RunUntilStateChanged(It2MeHostState::kDisconnected);
406 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 437 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
407 } 438 }
408 439
409 } // namespace remoting 440 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698