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

Side by Side Diff: remoting/protocol/ice_transport_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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 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/ice_transport.h" 5 #include "remoting/protocol/ice_transport.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "jingle/glue/thread_wrapper.h" 17 #include "jingle/glue/thread_wrapper.h"
17 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
18 #include "remoting/base/url_request.h" 19 #include "remoting/base/url_request.h"
19 #include "remoting/protocol/chromium_port_allocator_factory.h" 20 #include "remoting/protocol/chromium_port_allocator_factory.h"
20 #include "remoting/protocol/connection_tester.h" 21 #include "remoting/protocol/connection_tester.h"
21 #include "remoting/protocol/fake_authenticator.h" 22 #include "remoting/protocol/fake_authenticator.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 91 }
91 92
92 void TearDown() override { 93 void TearDown() override {
93 client_message_pipe_.reset(); 94 client_message_pipe_.reset();
94 host_message_pipe_.reset(); 95 host_message_pipe_.reset();
95 client_transport_.reset(); 96 client_transport_.reset();
96 host_transport_.reset(); 97 host_transport_.reset();
97 message_loop_.RunUntilIdle(); 98 message_loop_.RunUntilIdle();
98 } 99 }
99 100
100 void ProcessTransportInfo(scoped_ptr<IceTransport>* target_transport, 101 void ProcessTransportInfo(std::unique_ptr<IceTransport>* target_transport,
101 scoped_ptr<buzz::XmlElement> transport_info) { 102 std::unique_ptr<buzz::XmlElement> transport_info) {
102 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 103 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
103 FROM_HERE, base::Bind(&IceTransportTest::DeliverTransportInfo, 104 FROM_HERE, base::Bind(&IceTransportTest::DeliverTransportInfo,
104 base::Unretained(this), target_transport, 105 base::Unretained(this), target_transport,
105 base::Passed(&transport_info)), 106 base::Passed(&transport_info)),
106 transport_info_delay_); 107 transport_info_delay_);
107 } 108 }
108 109
109 void DeliverTransportInfo(scoped_ptr<IceTransport>* target_transport, 110 void DeliverTransportInfo(std::unique_ptr<IceTransport>* target_transport,
110 scoped_ptr<buzz::XmlElement> transport_info) { 111 std::unique_ptr<buzz::XmlElement> transport_info) {
111 ASSERT_TRUE(target_transport); 112 ASSERT_TRUE(target_transport);
112 EXPECT_TRUE( 113 EXPECT_TRUE(
113 (*target_transport)->ProcessTransportInfo(transport_info.get())); 114 (*target_transport)->ProcessTransportInfo(transport_info.get()));
114 } 115 }
115 116
116 void InitializeConnection() { 117 void InitializeConnection() {
117 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 118 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
118 119
119 host_transport_.reset(new IceTransport( 120 host_transport_.reset(new IceTransport(
120 new TransportContext( 121 new TransportContext(
121 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory()), 122 nullptr, base::WrapUnique(new ChromiumPortAllocatorFactory()),
122 nullptr, network_settings_, TransportRole::SERVER), 123 nullptr, network_settings_, TransportRole::SERVER),
123 &host_event_handler_)); 124 &host_event_handler_));
124 if (!host_authenticator_) { 125 if (!host_authenticator_) {
125 host_authenticator_.reset(new FakeAuthenticator( 126 host_authenticator_.reset(new FakeAuthenticator(
126 FakeAuthenticator::HOST, 0, FakeAuthenticator::ACCEPT, true)); 127 FakeAuthenticator::HOST, 0, FakeAuthenticator::ACCEPT, true));
127 } 128 }
128 129
129 client_transport_.reset(new IceTransport( 130 client_transport_.reset(new IceTransport(
130 new TransportContext( 131 new TransportContext(
131 nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory()), 132 nullptr, base::WrapUnique(new ChromiumPortAllocatorFactory()),
132 nullptr, network_settings_, TransportRole::CLIENT), 133 nullptr, network_settings_, TransportRole::CLIENT),
133 &client_event_handler_)); 134 &client_event_handler_));
134 if (!client_authenticator_) { 135 if (!client_authenticator_) {
135 client_authenticator_.reset(new FakeAuthenticator( 136 client_authenticator_.reset(new FakeAuthenticator(
136 FakeAuthenticator::CLIENT, 0, FakeAuthenticator::ACCEPT, true)); 137 FakeAuthenticator::CLIENT, 0, FakeAuthenticator::ACCEPT, true));
137 } 138 }
138 139
139 host_event_handler_.set_error_callback(base::Bind( 140 host_event_handler_.set_error_callback(base::Bind(
140 &IceTransportTest::OnTransportError, base::Unretained(this))); 141 &IceTransportTest::OnTransportError, base::Unretained(this)));
141 client_event_handler_.set_error_callback(base::Bind( 142 client_event_handler_.set_error_callback(base::Bind(
(...skipping 18 matching lines...) Expand all
160 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter)); 161 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter));
161 EXPECT_CALL(host_channel_callback_, OnDone(_)) 162 EXPECT_CALL(host_channel_callback_, OnDone(_))
162 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter)); 163 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter));
163 164
164 run_loop_->Run(); 165 run_loop_->Run();
165 166
166 EXPECT_TRUE(client_message_pipe_.get()); 167 EXPECT_TRUE(client_message_pipe_.get());
167 EXPECT_TRUE(host_message_pipe_.get()); 168 EXPECT_TRUE(host_message_pipe_.get());
168 } 169 }
169 170
170 void OnClientChannelCreated(scoped_ptr<MessagePipe> message_pipe) { 171 void OnClientChannelCreated(std::unique_ptr<MessagePipe> message_pipe) {
171 client_message_pipe_ = std::move(message_pipe); 172 client_message_pipe_ = std::move(message_pipe);
172 client_channel_callback_.OnDone(client_message_pipe_.get()); 173 client_channel_callback_.OnDone(client_message_pipe_.get());
173 } 174 }
174 175
175 void OnHostChannelCreated(scoped_ptr<MessagePipe> message_pipe) { 176 void OnHostChannelCreated(std::unique_ptr<MessagePipe> message_pipe) {
176 host_message_pipe_ = std::move(message_pipe); 177 host_message_pipe_ = std::move(message_pipe);
177 host_channel_callback_.OnDone(host_message_pipe_.get()); 178 host_channel_callback_.OnDone(host_message_pipe_.get());
178 } 179 }
179 180
180 void OnTransportError(ErrorCode error) { 181 void OnTransportError(ErrorCode error) {
181 LOG(ERROR) << "Transport Error"; 182 LOG(ERROR) << "Transport Error";
182 error_ = error; 183 error_ = error;
183 run_loop_->Quit(); 184 run_loop_->Quit();
184 } 185 }
185 186
186 protected: 187 protected:
187 base::MessageLoopForIO message_loop_; 188 base::MessageLoopForIO message_loop_;
188 scoped_ptr<base::RunLoop> run_loop_; 189 std::unique_ptr<base::RunLoop> run_loop_;
189 190
190 NetworkSettings network_settings_; 191 NetworkSettings network_settings_;
191 192
192 base::TimeDelta transport_info_delay_; 193 base::TimeDelta transport_info_delay_;
193 194
194 scoped_ptr<IceTransport> host_transport_; 195 std::unique_ptr<IceTransport> host_transport_;
195 TestTransportEventHandler host_event_handler_; 196 TestTransportEventHandler host_event_handler_;
196 scoped_ptr<FakeAuthenticator> host_authenticator_; 197 std::unique_ptr<FakeAuthenticator> host_authenticator_;
197 198
198 scoped_ptr<IceTransport> client_transport_; 199 std::unique_ptr<IceTransport> client_transport_;
199 TestTransportEventHandler client_event_handler_; 200 TestTransportEventHandler client_event_handler_;
200 scoped_ptr<FakeAuthenticator> client_authenticator_; 201 std::unique_ptr<FakeAuthenticator> client_authenticator_;
201 202
202 MockChannelCreatedCallback client_channel_callback_; 203 MockChannelCreatedCallback client_channel_callback_;
203 MockChannelCreatedCallback host_channel_callback_; 204 MockChannelCreatedCallback host_channel_callback_;
204 205
205 scoped_ptr<MessagePipe> client_message_pipe_; 206 std::unique_ptr<MessagePipe> client_message_pipe_;
206 scoped_ptr<MessagePipe> host_message_pipe_; 207 std::unique_ptr<MessagePipe> host_message_pipe_;
207 208
208 ErrorCode error_ = OK; 209 ErrorCode error_ = OK;
209 }; 210 };
210 211
211 TEST_F(IceTransportTest, DataStream) { 212 TEST_F(IceTransportTest, DataStream) {
212 InitializeConnection(); 213 InitializeConnection();
213 214
214 client_transport_->GetChannelFactory()->CreateChannel( 215 client_transport_->GetChannelFactory()->CreateChannel(
215 kChannelName, base::Bind(&IceTransportTest::OnClientChannelCreated, 216 kChannelName, base::Bind(&IceTransportTest::OnClientChannelCreated,
216 base::Unretained(this))); 217 base::Unretained(this)));
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 337
337 MessagePipeConnectionTester tester(host_message_pipe_.get(), 338 MessagePipeConnectionTester tester(host_message_pipe_.get(),
338 client_message_pipe_.get(), kMessageSize, 339 client_message_pipe_.get(), kMessageSize,
339 kMessages); 340 kMessages);
340 tester.RunAndCheckResults(); 341 tester.RunAndCheckResults();
341 } 342 }
342 343
343 344
344 } // namespace protocol 345 } // namespace protocol
345 } // namespace remoting 346 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/ice_transport_channel.cc ('k') | remoting/protocol/it2me_host_authenticator_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698