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

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: 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
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 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 1150
1151 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_REMOVED, _)); 1151 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_REMOVED, _));
1152 1152
1153 RunFor(base::TimeDelta::FromSeconds(6)); 1153 RunFor(base::TimeDelta::FromSeconds(6));
1154 } 1154 }
1155 1155
1156 // Note: These tests assume that the ipv4 socket will always be created first. 1156 // 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. 1157 // This is a simplifying assumption based on the way the code works now.
1158 class SimpleMockSocketFactory : public MDnsSocketFactory { 1158 class SimpleMockSocketFactory : public MDnsSocketFactory {
1159 public: 1159 public:
1160 void CreateSockets(ScopedVector<DatagramServerSocket>* sockets) override { 1160 void CreateSockets(
1161 std::vector<scoped_ptr<DatagramServerSocket>>* sockets) override {
mmenke 2015/11/24 17:39:33 include vector, scoped_ptr
1161 sockets->clear(); 1162 sockets->clear();
1162 sockets->swap(sockets_); 1163 sockets->swap(sockets_);
1163 } 1164 }
1164 1165
1165 void PushSocket(DatagramServerSocket* socket) { 1166 void PushSocket(scoped_ptr<DatagramServerSocket> socket) {
1166 sockets_.push_back(socket); 1167 sockets_.push_back(std::move(socket));
1167 } 1168 }
1168 1169
1169 private: 1170 private:
1170 ScopedVector<DatagramServerSocket> sockets_; 1171 std::vector<scoped_ptr<DatagramServerSocket>> sockets_;
1171 }; 1172 };
1172 1173
1173 class MockMDnsConnectionDelegate : public MDnsConnection::Delegate { 1174 class MockMDnsConnectionDelegate : public MDnsConnection::Delegate {
1174 public: 1175 public:
1175 virtual void HandlePacket(DnsResponse* response, int size) { 1176 virtual void HandlePacket(DnsResponse* response, int size) {
1176 HandlePacketInternal(std::string(response->io_buffer()->data(), size)); 1177 HandlePacketInternal(std::string(response->io_buffer()->data(), size));
1177 } 1178 }
1178 1179
1179 MOCK_METHOD1(HandlePacketInternal, void(std::string packet)); 1180 MOCK_METHOD1(HandlePacketInternal, void(std::string packet));
1180 1181
1181 MOCK_METHOD1(OnConnectionError, void(int error)); 1182 MOCK_METHOD1(OnConnectionError, void(int error));
1182 }; 1183 };
1183 1184
1184 class MDnsConnectionTest : public ::testing::Test { 1185 class MDnsConnectionTest : public ::testing::Test {
1185 public: 1186 public:
1186 MDnsConnectionTest() : connection_(&delegate_) { 1187 MDnsConnectionTest() : connection_(&delegate_) {
1187 } 1188 }
1188 1189
1189 protected: 1190 protected:
1190 // Follow successful connection initialization. 1191 // Follow successful connection initialization.
1191 void SetUp() override { 1192 void SetUp() override {
1192 socket_ipv4_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV4); 1193 socket_ipv4_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV4);
1193 socket_ipv6_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV6); 1194 socket_ipv6_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV6);
1194 factory_.PushSocket(socket_ipv6_); 1195 factory_.PushSocket(make_scoped_ptr(socket_ipv6_));
1195 factory_.PushSocket(socket_ipv4_); 1196 factory_.PushSocket(make_scoped_ptr(socket_ipv4_));
1196 sample_packet_ = MakeString(kSamplePacket1, sizeof(kSamplePacket1)); 1197 sample_packet_ = MakeString(kSamplePacket1, sizeof(kSamplePacket1));
1197 sample_buffer_ = new StringIOBuffer(sample_packet_); 1198 sample_buffer_ = new StringIOBuffer(sample_packet_);
1198 } 1199 }
1199 1200
1200 bool InitConnection() { 1201 bool InitConnection() {
1201 return connection_.Init(&factory_); 1202 return connection_.Init(&factory_);
1202 } 1203 }
1203 1204
1204 StrictMock<MockMDnsConnectionDelegate> delegate_; 1205 StrictMock<MockMDnsConnectionDelegate> delegate_;
1205 1206
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 SendToInternal(sample_packet_, "224.0.0.251:5353", _)) 1315 SendToInternal(sample_packet_, "224.0.0.251:5353", _))
1315 .Times(0); 1316 .Times(0);
1316 // Expect call for the second IPv6 packed. 1317 // Expect call for the second IPv6 packed.
1317 EXPECT_CALL(*socket_ipv6_, 1318 EXPECT_CALL(*socket_ipv6_,
1318 SendToInternal(sample_packet_, "[ff02::fb]:5353", _)) 1319 SendToInternal(sample_packet_, "[ff02::fb]:5353", _))
1319 .WillOnce(Return(OK)); 1320 .WillOnce(Return(OK));
1320 callback.Run(OK); 1321 callback.Run(OK);
1321 } 1322 }
1322 1323
1323 } // namespace net 1324 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698