| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> |
| 6 |
| 5 #include "base/location.h" | 7 #include "base/location.h" |
| 6 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 7 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 8 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 9 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 10 #include "chrome/common/local_discovery/service_discovery_client_impl.h" | 12 #include "chrome/common/local_discovery/service_discovery_client_impl.h" |
| 11 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 12 #include "net/dns/dns_protocol.h" | 14 #include "net/dns/dns_protocol.h" |
| 13 #include "net/dns/mdns_client_impl.h" | 15 #include "net/dns/mdns_client_impl.h" |
| 14 #include "net/dns/mock_mdns_socket_factory.h" | 16 #include "net/dns/mock_mdns_socket_factory.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 using ::testing::_; | 20 using ::testing::_; |
| 19 using ::testing::Invoke; | 21 using ::testing::Invoke; |
| 20 using ::testing::StrictMock; | 22 using ::testing::StrictMock; |
| 21 using ::testing::NiceMock; | 23 using ::testing::NiceMock; |
| 22 using ::testing::Mock; | 24 using ::testing::Mock; |
| 23 using ::testing::SaveArg; | 25 using ::testing::SaveArg; |
| 24 using ::testing::SetArgPointee; | 26 using ::testing::SetArgPointee; |
| 25 using ::testing::Return; | 27 using ::testing::Return; |
| 26 using ::testing::Exactly; | 28 using ::testing::Exactly; |
| 27 | 29 |
| 28 namespace local_discovery { | 30 namespace local_discovery { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 const uint8 kSamplePacketPTR[] = { | 34 const uint8_t kSamplePacketPTR[] = { |
| 33 // Header | 35 // Header |
| 34 0x00, 0x00, // ID is zeroed out | 36 0x00, 0x00, // ID is zeroed out |
| 35 0x81, 0x80, // Standard query response, RA, no error | 37 0x81, 0x80, // Standard query response, RA, no error |
| 36 0x00, 0x00, // No questions (for simplicity) | 38 0x00, 0x00, // No questions (for simplicity) |
| 37 0x00, 0x01, // 1 RR (answers) | 39 0x00, 0x01, // 1 RR (answers) |
| 38 0x00, 0x00, // 0 authority RRs | 40 0x00, 0x00, // 0 authority RRs |
| 39 0x00, 0x00, // 0 additional RRs | 41 0x00, 0x00, // 0 additional RRs |
| 40 | 42 |
| 41 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 43 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', |
| 42 0x04, '_', 't', 'c', 'p', | 44 0x04, '_', 't', 'c', 'p', |
| 43 0x05, 'l', 'o', 'c', 'a', 'l', | 45 0x05, 'l', 'o', 'c', 'a', 'l', |
| 44 0x00, | 46 0x00, |
| 45 0x00, 0x0c, // TYPE is PTR. | 47 0x00, 0x0c, // TYPE is PTR. |
| 46 0x00, 0x01, // CLASS is IN. | 48 0x00, 0x01, // CLASS is IN. |
| 47 0x00, 0x00, // TTL (4 bytes) is 1 second. | 49 0x00, 0x00, // TTL (4 bytes) is 1 second. |
| 48 0x00, 0x01, | 50 0x00, 0x01, |
| 49 0x00, 0x08, // RDLENGTH is 8 bytes. | 51 0x00, 0x08, // RDLENGTH is 8 bytes. |
| 50 0x05, 'h', 'e', 'l', 'l', 'o', | 52 0x05, 'h', 'e', 'l', 'l', 'o', |
| 51 0xc0, 0x0c | 53 0xc0, 0x0c |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 const uint8 kSamplePacketSRV[] = { | 56 const uint8_t kSamplePacketSRV[] = { |
| 55 // Header | 57 // Header |
| 56 0x00, 0x00, // ID is zeroed out | 58 0x00, 0x00, // ID is zeroed out |
| 57 0x81, 0x80, // Standard query response, RA, no error | 59 0x81, 0x80, // Standard query response, RA, no error |
| 58 0x00, 0x00, // No questions (for simplicity) | 60 0x00, 0x00, // No questions (for simplicity) |
| 59 0x00, 0x01, // 1 RR (answers) | 61 0x00, 0x01, // 1 RR (answers) |
| 60 0x00, 0x00, // 0 authority RRs | 62 0x00, 0x00, // 0 authority RRs |
| 61 0x00, 0x00, // 0 additional RRs | 63 0x00, 0x00, // 0 additional RRs |
| 62 | 64 |
| 63 0x05, 'h', 'e', 'l', 'l', 'o', | 65 0x05, 'h', 'e', 'l', 'l', 'o', |
| 64 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 66 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', |
| 65 0x04, '_', 't', 'c', 'p', | 67 0x04, '_', 't', 'c', 'p', |
| 66 0x05, 'l', 'o', 'c', 'a', 'l', | 68 0x05, 'l', 'o', 'c', 'a', 'l', |
| 67 0x00, | 69 0x00, |
| 68 0x00, 0x21, // TYPE is SRV. | 70 0x00, 0x21, // TYPE is SRV. |
| 69 0x00, 0x01, // CLASS is IN. | 71 0x00, 0x01, // CLASS is IN. |
| 70 0x00, 0x00, // TTL (4 bytes) is 1 second. | 72 0x00, 0x00, // TTL (4 bytes) is 1 second. |
| 71 0x00, 0x01, | 73 0x00, 0x01, |
| 72 0x00, 0x15, // RDLENGTH is 21 bytes. | 74 0x00, 0x15, // RDLENGTH is 21 bytes. |
| 73 0x00, 0x00, | 75 0x00, 0x00, |
| 74 0x00, 0x00, | 76 0x00, 0x00, |
| 75 0x22, 0xb8, // port 8888 | 77 0x22, 0xb8, // port 8888 |
| 76 0x07, 'm', 'y', 'h', 'e', 'l', 'l', 'o', | 78 0x07, 'm', 'y', 'h', 'e', 'l', 'l', 'o', |
| 77 0x05, 'l', 'o', 'c', 'a', 'l', | 79 0x05, 'l', 'o', 'c', 'a', 'l', |
| 78 0x00, | 80 0x00, |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 const uint8 kSamplePacketTXT[] = { | 83 const uint8_t kSamplePacketTXT[] = { |
| 82 // Header | 84 // Header |
| 83 0x00, 0x00, // ID is zeroed out | 85 0x00, 0x00, // ID is zeroed out |
| 84 0x81, 0x80, // Standard query response, RA, no error | 86 0x81, 0x80, // Standard query response, RA, no error |
| 85 0x00, 0x00, // No questions (for simplicity) | 87 0x00, 0x00, // No questions (for simplicity) |
| 86 0x00, 0x01, // 1 RR (answers) | 88 0x00, 0x01, // 1 RR (answers) |
| 87 0x00, 0x00, // 0 authority RRs | 89 0x00, 0x00, // 0 authority RRs |
| 88 0x00, 0x00, // 0 additional RRs | 90 0x00, 0x00, // 0 additional RRs |
| 89 | 91 |
| 90 0x05, 'h', 'e', 'l', 'l', 'o', | 92 0x05, 'h', 'e', 'l', 'l', 'o', |
| 91 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 93 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', |
| 92 0x04, '_', 't', 'c', 'p', | 94 0x04, '_', 't', 'c', 'p', |
| 93 0x05, 'l', 'o', 'c', 'a', 'l', | 95 0x05, 'l', 'o', 'c', 'a', 'l', |
| 94 0x00, | 96 0x00, |
| 95 0x00, 0x10, // TYPE is PTR. | 97 0x00, 0x10, // TYPE is PTR. |
| 96 0x00, 0x01, // CLASS is IN. | 98 0x00, 0x01, // CLASS is IN. |
| 97 0x00, 0x00, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. | 99 0x00, 0x00, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. |
| 98 0x00, 0x01, | 100 0x00, 0x01, |
| 99 0x00, 0x06, // RDLENGTH is 21 bytes. | 101 0x00, 0x06, // RDLENGTH is 21 bytes. |
| 100 0x05, 'h', 'e', 'l', 'l', 'o' | 102 0x05, 'h', 'e', 'l', 'l', 'o' |
| 101 }; | 103 }; |
| 102 | 104 |
| 103 const uint8 kSamplePacketSRVA[] = { | 105 const uint8_t kSamplePacketSRVA[] = { |
| 104 // Header | 106 // Header |
| 105 0x00, 0x00, // ID is zeroed out | 107 0x00, 0x00, // ID is zeroed out |
| 106 0x81, 0x80, // Standard query response, RA, no error | 108 0x81, 0x80, // Standard query response, RA, no error |
| 107 0x00, 0x00, // No questions (for simplicity) | 109 0x00, 0x00, // No questions (for simplicity) |
| 108 0x00, 0x02, // 2 RR (answers) | 110 0x00, 0x02, // 2 RR (answers) |
| 109 0x00, 0x00, // 0 authority RRs | 111 0x00, 0x00, // 0 authority RRs |
| 110 0x00, 0x00, // 0 additional RRs | 112 0x00, 0x00, // 0 additional RRs |
| 111 | 113 |
| 112 0x05, 'h', 'e', 'l', 'l', 'o', | 114 0x05, 'h', 'e', 'l', 'l', 'o', |
| 113 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 115 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', |
| (...skipping 17 matching lines...) Expand all Loading... |
| 131 0x00, | 133 0x00, |
| 132 0x00, 0x01, // TYPE is A. | 134 0x00, 0x01, // TYPE is A. |
| 133 0x00, 0x01, // CLASS is IN. | 135 0x00, 0x01, // CLASS is IN. |
| 134 0x00, 0x00, // TTL (4 bytes) is 16 seconds. | 136 0x00, 0x00, // TTL (4 bytes) is 16 seconds. |
| 135 0x00, 0x10, | 137 0x00, 0x10, |
| 136 0x00, 0x04, // RDLENGTH is 4 bytes. | 138 0x00, 0x04, // RDLENGTH is 4 bytes. |
| 137 0x01, 0x02, | 139 0x01, 0x02, |
| 138 0x03, 0x04, | 140 0x03, 0x04, |
| 139 }; | 141 }; |
| 140 | 142 |
| 141 const uint8 kSamplePacketPTR2[] = { | 143 const uint8_t kSamplePacketPTR2[] = { |
| 142 // Header | 144 // Header |
| 143 0x00, 0x00, // ID is zeroed out | 145 0x00, 0x00, // ID is zeroed out |
| 144 0x81, 0x80, // Standard query response, RA, no error | 146 0x81, 0x80, // Standard query response, RA, no error |
| 145 0x00, 0x00, // No questions (for simplicity) | 147 0x00, 0x00, // No questions (for simplicity) |
| 146 0x00, 0x02, // 2 RR (answers) | 148 0x00, 0x02, // 2 RR (answers) |
| 147 0x00, 0x00, // 0 authority RRs | 149 0x00, 0x00, // 0 authority RRs |
| 148 0x00, 0x00, // 0 additional RRs | 150 0x00, 0x00, // 0 additional RRs |
| 149 | 151 |
| 150 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', | 152 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', |
| 151 0x04, '_', 't', 'c', 'p', | 153 0x04, '_', 't', 'c', 'p', |
| (...skipping 13 matching lines...) Expand all Loading... |
| 165 0x00, | 167 0x00, |
| 166 0x00, 0x0c, // TYPE is PTR. | 168 0x00, 0x0c, // TYPE is PTR. |
| 167 0x00, 0x01, // CLASS is IN. | 169 0x00, 0x01, // CLASS is IN. |
| 168 0x02, 0x00, // TTL (4 bytes) is 1 second. | 170 0x02, 0x00, // TTL (4 bytes) is 1 second. |
| 169 0x00, 0x01, | 171 0x00, 0x01, |
| 170 0x00, 0x08, // RDLENGTH is 8 bytes. | 172 0x00, 0x08, // RDLENGTH is 8 bytes. |
| 171 0x05, 'h', 'e', 'l', 'l', 'o', | 173 0x05, 'h', 'e', 'l', 'l', 'o', |
| 172 0xc0, 0x0c | 174 0xc0, 0x0c |
| 173 }; | 175 }; |
| 174 | 176 |
| 175 const uint8 kSamplePacketQuerySRV[] = { | 177 const uint8_t kSamplePacketQuerySRV[] = { |
| 176 // Header | 178 // Header |
| 177 0x00, 0x00, // ID is zeroed out | 179 0x00, 0x00, // ID is zeroed out |
| 178 0x00, 0x00, // No flags. | 180 0x00, 0x00, // No flags. |
| 179 0x00, 0x01, // One question. | 181 0x00, 0x01, // One question. |
| 180 0x00, 0x00, // 0 RRs (answers) | 182 0x00, 0x00, // 0 RRs (answers) |
| 181 0x00, 0x00, // 0 authority RRs | 183 0x00, 0x00, // 0 authority RRs |
| 182 0x00, 0x00, // 0 additional RRs | 184 0x00, 0x00, // 0 additional RRs |
| 183 | 185 |
| 184 // Question | 186 // Question |
| 185 0x05, 'h', 'e', 'l', 'l', 'o', | 187 0x05, 'h', 'e', 'l', 'l', 'o', |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 ServiceResolver::STATUS_REQUEST_TIMEOUT, _, _, _)); | 511 ServiceResolver::STATUS_REQUEST_TIMEOUT, _, _, _)); |
| 510 | 512 |
| 511 // TODO(noamsml): When NSEC record support is added, change this to use an | 513 // TODO(noamsml): When NSEC record support is added, change this to use an |
| 512 // NSEC record. | 514 // NSEC record. |
| 513 RunFor(base::TimeDelta::FromSeconds(4)); | 515 RunFor(base::TimeDelta::FromSeconds(4)); |
| 514 }; | 516 }; |
| 515 | 517 |
| 516 } // namespace | 518 } // namespace |
| 517 | 519 |
| 518 } // namespace local_discovery | 520 } // namespace local_discovery |
| OLD | NEW |