| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/protocol/webrtc_transport.h" | 5 #include "remoting/protocol/webrtc_transport.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 void TearDown() override { | 88 void TearDown() override { |
| 89 run_loop_.reset(); | 89 run_loop_.reset(); |
| 90 client_message_pipe_.reset(); | 90 client_message_pipe_.reset(); |
| 91 client_transport_.reset(); | 91 client_transport_.reset(); |
| 92 host_message_pipe_.reset(); | 92 host_message_pipe_.reset(); |
| 93 host_transport_.reset(); | 93 host_transport_.reset(); |
| 94 base::RunLoop().RunUntilIdle(); | 94 base::RunLoop().RunUntilIdle(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ProcessTransportInfo(scoped_ptr<WebrtcTransport>* target_transport, | 97 void ProcessTransportInfo(std::unique_ptr<WebrtcTransport>* target_transport, |
| 98 bool normalize_line_endings, | 98 bool normalize_line_endings, |
| 99 scoped_ptr<buzz::XmlElement> transport_info) { | 99 std::unique_ptr<buzz::XmlElement> transport_info) { |
| 100 ASSERT_TRUE(target_transport); | 100 ASSERT_TRUE(target_transport); |
| 101 | 101 |
| 102 // Reformat the message to normalize line endings by removing CR symbol. | 102 // Reformat the message to normalize line endings by removing CR symbol. |
| 103 if (normalize_line_endings) { | 103 if (normalize_line_endings) { |
| 104 std::string xml = transport_info->Str(); | 104 std::string xml = transport_info->Str(); |
| 105 base::ReplaceChars(xml, "\r", std::string(), &xml); | 105 base::ReplaceChars(xml, "\r", std::string(), &xml); |
| 106 transport_info.reset(buzz::XmlElement::ForStr(xml)); | 106 transport_info.reset(buzz::XmlElement::ForStr(xml)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 EXPECT_TRUE( | 109 EXPECT_TRUE( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 kChannelName, base::Bind(&WebrtcTransportTest::OnClientChannelCreated, | 174 kChannelName, base::Bind(&WebrtcTransportTest::OnClientChannelCreated, |
| 175 base::Unretained(this))); | 175 base::Unretained(this))); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void CreateHostDataStream() { | 178 void CreateHostDataStream() { |
| 179 host_transport_->outgoing_channel_factory()->CreateChannel( | 179 host_transport_->outgoing_channel_factory()->CreateChannel( |
| 180 kChannelName, base::Bind(&WebrtcTransportTest::OnHostChannelCreated, | 180 kChannelName, base::Bind(&WebrtcTransportTest::OnHostChannelCreated, |
| 181 base::Unretained(this))); | 181 base::Unretained(this))); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void OnClientChannelCreated(scoped_ptr<MessagePipe> pipe) { | 184 void OnClientChannelCreated(std::unique_ptr<MessagePipe> pipe) { |
| 185 client_message_pipe_ = std::move(pipe); | 185 client_message_pipe_ = std::move(pipe); |
| 186 if (run_loop_ && host_message_pipe_) | 186 if (run_loop_ && host_message_pipe_) |
| 187 run_loop_->Quit(); | 187 run_loop_->Quit(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void OnHostChannelCreated(scoped_ptr<MessagePipe> pipe) { | 190 void OnHostChannelCreated(std::unique_ptr<MessagePipe> pipe) { |
| 191 host_message_pipe_ = std::move(pipe); | 191 host_message_pipe_ = std::move(pipe); |
| 192 if (run_loop_ && client_message_pipe_) | 192 if (run_loop_ && client_message_pipe_) |
| 193 run_loop_->Quit(); | 193 run_loop_->Quit(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void OnSessionError(TransportRole role, ErrorCode error) { | 196 void OnSessionError(TransportRole role, ErrorCode error) { |
| 197 if (role == TransportRole::SERVER) { | 197 if (role == TransportRole::SERVER) { |
| 198 host_error_ = error; | 198 host_error_ = error; |
| 199 if (destroy_on_error_) { | 199 if (destroy_on_error_) { |
| 200 host_message_pipe_.reset(); | 200 host_message_pipe_.reset(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 212 } | 212 } |
| 213 | 213 |
| 214 void QuitRunLoopOnCounter(int* counter) { | 214 void QuitRunLoopOnCounter(int* counter) { |
| 215 --(*counter); | 215 --(*counter); |
| 216 if (*counter == 0) | 216 if (*counter == 0) |
| 217 run_loop_->Quit(); | 217 run_loop_->Quit(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 protected: | 220 protected: |
| 221 base::MessageLoopForIO message_loop_; | 221 base::MessageLoopForIO message_loop_; |
| 222 scoped_ptr<base::RunLoop> run_loop_; | 222 std::unique_ptr<base::RunLoop> run_loop_; |
| 223 | 223 |
| 224 NetworkSettings network_settings_; | 224 NetworkSettings network_settings_; |
| 225 | 225 |
| 226 scoped_ptr<WebrtcTransport> host_transport_; | 226 std::unique_ptr<WebrtcTransport> host_transport_; |
| 227 TestTransportEventHandler host_event_handler_; | 227 TestTransportEventHandler host_event_handler_; |
| 228 scoped_ptr<FakeAuthenticator> host_authenticator_; | 228 std::unique_ptr<FakeAuthenticator> host_authenticator_; |
| 229 | 229 |
| 230 scoped_ptr<WebrtcTransport> client_transport_; | 230 std::unique_ptr<WebrtcTransport> client_transport_; |
| 231 TestTransportEventHandler client_event_handler_; | 231 TestTransportEventHandler client_event_handler_; |
| 232 scoped_ptr<FakeAuthenticator> client_authenticator_; | 232 std::unique_ptr<FakeAuthenticator> client_authenticator_; |
| 233 | 233 |
| 234 scoped_ptr<MessagePipe> client_message_pipe_; | 234 std::unique_ptr<MessagePipe> client_message_pipe_; |
| 235 scoped_ptr<MessagePipe> host_message_pipe_; | 235 std::unique_ptr<MessagePipe> host_message_pipe_; |
| 236 | 236 |
| 237 ErrorCode client_error_ = OK; | 237 ErrorCode client_error_ = OK; |
| 238 ErrorCode host_error_ = OK; | 238 ErrorCode host_error_ = OK; |
| 239 | 239 |
| 240 bool destroy_on_error_ = false; | 240 bool destroy_on_error_ = false; |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 TEST_F(WebrtcTransportTest, Connects) { | 243 TEST_F(WebrtcTransportTest, Connects) { |
| 244 InitializeConnection(); | 244 InitializeConnection(); |
| 245 StartConnection(); | 245 StartConnection(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 run_loop_.reset(new base::RunLoop()); | 319 run_loop_.reset(new base::RunLoop()); |
| 320 run_loop_->Run(); | 320 run_loop_->Run(); |
| 321 | 321 |
| 322 // Check that OnSessionError() has been called. | 322 // Check that OnSessionError() has been called. |
| 323 EXPECT_EQ(CHANNEL_CONNECTION_ERROR, host_error_); | 323 EXPECT_EQ(CHANNEL_CONNECTION_ERROR, host_error_); |
| 324 EXPECT_FALSE(host_transport_); | 324 EXPECT_FALSE(host_transport_); |
| 325 } | 325 } |
| 326 | 326 |
| 327 } // namespace protocol | 327 } // namespace protocol |
| 328 } // namespace remoting | 328 } // namespace remoting |
| OLD | NEW |