| 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 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ValidationResult validation_result); | 120 ValidationResult validation_result); |
| 121 | 121 |
| 122 protected: | 122 protected: |
| 123 void SetClientDomainPolicy(const std::string& policy_value); | 123 void SetClientDomainPolicy(const std::string& policy_value); |
| 124 | 124 |
| 125 void RunValidationCallback(const std::string& remote_jid); | 125 void RunValidationCallback(const std::string& remote_jid); |
| 126 | 126 |
| 127 ValidationResult validation_result_ = ValidationResult::SUCCESS; | 127 ValidationResult validation_result_ = ValidationResult::SUCCESS; |
| 128 | 128 |
| 129 // Used to set ConfirmationDialog behavior. | 129 // Used to set ConfirmationDialog behavior. |
| 130 FakeIt2MeConfirmationDialogFactory* fake_dialog_factory_ = nullptr; | 130 FakeIt2MeConfirmationDialog* dialog_ = nullptr; |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 std::unique_ptr<base::MessageLoop> message_loop_; | 133 std::unique_ptr<base::MessageLoop> message_loop_; |
| 134 std::unique_ptr<base::RunLoop> run_loop_; | 134 std::unique_ptr<base::RunLoop> run_loop_; |
| 135 | 135 |
| 136 scoped_refptr<It2MeHost> it2me_host_; | 136 scoped_refptr<It2MeHost> it2me_host_; |
| 137 | 137 |
| 138 std::string directory_bot_jid_; | 138 std::string directory_bot_jid_; |
| 139 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 139 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
| 140 | 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); | 141 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 void It2MeHostTest::SetUp() { | 144 void It2MeHostTest::SetUp() { |
| 145 message_loop_.reset(new base::MessageLoop()); | 145 message_loop_.reset(new base::MessageLoop()); |
| 146 run_loop_.reset(new base::RunLoop()); | 146 run_loop_.reset(new base::RunLoop()); |
| 147 | 147 |
| 148 fake_dialog_factory_ = new FakeIt2MeConfirmationDialogFactory(); | 148 std::unique_ptr<FakeIt2MeConfirmationDialogFactory> fake_dialog_factory( |
| 149 new FakeIt2MeConfirmationDialogFactory()); |
| 150 dialog_ = new FakeIt2MeConfirmationDialog(); |
| 151 fake_dialog_factory->set_confirmation_dialog(base::WrapUnique(dialog_)); |
| 152 |
| 149 scoped_refptr<AutoThreadTaskRunner> auto_thread_task_runner = | 153 scoped_refptr<AutoThreadTaskRunner> auto_thread_task_runner = |
| 150 new AutoThreadTaskRunner(base::ThreadTaskRunnerHandle::Get(), | 154 new AutoThreadTaskRunner(base::ThreadTaskRunnerHandle::Get(), |
| 151 run_loop_->QuitClosure()); | 155 run_loop_->QuitClosure()); |
| 156 |
| 152 it2me_host_ = new It2MeHost( | 157 it2me_host_ = new It2MeHost( |
| 153 ChromotingHostContext::Create(auto_thread_task_runner), | 158 ChromotingHostContext::Create(auto_thread_task_runner), |
| 154 /*policy_watcher=*/nullptr, base::WrapUnique(fake_dialog_factory_), | 159 /*policy_watcher=*/nullptr, std::move(fake_dialog_factory), |
| 155 /*observer=*/nullptr, xmpp_server_config_, directory_bot_jid_); | 160 /*observer=*/nullptr, xmpp_server_config_, directory_bot_jid_); |
| 156 } | 161 } |
| 157 | 162 |
| 158 void It2MeHostTest::TearDown() { | 163 void It2MeHostTest::TearDown() { |
| 159 it2me_host_ = nullptr; | 164 it2me_host_ = nullptr; |
| 160 run_loop_->Run(); | 165 run_loop_->Run(); |
| 161 } | 166 } |
| 162 | 167 |
| 163 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, | 168 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, |
| 164 ValidationResult validation_result) { | 169 ValidationResult validation_result) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 RunValidationCallback(kTestClientJid); | 240 RunValidationCallback(kTestClientJid); |
| 236 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 241 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 237 } | 242 } |
| 238 | 243 |
| 239 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) { | 244 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) { |
| 240 SetClientDomainPolicy(kMismatchedDomain1); | 245 SetClientDomainPolicy(kMismatchedDomain1); |
| 241 RunValidationCallback(kTestClientJid); | 246 RunValidationCallback(kTestClientJid); |
| 242 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 247 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 243 } | 248 } |
| 244 | 249 |
| 245 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_NoDialog) { | 250 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { |
| 246 RunValidationCallback(kTestClientJid); | 251 RunValidationCallback(kTestClientJid); |
| 247 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 252 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 248 } | 253 ASSERT_STREQ(kTestClientUserName, dialog_->get_remote_user_email().c_str()); |
| 249 | |
| 250 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { | |
| 251 FakeIt2MeConfirmationDialog* dialog = new FakeIt2MeConfirmationDialog(); | |
| 252 fake_dialog_factory_->set_confirmation_dialog(base::WrapUnique(dialog)); | |
| 253 | |
| 254 RunValidationCallback(kTestClientJid); | |
| 255 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | |
| 256 ASSERT_STREQ(kTestClientUserName, dialog->get_remote_user_email().c_str()); | |
| 257 } | 254 } |
| 258 | 255 |
| 259 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { | 256 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { |
| 260 FakeIt2MeConfirmationDialog* dialog = new FakeIt2MeConfirmationDialog(); | 257 dialog_->set_dialog_result(DialogResult::CANCEL); |
| 261 dialog->set_dialog_result(DialogResult::CANCEL); | |
| 262 fake_dialog_factory_->set_confirmation_dialog(base::WrapUnique(dialog)); | |
| 263 | |
| 264 RunValidationCallback(kTestClientJid); | 258 RunValidationCallback(kTestClientJid); |
| 265 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); | 259 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); |
| 266 ASSERT_STREQ(kTestClientUserName, dialog->get_remote_user_email().c_str()); | 260 ASSERT_STREQ(kTestClientUserName, dialog_->get_remote_user_email().c_str()); |
| 267 } | 261 } |
| 268 | 262 |
| 269 } // namespace remoting | 263 } // namespace remoting |
| OLD | NEW |