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

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