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

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

Issue 132693025: Add the ability for MDnsListener to actively refresh records (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/dns/mdns_client_impl.cc ('k') | no next file » | 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/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "net/base/rand_callback.h" 9 #include "net/base/rand_callback.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // Question 234 // Question
235 // This part is echoed back from the respective query. 235 // This part is echoed back from the respective query.
236 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 236 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't',
237 0x04, '_', 't', 'c', 'p', 237 0x04, '_', 't', 'c', 'p',
238 0x05, 'l', 'o', 'c', 'a', 'l', 238 0x05, 'l', 'o', 'c', 'a', 'l',
239 0x00, 239 0x00,
240 0x00, 0x0c, // TYPE is PTR. 240 0x00, 0x0c, // TYPE is PTR.
241 0x00, 0x01, // CLASS is IN. 241 0x00, 0x01, // CLASS is IN.
242 }; 242 };
243 243
244 const uint8 kQueryPacketPrivetA[] = {
245 // Header
246 0x00, 0x00, // ID is zeroed out
247 0x00, 0x00, // No flags.
248 0x00, 0x01, // One question.
249 0x00, 0x00, // 0 RRs (answers)
250 0x00, 0x00, // 0 authority RRs
251 0x00, 0x00, // 0 additional RRs
252
253 // Question
254 // This part is echoed back from the respective query.
255 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't',
256 0x04, '_', 't', 'c', 'p',
257 0x05, 'l', 'o', 'c', 'a', 'l',
258 0x00,
259 0x00, 0x01, // TYPE is A.
260 0x00, 0x01, // CLASS is IN.
261 };
262
244 const uint8 kSamplePacketAdditionalOnly[] = { 263 const uint8 kSamplePacketAdditionalOnly[] = {
245 // Header 264 // Header
246 0x00, 0x00, // ID is zeroed out 265 0x00, 0x00, // ID is zeroed out
247 0x81, 0x80, // Standard query response, RA, no error 266 0x81, 0x80, // Standard query response, RA, no error
248 0x00, 0x00, // No questions (for simplicity) 267 0x00, 0x00, // No questions (for simplicity)
249 0x00, 0x00, // 2 RRs (answers) 268 0x00, 0x00, // 2 RRs (answers)
250 0x00, 0x00, // 0 authority RRs 269 0x00, 0x00, // 0 authority RRs
251 0x00, 0x01, // 0 additional RRs 270 0x00, 0x01, // 0 additional RRs
252 271
253 // Answer 1 272 // Answer 1
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 0x00, 0x00, // 0 authority RRs 315 0x00, 0x00, // 0 authority RRs
297 0x00, 0x00, // 0 additional RRs 316 0x00, 0x00, // 0 additional RRs
298 317
299 // Answer 1 318 // Answer 1
300 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 319 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't',
301 0x04, '_', 't', 'c', 'p', 320 0x04, '_', 't', 'c', 'p',
302 0x05, 'l', 'o', 'c', 'a', 'l', 321 0x05, 'l', 'o', 'c', 'a', 'l',
303 0x00, 322 0x00,
304 0x00, 0x01, // TYPE is A. 323 0x00, 0x01, // TYPE is A.
305 0x00, 0x01, // CLASS is IN. 324 0x00, 0x01, // CLASS is IN.
306 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. 325 0x00, 0x00, // TTL (4 bytes) is 5 seconds
307 0x24, 0x74, 326 0x00, 0x05,
308 0x00, 0x04, // RDLENGTH is 4 bytes. 327 0x00, 0x04, // RDLENGTH is 4 bytes.
309 0xc0, 0x0c, 328 0xc0, 0x0c,
310 0x00, 0x02, 329 0x00, 0x02,
311 }; 330 };
312 331
313 const uint8 kSamplePacketGoodbye[] = { 332 const uint8 kSamplePacketGoodbye[] = {
314 // Header 333 // Header
315 0x00, 0x00, // ID is zeroed out 334 0x00, 0x00, // ID is zeroed out
316 0x81, 0x80, // Standard query response, RA, no error 335 0x81, 0x80, // Standard query response, RA, no error
317 0x00, 0x00, // No questions (for simplicity) 336 0x00, 0x00, // No questions (for simplicity)
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 EXPECT_CALL(delegate_privet, 1020 EXPECT_CALL(delegate_privet,
1002 OnNsecRecord("_privet._tcp.local", dns_protocol::kTypeA)); 1021 OnNsecRecord("_privet._tcp.local", dns_protocol::kTypeA));
1003 1022
1004 SimulatePacketReceive(kSamplePacketNsec, 1023 SimulatePacketReceive(kSamplePacketNsec,
1005 sizeof(kSamplePacketNsec)); 1024 sizeof(kSamplePacketNsec));
1006 1025
1007 EXPECT_EQ(record1, record2); 1026 EXPECT_EQ(record1, record2);
1008 } 1027 }
1009 1028
1010 1029
1030 TEST_F(MDnsTest, RefreshQuery) {
1031 StrictMock<MockListenerDelegate> delegate_privet;
1032 scoped_ptr<MDnsListener> listener_privet =
1033 test_client_.CreateListener(dns_protocol::kTypeA, "_privet._tcp.local",
1034 &delegate_privet);
1035
1036 listener_privet->SetActiveRefresh(true);
1037 ASSERT_TRUE(listener_privet->Start());
1038
1039 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _));
1040
1041 SimulatePacketReceive(kSamplePacketAPrivet,
1042 sizeof(kSamplePacketAPrivet));
1043
1044 // Expecting 2 calls (one for ipv4 and one for ipv6) at 85% of the TTL and 2
1045 // calls at 95% of the TTL.
szym 2014/01/29 19:08:39 nit: I'd remove the 85% and 95% numbers from this
Noam Samuel 2014/01/29 19:21:36 Done.
1046 EXPECT_CALL(socket_factory_, OnSendTo(
1047 MakeString(kQueryPacketPrivetA, sizeof(kQueryPacketPrivetA))))
1048 .Times(4);
1049
1050 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_REMOVED, _));
1051
1052 RunFor(base::TimeDelta::FromSeconds(6));
1053 }
1054
1011 // Note: These tests assume that the ipv4 socket will always be created first. 1055 // Note: These tests assume that the ipv4 socket will always be created first.
1012 // This is a simplifying assumption based on the way the code works now. 1056 // This is a simplifying assumption based on the way the code works now.
1013 class SimpleMockSocketFactory : public MDnsSocketFactory { 1057 class SimpleMockSocketFactory : public MDnsSocketFactory {
1014 public: 1058 public:
1015 virtual void CreateSockets( 1059 virtual void CreateSockets(
1016 ScopedVector<DatagramServerSocket>* sockets) OVERRIDE { 1060 ScopedVector<DatagramServerSocket>* sockets) OVERRIDE {
1017 sockets->clear(); 1061 sockets->clear();
1018 sockets->swap(sockets_); 1062 sockets->swap(sockets_);
1019 } 1063 }
1020 1064
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 1176
1133 ASSERT_TRUE(InitConnection()); 1177 ASSERT_TRUE(InitConnection());
1134 1178
1135 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED)); 1179 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED));
1136 callback.Run(ERR_SOCKET_NOT_CONNECTED); 1180 callback.Run(ERR_SOCKET_NOT_CONNECTED);
1137 } 1181 }
1138 1182
1139 } // namespace 1183 } // namespace
1140 1184
1141 } // namespace net 1185 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/mdns_client_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698