Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 EXPECT_CALL(socket_factory_, OnSendTo( | |
| 1045 MakeString(kQueryPacketPrivetA, sizeof(kQueryPacketPrivetA)))) | |
| 1046 .Times(4); | |
|
szym
2014/01/23 11:24:03
Add comment explaining why 4.
Noam Samuel
2014/01/23 17:50:42
Done.
| |
| 1047 | |
| 1048 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_REMOVED, _)); | |
| 1049 | |
| 1050 RunFor(base::TimeDelta::FromSeconds(6)); | |
| 1051 } | |
| 1052 | |
| 1011 // Note: These tests assume that the ipv4 socket will always be created first. | 1053 // 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. | 1054 // This is a simplifying assumption based on the way the code works now. |
| 1013 class SimpleMockSocketFactory : public MDnsSocketFactory { | 1055 class SimpleMockSocketFactory : public MDnsSocketFactory { |
| 1014 public: | 1056 public: |
| 1015 virtual void CreateSockets( | 1057 virtual void CreateSockets( |
| 1016 ScopedVector<DatagramServerSocket>* sockets) OVERRIDE { | 1058 ScopedVector<DatagramServerSocket>* sockets) OVERRIDE { |
| 1017 sockets->clear(); | 1059 sockets->clear(); |
| 1018 sockets->swap(sockets_); | 1060 sockets->swap(sockets_); |
| 1019 } | 1061 } |
| 1020 | 1062 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1132 | 1174 |
| 1133 ASSERT_TRUE(InitConnection()); | 1175 ASSERT_TRUE(InitConnection()); |
| 1134 | 1176 |
| 1135 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED)); | 1177 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED)); |
| 1136 callback.Run(ERR_SOCKET_NOT_CONNECTED); | 1178 callback.Run(ERR_SOCKET_NOT_CONNECTED); |
| 1137 } | 1179 } |
| 1138 | 1180 |
| 1139 } // namespace | 1181 } // namespace |
| 1140 | 1182 |
| 1141 } // namespace net | 1183 } // namespace net |
| OLD | NEW |