OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "net/dns/dns_response.h" | 8 #include "net/dns/dns_response.h" |
9 #include "net/dns/dns_test_util.h" | 9 #include "net/dns/dns_test_util.h" |
10 #include "net/dns/mdns_cache.h" | 10 #include "net/dns/mdns_cache.h" |
11 #include "net/dns/record_parsed.h" | 11 #include "net/dns/record_parsed.h" |
12 #include "net/dns/record_rdata.h" | 12 #include "net/dns/record_rdata.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using ::testing::Return; | 16 using ::testing::Return; |
17 using ::testing::StrictMock; | 17 using ::testing::StrictMock; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 static const uint8 kTestResponsesDifferentAnswers[] = { | 21 static const uint8_t kTestResponsesDifferentAnswers[] = { |
22 // Answer 1 | 22 // Answer 1 |
23 // ghs.l.google.com in DNS format. | 23 // ghs.l.google.com in DNS format. |
24 3, 'g', 'h', 's', | 24 3, 'g', 'h', 's', 1, 'l', 6, 'g', 'o', 'o', 'g', 'l', 'e', 3, 'c', 'o', 'm', |
25 1, 'l', | 25 0x00, 0x00, 0x01, // TYPE is A. |
26 6, 'g', 'o', 'o', 'g', 'l', 'e', | 26 0x00, 0x01, // CLASS is IN. |
27 3, 'c', 'o', 'm', | 27 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. |
28 0x00, | 28 0, 4, // RDLENGTH is 4 bytes. |
29 0x00, 0x01, // TYPE is A. | 29 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 |
30 0x00, 0x01, // CLASS is IN. | |
31 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. | |
32 0, 4, // RDLENGTH is 4 bytes. | |
33 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 | |
34 | 30 |
35 // Answer 2 | 31 // Answer 2 |
36 // Pointer to answer 1 | 32 // Pointer to answer 1 |
37 0xc0, 0x00, | 33 0xc0, 0x00, 0x00, 0x01, // TYPE is A. |
38 0x00, 0x01, // TYPE is A. | 34 0x00, 0x01, // CLASS is IN. |
39 0x00, 0x01, // CLASS is IN. | 35 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. |
40 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. | 36 0, 4, // RDLENGTH is 4 bytes. |
41 0, 4, // RDLENGTH is 4 bytes. | 37 74, 125, 95, 122, // RDATA is the IP: 74.125.95.122 |
42 74, 125, 95, 122, // RDATA is the IP: 74.125.95.122 | |
43 }; | 38 }; |
44 | 39 |
45 static const uint8 kTestResponsesSameAnswers[] = { | 40 static const uint8_t kTestResponsesSameAnswers[] = { |
46 // Answer 1 | 41 // Answer 1 |
47 // ghs.l.google.com in DNS format. | 42 // ghs.l.google.com in DNS format. |
48 3, 'g', 'h', 's', | 43 3, 'g', 'h', 's', 1, 'l', 6, 'g', 'o', 'o', 'g', 'l', 'e', 3, 'c', 'o', 'm', |
49 1, 'l', | 44 0x00, 0x00, 0x01, // TYPE is A. |
50 6, 'g', 'o', 'o', 'g', 'l', 'e', | 45 0x00, 0x01, // CLASS is IN. |
51 3, 'c', 'o', 'm', | 46 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. |
52 0x00, | 47 0, 4, // RDLENGTH is 4 bytes. |
53 0x00, 0x01, // TYPE is A. | 48 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 |
54 0x00, 0x01, // CLASS is IN. | |
55 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. | |
56 0, 4, // RDLENGTH is 4 bytes. | |
57 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 | |
58 | 49 |
59 // Answer 2 | 50 // Answer 2 |
60 // Pointer to answer 1 | 51 // Pointer to answer 1 |
61 0xc0, 0x00, | 52 0xc0, 0x00, 0x00, 0x01, // TYPE is A. |
62 0x00, 0x01, // TYPE is A. | 53 0x00, 0x01, // CLASS is IN. |
63 0x00, 0x01, // CLASS is IN. | 54 0, 0, 0, 112, // TTL (4 bytes) is 112 seconds. |
64 0, 0, 0, 112, // TTL (4 bytes) is 112 seconds. | 55 0, 4, // RDLENGTH is 4 bytes. |
65 0, 4, // RDLENGTH is 4 bytes. | 56 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 |
66 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 | |
67 }; | 57 }; |
68 | 58 |
69 static const uint8 kTestResponseTwoRecords[] = { | 59 static const uint8_t kTestResponseTwoRecords[] = { |
70 // Answer 1 | 60 // Answer 1 |
71 // ghs.l.google.com in DNS format. (A) | 61 // ghs.l.google.com in DNS format. (A) |
72 3, 'g', 'h', 's', | 62 3, 'g', 'h', 's', 1, 'l', 6, 'g', 'o', 'o', 'g', 'l', 'e', 3, 'c', 'o', 'm', |
73 1, 'l', | 63 0x00, 0x00, 0x01, // TYPE is A. |
74 6, 'g', 'o', 'o', 'g', 'l', 'e', | 64 0x00, 0x01, // CLASS is IN. |
75 3, 'c', 'o', 'm', | 65 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. |
76 0x00, | 66 0, 4, // RDLENGTH is 4 bytes. |
77 0x00, 0x01, // TYPE is A. | 67 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 |
78 0x00, 0x01, // CLASS is IN. | |
79 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. | |
80 0, 4, // RDLENGTH is 4 bytes. | |
81 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 | |
82 | 68 |
83 // Answer 2 | 69 // Answer 2 |
84 // ghs.l.google.com in DNS format. (AAAA) | 70 // ghs.l.google.com in DNS format. (AAAA) |
85 3, 'g', 'h', 's', | 71 3, 'g', 'h', 's', 1, 'l', 6, 'g', 'o', 'o', 'g', 'l', 'e', 3, 'c', 'o', 'm', |
86 1, 'l', | 72 0x00, 0x00, 0x1c, // TYPE is AAA. |
87 6, 'g', 'o', 'o', 'g', 'l', 'e', | 73 0x00, 0x01, // CLASS is IN. |
88 3, 'c', 'o', 'm', | 74 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. |
89 0x00, | 75 0, 16, // RDLENGTH is 16 bytes. |
90 0x00, 0x1c, // TYPE is AAA. | 76 0x4a, 0x7d, 0x4a, 0x7d, 0x5f, 0x79, 0x5f, 0x79, 0x5f, 0x79, 0x5f, 0x79, |
91 0x00, 0x01, // CLASS is IN. | 77 0x5f, 0x79, 0x5f, 0x79, |
92 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. | |
93 0, 16, // RDLENGTH is 16 bytes. | |
94 0x4a, 0x7d, 0x4a, 0x7d, | |
95 0x5f, 0x79, 0x5f, 0x79, | |
96 0x5f, 0x79, 0x5f, 0x79, | |
97 0x5f, 0x79, 0x5f, 0x79, | |
98 }; | 78 }; |
99 | 79 |
100 static const uint8 kTestResponsesGoodbyePacket[] = { | 80 static const uint8_t kTestResponsesGoodbyePacket[] = { |
101 // Answer 1 | 81 // Answer 1 |
102 // ghs.l.google.com in DNS format. (Goodbye packet) | 82 // ghs.l.google.com in DNS format. (Goodbye packet) |
103 3, 'g', 'h', 's', | 83 3, 'g', 'h', 's', 1, 'l', 6, 'g', 'o', 'o', 'g', 'l', 'e', 3, 'c', 'o', 'm', |
104 1, 'l', | 84 0x00, 0x00, 0x01, // TYPE is A. |
105 6, 'g', 'o', 'o', 'g', 'l', 'e', | 85 0x00, 0x01, // CLASS is IN. |
106 3, 'c', 'o', 'm', | 86 0, 0, 0, 0, // TTL (4 bytes) is zero. |
107 0x00, | 87 0, 4, // RDLENGTH is 4 bytes. |
108 0x00, 0x01, // TYPE is A. | 88 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 |
109 0x00, 0x01, // CLASS is IN. | |
110 0, 0, 0, 0, // TTL (4 bytes) is zero. | |
111 0, 4, // RDLENGTH is 4 bytes. | |
112 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 | |
113 | 89 |
114 // Answer 2 | 90 // Answer 2 |
115 // ghs.l.google.com in DNS format. | 91 // ghs.l.google.com in DNS format. |
116 3, 'g', 'h', 's', | 92 3, 'g', 'h', 's', 1, 'l', 6, 'g', 'o', 'o', 'g', 'l', 'e', 3, 'c', 'o', 'm', |
117 1, 'l', | 93 0x00, 0x00, 0x01, // TYPE is A. |
118 6, 'g', 'o', 'o', 'g', 'l', 'e', | 94 0x00, 0x01, // CLASS is IN. |
119 3, 'c', 'o', 'm', | 95 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. |
120 0x00, | 96 0, 4, // RDLENGTH is 4 bytes. |
121 0x00, 0x01, // TYPE is A. | 97 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 |
122 0x00, 0x01, // CLASS is IN. | |
123 0, 0, 0, 53, // TTL (4 bytes) is 53 seconds. | |
124 0, 4, // RDLENGTH is 4 bytes. | |
125 74, 125, 95, 121, // RDATA is the IP: 74.125.95.121 | |
126 }; | 98 }; |
127 | 99 |
128 class RecordRemovalMock { | 100 class RecordRemovalMock { |
129 public: | 101 public: |
130 MOCK_METHOD1(OnRecordRemoved, void(const RecordParsed*)); | 102 MOCK_METHOD1(OnRecordRemoved, void(const RecordParsed*)); |
131 }; | 103 }; |
132 | 104 |
133 class MDnsCacheTest : public ::testing::Test { | 105 class MDnsCacheTest : public ::testing::Test { |
134 public: | 106 public: |
135 MDnsCacheTest() | 107 MDnsCacheTest() |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 338 |
367 EXPECT_EQ(record_out.get(), results.front()); | 339 EXPECT_EQ(record_out.get(), results.front()); |
368 | 340 |
369 cache_.FindDnsRecords(dns_protocol::kTypeCNAME, "codereview.chromium.org", | 341 cache_.FindDnsRecords(dns_protocol::kTypeCNAME, "codereview.chromium.org", |
370 &results, default_time_); | 342 &results, default_time_); |
371 | 343 |
372 EXPECT_EQ(0u, results.size()); | 344 EXPECT_EQ(0u, results.size()); |
373 } | 345 } |
374 | 346 |
375 } // namespace net | 347 } // namespace net |
OLD | NEW |