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

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

Issue 2082363002: Remove calls to deprecated MessageLoop methods in remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/pseudotcp_adapter.h" 5 #include "remoting/protocol/pseudotcp_adapter.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.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/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "jingle/glue/thread_wrapper.h" 17 #include "jingle/glue/thread_wrapper.h"
17 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
19 #include "net/base/test_completion_callback.h" 20 #include "net/base/test_completion_callback.h"
20 #include "remoting/protocol/p2p_datagram_socket.h" 21 #include "remoting/protocol/p2p_datagram_socket.h"
21 #include "remoting/protocol/p2p_stream_socket.h" 22 #include "remoting/protocol/p2p_stream_socket.h"
22 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 149
149 std::deque<std::vector<char> > incoming_packets_; 150 std::deque<std::vector<char> > incoming_packets_;
150 151
151 FakeSocket* peer_socket_; 152 FakeSocket* peer_socket_;
152 RateLimiter* rate_limiter_; 153 RateLimiter* rate_limiter_;
153 int latency_ms_; 154 int latency_ms_;
154 }; 155 };
155 156
156 class TCPChannelTester : public base::RefCountedThreadSafe<TCPChannelTester> { 157 class TCPChannelTester : public base::RefCountedThreadSafe<TCPChannelTester> {
157 public: 158 public:
158 TCPChannelTester(base::MessageLoop* message_loop, 159 TCPChannelTester(base::MessageLoop* message_loop,
Sergey Ulanov 2016/06/22 17:50:15 nit: this can be replaced with scoped_refptr<base:
fdoray 2016/06/22 18:12:48 Done. Might as well do it now.
Sergey Ulanov 2016/06/22 18:35:22 Thanks!
159 P2PStreamSocket* client_socket, 160 P2PStreamSocket* client_socket,
160 P2PStreamSocket* host_socket) 161 P2PStreamSocket* host_socket)
161 : message_loop_(message_loop), 162 : message_loop_(message_loop),
162 host_socket_(host_socket), 163 host_socket_(host_socket),
163 client_socket_(client_socket), 164 client_socket_(client_socket),
164 done_(false), 165 done_(false),
165 write_errors_(0), 166 write_errors_(0),
166 read_errors_(0) {} 167 read_errors_(0) {}
167 168
168 void Start() { 169 void Start() {
169 message_loop_->PostTask( 170 message_loop_->task_runner()->PostTask(
170 FROM_HERE, base::Bind(&TCPChannelTester::DoStart, this)); 171 FROM_HERE, base::Bind(&TCPChannelTester::DoStart, this));
171 } 172 }
172 173
173 void CheckResults() { 174 void CheckResults() {
174 EXPECT_EQ(0, write_errors_); 175 EXPECT_EQ(0, write_errors_);
175 EXPECT_EQ(0, read_errors_); 176 EXPECT_EQ(0, read_errors_);
176 177
177 ASSERT_EQ(kTestDataSize + kMessageSize, input_buffer_->capacity()); 178 ASSERT_EQ(kTestDataSize + kMessageSize, input_buffer_->capacity());
178 179
179 output_buffer_->SetOffset(0); 180 output_buffer_->SetOffset(0);
180 ASSERT_EQ(kTestDataSize, output_buffer_->size()); 181 ASSERT_EQ(kTestDataSize, output_buffer_->size());
181 182
182 EXPECT_EQ(0, memcmp(output_buffer_->data(), 183 EXPECT_EQ(0, memcmp(output_buffer_->data(),
183 input_buffer_->StartOfBuffer(), kTestDataSize)); 184 input_buffer_->StartOfBuffer(), kTestDataSize));
184 } 185 }
185 186
186 protected: 187 protected:
187 virtual ~TCPChannelTester() {} 188 virtual ~TCPChannelTester() {}
188 189
189 void Done() { 190 void Done() {
190 done_ = true; 191 done_ = true;
191 message_loop_->PostTask(FROM_HERE, 192 message_loop_->task_runner()->PostTask(
192 base::MessageLoop::QuitWhenIdleClosure()); 193 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
193 } 194 }
194 195
195 void DoStart() { 196 void DoStart() {
196 InitBuffers(); 197 InitBuffers();
197 DoRead(); 198 DoRead();
198 DoWrite(); 199 DoWrite();
199 } 200 }
200 201
201 void InitBuffers() { 202 void InitBuffers() {
202 output_buffer_ = new net::DrainableIOBuffer( 203 output_buffer_ = new net::DrainableIOBuffer(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if (rv2 == net::ERR_IO_PENDING) 324 if (rv2 == net::ERR_IO_PENDING)
324 rv2 = client_connect_cb.WaitForResult(); 325 rv2 = client_connect_cb.WaitForResult();
325 ASSERT_EQ(net::OK, rv1); 326 ASSERT_EQ(net::OK, rv1);
326 ASSERT_EQ(net::OK, rv2); 327 ASSERT_EQ(net::OK, rv2);
327 328
328 scoped_refptr<TCPChannelTester> tester = 329 scoped_refptr<TCPChannelTester> tester =
329 new TCPChannelTester(&message_loop_, host_pseudotcp_.get(), 330 new TCPChannelTester(&message_loop_, host_pseudotcp_.get(),
330 client_pseudotcp_.get()); 331 client_pseudotcp_.get());
331 332
332 tester->Start(); 333 tester->Start();
333 message_loop_.Run(); 334 base::RunLoop().Run();
334 tester->CheckResults(); 335 tester->CheckResults();
335 } 336 }
336 337
337 TEST_F(PseudoTcpAdapterTest, LimitedChannel) { 338 TEST_F(PseudoTcpAdapterTest, LimitedChannel) {
338 const int kLatencyMs = 20; 339 const int kLatencyMs = 20;
339 const int kPacketsPerSecond = 400; 340 const int kPacketsPerSecond = 400;
340 const int kBurstPackets = 10; 341 const int kBurstPackets = 10;
341 342
342 LeakyBucket host_limiter(kBurstPackets, kPacketsPerSecond); 343 LeakyBucket host_limiter(kBurstPackets, kPacketsPerSecond);
343 host_socket_->set_latency(kLatencyMs); 344 host_socket_->set_latency(kLatencyMs);
(...skipping 14 matching lines...) Expand all
358 if (rv2 == net::ERR_IO_PENDING) 359 if (rv2 == net::ERR_IO_PENDING)
359 rv2 = client_connect_cb.WaitForResult(); 360 rv2 = client_connect_cb.WaitForResult();
360 ASSERT_EQ(net::OK, rv1); 361 ASSERT_EQ(net::OK, rv1);
361 ASSERT_EQ(net::OK, rv2); 362 ASSERT_EQ(net::OK, rv2);
362 363
363 scoped_refptr<TCPChannelTester> tester = 364 scoped_refptr<TCPChannelTester> tester =
364 new TCPChannelTester(&message_loop_, host_pseudotcp_.get(), 365 new TCPChannelTester(&message_loop_, host_pseudotcp_.get(),
365 client_pseudotcp_.get()); 366 client_pseudotcp_.get());
366 367
367 tester->Start(); 368 tester->Start();
368 message_loop_.Run(); 369 base::RunLoop().Run();
369 tester->CheckResults(); 370 tester->CheckResults();
370 } 371 }
371 372
372 class DeleteOnConnected { 373 class DeleteOnConnected {
373 public: 374 public:
374 DeleteOnConnected(base::MessageLoop* message_loop, 375 DeleteOnConnected(base::MessageLoop* message_loop,
375 std::unique_ptr<PseudoTcpAdapter>* adapter) 376 std::unique_ptr<PseudoTcpAdapter>* adapter)
376 : message_loop_(message_loop), adapter_(adapter) {} 377 : message_loop_(message_loop), adapter_(adapter) {}
377 void OnConnected(int error) { 378 void OnConnected(int error) {
378 adapter_->reset(); 379 adapter_->reset();
379 message_loop_->PostTask(FROM_HERE, 380 message_loop_->task_runner()->PostTask(
380 base::MessageLoop::QuitWhenIdleClosure()); 381 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
381 } 382 }
382 base::MessageLoop* message_loop_; 383 base::MessageLoop* message_loop_;
383 std::unique_ptr<PseudoTcpAdapter>* adapter_; 384 std::unique_ptr<PseudoTcpAdapter>* adapter_;
384 }; 385 };
385 386
386 TEST_F(PseudoTcpAdapterTest, DeleteOnConnected) { 387 TEST_F(PseudoTcpAdapterTest, DeleteOnConnected) {
387 // This test verifies that deleting the adapter mid-callback doesn't lead 388 // This test verifies that deleting the adapter mid-callback doesn't lead
388 // to deleted structures being touched as the stack unrolls, so the failure 389 // to deleted structures being touched as the stack unrolls, so the failure
389 // mode is a crash rather than a normal test failure. 390 // mode is a crash rather than a normal test failure.
390 net::TestCompletionCallback client_connect_cb; 391 net::TestCompletionCallback client_connect_cb;
391 DeleteOnConnected host_delete(&message_loop_, &host_pseudotcp_); 392 DeleteOnConnected host_delete(&message_loop_, &host_pseudotcp_);
392 393
393 host_pseudotcp_->Connect(base::Bind(&DeleteOnConnected::OnConnected, 394 host_pseudotcp_->Connect(base::Bind(&DeleteOnConnected::OnConnected,
394 base::Unretained(&host_delete))); 395 base::Unretained(&host_delete)));
395 client_pseudotcp_->Connect(client_connect_cb.callback()); 396 client_pseudotcp_->Connect(client_connect_cb.callback());
396 message_loop_.Run(); 397 base::RunLoop().Run();
397 398
398 ASSERT_EQ(NULL, host_pseudotcp_.get()); 399 ASSERT_EQ(NULL, host_pseudotcp_.get());
399 } 400 }
400 401
401 // Verify that we can send/receive data with the write-waits-for-send 402 // Verify that we can send/receive data with the write-waits-for-send
402 // flag set. 403 // flag set.
403 TEST_F(PseudoTcpAdapterTest, WriteWaitsForSendLetsDataThrough) { 404 TEST_F(PseudoTcpAdapterTest, WriteWaitsForSendLetsDataThrough) {
404 net::TestCompletionCallback host_connect_cb; 405 net::TestCompletionCallback host_connect_cb;
405 net::TestCompletionCallback client_connect_cb; 406 net::TestCompletionCallback client_connect_cb;
406 407
(...skipping 12 matching lines...) Expand all
419 if (rv2 == net::ERR_IO_PENDING) 420 if (rv2 == net::ERR_IO_PENDING)
420 rv2 = client_connect_cb.WaitForResult(); 421 rv2 = client_connect_cb.WaitForResult();
421 ASSERT_EQ(net::OK, rv1); 422 ASSERT_EQ(net::OK, rv1);
422 ASSERT_EQ(net::OK, rv2); 423 ASSERT_EQ(net::OK, rv2);
423 424
424 scoped_refptr<TCPChannelTester> tester = 425 scoped_refptr<TCPChannelTester> tester =
425 new TCPChannelTester(&message_loop_, host_pseudotcp_.get(), 426 new TCPChannelTester(&message_loop_, host_pseudotcp_.get(),
426 client_pseudotcp_.get()); 427 client_pseudotcp_.get());
427 428
428 tester->Start(); 429 tester->Start();
429 message_loop_.Run(); 430 base::RunLoop().Run();
430 tester->CheckResults(); 431 tester->CheckResults();
431 } 432 }
432 433
433 } // namespace 434 } // namespace
434 435
435 } // namespace protocol 436 } // namespace protocol
436 } // namespace remoting 437 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/chromium_socket_factory_unittest.cc ('k') | remoting/protocol/spake2_authenticator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698