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

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

Issue 1475553002: Remove ScopedVector from CreateSockets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove {} Created 5 years 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
« no previous file with comments | « net/dns/mdns_client_impl.cc ('k') | net/dns/mock_mdns_socket_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <queue> 5 #include <queue>
6 #include <vector>
6 7
7 #include "base/location.h" 8 #include "base/location.h"
8 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
10 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
12 #include "base/time/clock.h" 14 #include "base/time/clock.h"
13 #include "base/time/default_clock.h" 15 #include "base/time/default_clock.h"
14 #include "base/timer/mock_timer.h" 16 #include "base/timer/mock_timer.h"
15 #include "net/base/rand_callback.h" 17 #include "net/base/rand_callback.h"
16 #include "net/base/test_completion_callback.h" 18 #include "net/base/test_completion_callback.h"
17 #include "net/dns/mdns_client_impl.h" 19 #include "net/dns/mdns_client_impl.h"
18 #include "net/dns/mock_mdns_socket_factory.h" 20 #include "net/dns/mock_mdns_socket_factory.h"
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 1152
1151 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_REMOVED, _)); 1153 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_REMOVED, _));
1152 1154
1153 RunFor(base::TimeDelta::FromSeconds(6)); 1155 RunFor(base::TimeDelta::FromSeconds(6));
1154 } 1156 }
1155 1157
1156 // Note: These tests assume that the ipv4 socket will always be created first. 1158 // Note: These tests assume that the ipv4 socket will always be created first.
1157 // This is a simplifying assumption based on the way the code works now. 1159 // This is a simplifying assumption based on the way the code works now.
1158 class SimpleMockSocketFactory : public MDnsSocketFactory { 1160 class SimpleMockSocketFactory : public MDnsSocketFactory {
1159 public: 1161 public:
1160 void CreateSockets(ScopedVector<DatagramServerSocket>* sockets) override { 1162 void CreateSockets(
1163 std::vector<scoped_ptr<DatagramServerSocket>>* sockets) override {
1161 sockets->clear(); 1164 sockets->clear();
1162 sockets->swap(sockets_); 1165 sockets->swap(sockets_);
1163 } 1166 }
1164 1167
1165 void PushSocket(DatagramServerSocket* socket) { 1168 void PushSocket(scoped_ptr<DatagramServerSocket> socket) {
1166 sockets_.push_back(socket); 1169 sockets_.push_back(std::move(socket));
1167 } 1170 }
1168 1171
1169 private: 1172 private:
1170 ScopedVector<DatagramServerSocket> sockets_; 1173 std::vector<scoped_ptr<DatagramServerSocket>> sockets_;
1171 }; 1174 };
1172 1175
1173 class MockMDnsConnectionDelegate : public MDnsConnection::Delegate { 1176 class MockMDnsConnectionDelegate : public MDnsConnection::Delegate {
1174 public: 1177 public:
1175 virtual void HandlePacket(DnsResponse* response, int size) { 1178 virtual void HandlePacket(DnsResponse* response, int size) {
1176 HandlePacketInternal(std::string(response->io_buffer()->data(), size)); 1179 HandlePacketInternal(std::string(response->io_buffer()->data(), size));
1177 } 1180 }
1178 1181
1179 MOCK_METHOD1(HandlePacketInternal, void(std::string packet)); 1182 MOCK_METHOD1(HandlePacketInternal, void(std::string packet));
1180 1183
1181 MOCK_METHOD1(OnConnectionError, void(int error)); 1184 MOCK_METHOD1(OnConnectionError, void(int error));
1182 }; 1185 };
1183 1186
1184 class MDnsConnectionTest : public ::testing::Test { 1187 class MDnsConnectionTest : public ::testing::Test {
1185 public: 1188 public:
1186 MDnsConnectionTest() : connection_(&delegate_) { 1189 MDnsConnectionTest() : connection_(&delegate_) {
1187 } 1190 }
1188 1191
1189 protected: 1192 protected:
1190 // Follow successful connection initialization. 1193 // Follow successful connection initialization.
1191 void SetUp() override { 1194 void SetUp() override {
1192 socket_ipv4_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV4); 1195 socket_ipv4_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV4);
1193 socket_ipv6_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV6); 1196 socket_ipv6_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV6);
1194 factory_.PushSocket(socket_ipv6_); 1197 factory_.PushSocket(make_scoped_ptr(socket_ipv6_));
1195 factory_.PushSocket(socket_ipv4_); 1198 factory_.PushSocket(make_scoped_ptr(socket_ipv4_));
1196 sample_packet_ = MakeString(kSamplePacket1, sizeof(kSamplePacket1)); 1199 sample_packet_ = MakeString(kSamplePacket1, sizeof(kSamplePacket1));
1197 sample_buffer_ = new StringIOBuffer(sample_packet_); 1200 sample_buffer_ = new StringIOBuffer(sample_packet_);
1198 } 1201 }
1199 1202
1200 bool InitConnection() { 1203 bool InitConnection() {
1201 return connection_.Init(&factory_); 1204 return connection_.Init(&factory_);
1202 } 1205 }
1203 1206
1204 StrictMock<MockMDnsConnectionDelegate> delegate_; 1207 StrictMock<MockMDnsConnectionDelegate> delegate_;
1205 1208
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 SendToInternal(sample_packet_, "224.0.0.251:5353", _)) 1317 SendToInternal(sample_packet_, "224.0.0.251:5353", _))
1315 .Times(0); 1318 .Times(0);
1316 // Expect call for the second IPv6 packed. 1319 // Expect call for the second IPv6 packed.
1317 EXPECT_CALL(*socket_ipv6_, 1320 EXPECT_CALL(*socket_ipv6_,
1318 SendToInternal(sample_packet_, "[ff02::fb]:5353", _)) 1321 SendToInternal(sample_packet_, "[ff02::fb]:5353", _))
1319 .WillOnce(Return(OK)); 1322 .WillOnce(Return(OK));
1320 callback.Run(OK); 1323 callback.Run(OK);
1321 } 1324 }
1322 1325
1323 } // namespace net 1326 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/mdns_client_impl.cc ('k') | net/dns/mock_mdns_socket_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698