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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 FakeIt2MeConfirmationDialog::~FakeIt2MeConfirmationDialog() {} | 71 FakeIt2MeConfirmationDialog::~FakeIt2MeConfirmationDialog() {} |
72 | 72 |
73 void FakeIt2MeConfirmationDialog::Show(const std::string& remote_user_email, | 73 void FakeIt2MeConfirmationDialog::Show(const std::string& remote_user_email, |
74 const ResultCallback& callback) { | 74 const ResultCallback& callback) { |
75 remote_user_email_ = remote_user_email; | 75 remote_user_email_ = remote_user_email; |
76 | 76 |
77 base::ThreadTaskRunnerHandle::Get()->PostTask( | 77 base::ThreadTaskRunnerHandle::Get()->PostTask( |
78 FROM_HERE, base::Bind(callback, dialog_result_)); | 78 FROM_HERE, base::Bind(callback, dialog_result_)); |
79 } | 79 } |
80 | 80 |
81 class FakeIt2MeConfirmationDialogFactory | |
82 : public It2MeConfirmationDialogFactory { | |
83 public: | |
84 FakeIt2MeConfirmationDialogFactory(); | |
85 ~FakeIt2MeConfirmationDialogFactory() override; | |
86 | |
87 // It2MeConfirmationDialogFactory override. | |
88 std::unique_ptr<It2MeConfirmationDialog> Create() override; | |
89 | |
90 void set_confirmation_dialog( | |
91 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog) { | |
92 confirmation_dialog_ = std::move(confirmation_dialog); | |
93 } | |
94 | |
95 private: | |
96 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(FakeIt2MeConfirmationDialogFactory); | |
99 }; | |
100 | |
101 FakeIt2MeConfirmationDialogFactory::FakeIt2MeConfirmationDialogFactory() {} | |
102 | |
103 FakeIt2MeConfirmationDialogFactory::~FakeIt2MeConfirmationDialogFactory() {} | |
104 | |
105 std::unique_ptr<It2MeConfirmationDialog> | |
106 FakeIt2MeConfirmationDialogFactory::Create() { | |
107 return std::move(confirmation_dialog_); | |
108 } | |
109 | |
110 class It2MeHostTest : public testing::Test { | 81 class It2MeHostTest : public testing::Test { |
111 public: | 82 public: |
112 It2MeHostTest() {} | 83 It2MeHostTest() {} |
113 ~It2MeHostTest() override {} | 84 ~It2MeHostTest() override {} |
114 | 85 |
115 // testing::Test interface. | 86 // testing::Test interface. |
116 void SetUp() override; | 87 void SetUp() override; |
117 void TearDown() override; | 88 void TearDown() override; |
118 | 89 |
119 void OnValidationComplete(const base::Closure& resume_callback, | 90 void OnValidationComplete(const base::Closure& resume_callback, |
(...skipping 18 matching lines...) Expand all Loading... |
138 std::string directory_bot_jid_; | 109 std::string directory_bot_jid_; |
139 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 110 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
140 | 111 |
141 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); | 112 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); |
142 }; | 113 }; |
143 | 114 |
144 void It2MeHostTest::SetUp() { | 115 void It2MeHostTest::SetUp() { |
145 message_loop_.reset(new base::MessageLoop()); | 116 message_loop_.reset(new base::MessageLoop()); |
146 run_loop_.reset(new base::RunLoop()); | 117 run_loop_.reset(new base::RunLoop()); |
147 | 118 |
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 | |
153 scoped_refptr<AutoThreadTaskRunner> auto_thread_task_runner = | 119 scoped_refptr<AutoThreadTaskRunner> auto_thread_task_runner = |
154 new AutoThreadTaskRunner(base::ThreadTaskRunnerHandle::Get(), | 120 new AutoThreadTaskRunner(base::ThreadTaskRunnerHandle::Get(), |
155 run_loop_->QuitClosure()); | 121 run_loop_->QuitClosure()); |
156 | 122 dialog_ = new FakeIt2MeConfirmationDialog(); |
157 it2me_host_ = new It2MeHost( | 123 it2me_host_ = new It2MeHost( |
158 ChromotingHostContext::Create(auto_thread_task_runner), | 124 ChromotingHostContext::Create(auto_thread_task_runner), |
159 /*policy_watcher=*/nullptr, std::move(fake_dialog_factory), | 125 /*policy_watcher=*/nullptr, base::WrapUnique(dialog_), |
160 /*observer=*/nullptr, xmpp_server_config_, directory_bot_jid_); | 126 /*observer=*/nullptr, xmpp_server_config_, directory_bot_jid_); |
161 } | 127 } |
162 | 128 |
163 void It2MeHostTest::TearDown() { | 129 void It2MeHostTest::TearDown() { |
164 it2me_host_ = nullptr; | 130 it2me_host_ = nullptr; |
165 run_loop_->Run(); | 131 run_loop_->Run(); |
166 } | 132 } |
167 | 133 |
168 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, | 134 void It2MeHostTest::OnValidationComplete(const base::Closure& resume_callback, |
169 ValidationResult validation_result) { | 135 ValidationResult validation_result) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 220 } |
255 | 221 |
256 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { | 222 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { |
257 dialog_->set_dialog_result(DialogResult::CANCEL); | 223 dialog_->set_dialog_result(DialogResult::CANCEL); |
258 RunValidationCallback(kTestClientJid); | 224 RunValidationCallback(kTestClientJid); |
259 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); | 225 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); |
260 ASSERT_STREQ(kTestClientUserName, dialog_->get_remote_user_email().c_str()); | 226 ASSERT_STREQ(kTestClientUserName, dialog_->get_remote_user_email().c_str()); |
261 } | 227 } |
262 | 228 |
263 } // namespace remoting | 229 } // namespace remoting |
OLD | NEW |