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

Side by Side Diff: net/dns/mdns_client_unittest.cc

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <memory> 5 #include <memory>
6 #include <queue> 6 #include <queue>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_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/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/time/clock.h" 17 #include "base/time/clock.h"
17 #include "base/time/default_clock.h" 18 #include "base/time/default_clock.h"
18 #include "base/timer/mock_timer.h" 19 #include "base/timer/mock_timer.h"
19 #include "net/base/ip_address.h" 20 #include "net/base/ip_address.h"
20 #include "net/base/rand_callback.h" 21 #include "net/base/rand_callback.h"
21 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
22 #include "net/dns/mdns_client_impl.h" 23 #include "net/dns/mdns_client_impl.h"
23 #include "net/dns/mock_mdns_socket_factory.h" 24 #include "net/dns/mock_mdns_socket_factory.h"
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 listener1_.reset(); 459 listener1_.reset();
459 listener2_.reset(); 460 listener2_.reset();
460 } 461 }
461 462
462 void MDnsTest::RunFor(base::TimeDelta time_period) { 463 void MDnsTest::RunFor(base::TimeDelta time_period) {
463 base::CancelableCallback<void()> callback(base::Bind(&MDnsTest::Stop, 464 base::CancelableCallback<void()> callback(base::Bind(&MDnsTest::Stop,
464 base::Unretained(this))); 465 base::Unretained(this)));
465 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 466 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
466 FROM_HERE, callback.callback(), time_period); 467 FROM_HERE, callback.callback(), time_period);
467 468
468 base::MessageLoop::current()->Run(); 469 base::RunLoop().Run();
469 callback.Cancel(); 470 callback.Cancel();
470 } 471 }
471 472
472 void MDnsTest::Stop() { 473 void MDnsTest::Stop() {
473 base::MessageLoop::current()->QuitWhenIdle(); 474 base::MessageLoop::current()->QuitWhenIdle();
474 } 475 }
475 476
476 TEST_F(MDnsTest, PassiveListeners) { 477 TEST_F(MDnsTest, PassiveListeners) {
477 StrictMock<MockListenerDelegate> delegate_privet; 478 StrictMock<MockListenerDelegate> delegate_privet;
478 StrictMock<MockListenerDelegate> delegate_printer; 479 StrictMock<MockListenerDelegate> delegate_printer;
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 EXPECT_CALL(*socket_ipv6_, RecvFrom(_, _, _, _)) 1179 EXPECT_CALL(*socket_ipv6_, RecvFrom(_, _, _, _))
1179 .Times(2) 1180 .Times(2)
1180 .WillOnce( 1181 .WillOnce(
1181 Invoke(socket_ipv6_, &MockMDnsDatagramServerSocket::HandleRecvLater)) 1182 Invoke(socket_ipv6_, &MockMDnsDatagramServerSocket::HandleRecvLater))
1182 .WillOnce(Return(ERR_IO_PENDING)); 1183 .WillOnce(Return(ERR_IO_PENDING));
1183 1184
1184 ASSERT_TRUE(InitConnection()); 1185 ASSERT_TRUE(InitConnection());
1185 1186
1186 EXPECT_CALL(delegate_, HandlePacketInternal(sample_packet_)); 1187 EXPECT_CALL(delegate_, HandlePacketInternal(sample_packet_));
1187 1188
1188 base::MessageLoop::current()->RunUntilIdle(); 1189 base::RunLoop().RunUntilIdle();
1189 } 1190 }
1190 1191
1191 TEST_F(MDnsConnectionTest, Error) { 1192 TEST_F(MDnsConnectionTest, Error) {
1192 CompletionCallback callback; 1193 CompletionCallback callback;
1193 1194
1194 EXPECT_CALL(*socket_ipv4_, RecvFrom(_, _, _, _)) 1195 EXPECT_CALL(*socket_ipv4_, RecvFrom(_, _, _, _))
1195 .WillOnce(Return(ERR_IO_PENDING)); 1196 .WillOnce(Return(ERR_IO_PENDING));
1196 EXPECT_CALL(*socket_ipv6_, RecvFrom(_, _, _, _)) 1197 EXPECT_CALL(*socket_ipv6_, RecvFrom(_, _, _, _))
1197 .WillOnce(DoAll(SaveArg<3>(&callback), Return(ERR_IO_PENDING))); 1198 .WillOnce(DoAll(SaveArg<3>(&callback), Return(ERR_IO_PENDING)));
1198 1199
1199 ASSERT_TRUE(InitConnection()); 1200 ASSERT_TRUE(InitConnection());
1200 1201
1201 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED)); 1202 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED));
1202 callback.Run(ERR_SOCKET_NOT_CONNECTED); 1203 callback.Run(ERR_SOCKET_NOT_CONNECTED);
1203 base::MessageLoop::current()->RunUntilIdle(); 1204 base::RunLoop().RunUntilIdle();
1204 } 1205 }
1205 1206
1206 class MDnsConnectionSendTest : public MDnsConnectionTest { 1207 class MDnsConnectionSendTest : public MDnsConnectionTest {
1207 protected: 1208 protected:
1208 void SetUp() override { 1209 void SetUp() override {
1209 MDnsConnectionTest::SetUp(); 1210 MDnsConnectionTest::SetUp();
1210 EXPECT_CALL(*socket_ipv4_, RecvFrom(_, _, _, _)) 1211 EXPECT_CALL(*socket_ipv4_, RecvFrom(_, _, _, _))
1211 .WillOnce(Return(ERR_IO_PENDING)); 1212 .WillOnce(Return(ERR_IO_PENDING));
1212 EXPECT_CALL(*socket_ipv6_, RecvFrom(_, _, _, _)) 1213 EXPECT_CALL(*socket_ipv6_, RecvFrom(_, _, _, _))
1213 .WillOnce(Return(ERR_IO_PENDING)); 1214 .WillOnce(Return(ERR_IO_PENDING));
(...skipping 14 matching lines...) Expand all
1228 CompletionCallback callback; 1229 CompletionCallback callback;
1229 1230
1230 EXPECT_CALL(*socket_ipv4_, 1231 EXPECT_CALL(*socket_ipv4_,
1231 SendToInternal(sample_packet_, "224.0.0.251:5353", _)); 1232 SendToInternal(sample_packet_, "224.0.0.251:5353", _));
1232 EXPECT_CALL(*socket_ipv6_, 1233 EXPECT_CALL(*socket_ipv6_,
1233 SendToInternal(sample_packet_, "[ff02::fb]:5353", _)) 1234 SendToInternal(sample_packet_, "[ff02::fb]:5353", _))
1234 .WillOnce(DoAll(SaveArg<2>(&callback), Return(ERR_SOCKET_NOT_CONNECTED))); 1235 .WillOnce(DoAll(SaveArg<2>(&callback), Return(ERR_SOCKET_NOT_CONNECTED)));
1235 1236
1236 connection_.Send(sample_buffer_, sample_packet_.size()); 1237 connection_.Send(sample_buffer_, sample_packet_.size());
1237 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED)); 1238 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED));
1238 base::MessageLoop::current()->RunUntilIdle(); 1239 base::RunLoop().RunUntilIdle();
1239 } 1240 }
1240 1241
1241 TEST_F(MDnsConnectionSendTest, SendQueued) { 1242 TEST_F(MDnsConnectionSendTest, SendQueued) {
1242 // Send data immediately. 1243 // Send data immediately.
1243 EXPECT_CALL(*socket_ipv4_, 1244 EXPECT_CALL(*socket_ipv4_,
1244 SendToInternal(sample_packet_, "224.0.0.251:5353", _)) 1245 SendToInternal(sample_packet_, "224.0.0.251:5353", _))
1245 .Times(2) 1246 .Times(2)
1246 .WillRepeatedly(Return(OK)); 1247 .WillRepeatedly(Return(OK));
1247 1248
1248 CompletionCallback callback; 1249 CompletionCallback callback;
(...skipping 10 matching lines...) Expand all
1259 SendToInternal(sample_packet_, "224.0.0.251:5353", _)) 1260 SendToInternal(sample_packet_, "224.0.0.251:5353", _))
1260 .Times(0); 1261 .Times(0);
1261 // Expect call for the second IPv6 packed. 1262 // Expect call for the second IPv6 packed.
1262 EXPECT_CALL(*socket_ipv6_, 1263 EXPECT_CALL(*socket_ipv6_,
1263 SendToInternal(sample_packet_, "[ff02::fb]:5353", _)) 1264 SendToInternal(sample_packet_, "[ff02::fb]:5353", _))
1264 .WillOnce(Return(OK)); 1265 .WillOnce(Return(OK));
1265 callback.Run(OK); 1266 callback.Run(OK);
1266 } 1267 }
1267 1268
1268 } // namespace net 1269 } // namespace net
OLDNEW
« no previous file with comments | « net/base/network_change_notifier_win_unittest.cc ('k') | net/http/transport_security_persister_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698