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

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

Issue 1485853003: Revert of Remove kuint16max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint2
Patch Set: 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/dns_session.cc ('k') | net/test/spawned_test_server/base_test_server.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/dns/dns_transaction.h" 5 #include "net/dns/dns_transaction.h"
6 6
7 #include <stdint.h>
8
9 #include <limits>
10
11 #include "base/bind.h" 7 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
13 #include "base/rand_util.h" 9 #include "base/rand_util.h"
14 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
15 #include "base/test/test_timeouts.h" 11 #include "base/test/test_timeouts.h"
16 #include "net/dns/dns_protocol.h" 12 #include "net/dns/dns_protocol.h"
17 #include "net/dns/dns_query.h" 13 #include "net/dns/dns_query.h"
18 #include "net/dns/dns_response.h" 14 #include "net/dns/dns_response.h"
19 #include "net/dns/dns_session.h" 15 #include "net/dns/dns_session.h"
20 #include "net/dns/dns_test_util.h" 16 #include "net/dns/dns_test_util.h"
21 #include "net/dns/dns_util.h" 17 #include "net/dns/dns_util.h"
22 #include "net/log/net_log.h" 18 #include "net/log/net_log.h"
23 #include "net/socket/socket_test_util.h" 19 #include "net/socket/socket_test_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
25 21
26 namespace net { 22 namespace net {
27 23
28 namespace { 24 namespace {
29 25
30 std::string DomainFromDot(const base::StringPiece& dotted) { 26 std::string DomainFromDot(const base::StringPiece& dotted) {
31 std::string out; 27 std::string out;
32 EXPECT_TRUE(DNSDomainFromDot(dotted, &out)); 28 EXPECT_TRUE(DNSDomainFromDot(dotted, &out));
33 return out; 29 return out;
34 } 30 }
35 31
36 // A SocketDataProvider builder. 32 // A SocketDataProvider builder.
37 class DnsSocketData { 33 class DnsSocketData {
38 public: 34 public:
39 // The ctor takes parameters for the DnsQuery. 35 // The ctor takes parameters for the DnsQuery.
40 DnsSocketData(uint16_t id, 36 DnsSocketData(uint16 id,
41 const char* dotted_name, 37 const char* dotted_name,
42 uint16_t qtype, 38 uint16 qtype,
43 IoMode mode, 39 IoMode mode,
44 bool use_tcp) 40 bool use_tcp)
45 : query_(new DnsQuery(id, DomainFromDot(dotted_name), qtype)), 41 : query_(new DnsQuery(id, DomainFromDot(dotted_name), qtype)),
46 use_tcp_(use_tcp) { 42 use_tcp_(use_tcp) {
47 if (use_tcp_) { 43 if (use_tcp_) {
48 scoped_ptr<uint16_t> length(new uint16_t); 44 scoped_ptr<uint16> length(new uint16);
49 *length = base::HostToNet16(query_->io_buffer()->size()); 45 *length = base::HostToNet16(query_->io_buffer()->size());
50 writes_.push_back(MockWrite(mode, 46 writes_.push_back(MockWrite(mode,
51 reinterpret_cast<const char*>(length.get()), 47 reinterpret_cast<const char*>(length.get()),
52 sizeof(uint16_t), num_reads_and_writes())); 48 sizeof(uint16), num_reads_and_writes()));
53 lengths_.push_back(length.Pass()); 49 lengths_.push_back(length.Pass());
54 } 50 }
55 writes_.push_back(MockWrite(mode, query_->io_buffer()->data(), 51 writes_.push_back(MockWrite(mode, query_->io_buffer()->data(),
56 query_->io_buffer()->size(), 52 query_->io_buffer()->size(),
57 num_reads_and_writes())); 53 num_reads_and_writes()));
58 } 54 }
59 ~DnsSocketData() {} 55 ~DnsSocketData() {}
60 56
61 // All responses must be added before GetProvider. 57 // All responses must be added before GetProvider.
62 58
63 // Adds pre-built DnsResponse. |tcp_length| will be used in TCP mode only. 59 // Adds pre-built DnsResponse. |tcp_length| will be used in TCP mode only.
64 void AddResponseWithLength(scoped_ptr<DnsResponse> response, 60 void AddResponseWithLength(scoped_ptr<DnsResponse> response, IoMode mode,
65 IoMode mode, 61 uint16 tcp_length) {
66 uint16_t tcp_length) {
67 CHECK(!provider_.get()); 62 CHECK(!provider_.get());
68 if (use_tcp_) { 63 if (use_tcp_) {
69 scoped_ptr<uint16_t> length(new uint16_t); 64 scoped_ptr<uint16> length(new uint16);
70 *length = base::HostToNet16(tcp_length); 65 *length = base::HostToNet16(tcp_length);
71 reads_.push_back(MockRead(mode, 66 reads_.push_back(MockRead(mode,
72 reinterpret_cast<const char*>(length.get()), 67 reinterpret_cast<const char*>(length.get()),
73 sizeof(uint16_t), num_reads_and_writes())); 68 sizeof(uint16), num_reads_and_writes()));
74 lengths_.push_back(length.Pass()); 69 lengths_.push_back(length.Pass());
75 } 70 }
76 reads_.push_back(MockRead(mode, response->io_buffer()->data(), 71 reads_.push_back(MockRead(mode, response->io_buffer()->data(),
77 response->io_buffer()->size(), 72 response->io_buffer()->size(),
78 num_reads_and_writes())); 73 num_reads_and_writes()));
79 responses_.push_back(response.Pass()); 74 responses_.push_back(response.Pass());
80 } 75 }
81 76
82 // Adds pre-built DnsResponse. 77 // Adds pre-built DnsResponse.
83 void AddResponse(scoped_ptr<DnsResponse> response, IoMode mode) { 78 void AddResponse(scoped_ptr<DnsResponse> response, IoMode mode) {
84 uint16_t tcp_length = response->io_buffer()->size(); 79 uint16 tcp_length = response->io_buffer()->size();
85 AddResponseWithLength(response.Pass(), mode, tcp_length); 80 AddResponseWithLength(response.Pass(), mode, tcp_length);
86 } 81 }
87 82
88 // Adds pre-built response from |data| buffer. 83 // Adds pre-built response from |data| buffer.
89 void AddResponseData(const uint8_t* data, size_t length, IoMode mode) { 84 void AddResponseData(const uint8* data, size_t length, IoMode mode) {
90 CHECK(!provider_.get()); 85 CHECK(!provider_.get());
91 AddResponse(make_scoped_ptr( 86 AddResponse(make_scoped_ptr(
92 new DnsResponse(reinterpret_cast<const char*>(data), length, 0)), mode); 87 new DnsResponse(reinterpret_cast<const char*>(data), length, 0)), mode);
93 } 88 }
94 89
95 // Add no-answer (RCODE only) response matching the query. 90 // Add no-answer (RCODE only) response matching the query.
96 void AddRcode(int rcode, IoMode mode) { 91 void AddRcode(int rcode, IoMode mode) {
97 scoped_ptr<DnsResponse> response( 92 scoped_ptr<DnsResponse> response(
98 new DnsResponse(query_->io_buffer()->data(), 93 new DnsResponse(query_->io_buffer()->data(),
99 query_->io_buffer()->size(), 94 query_->io_buffer()->size(),
(...skipping 19 matching lines...) Expand all
119 reads_.push_back( 114 reads_.push_back(
120 MockRead(ASYNC, ERR_IO_PENDING, writes_.size() + reads_.size())); 115 MockRead(ASYNC, ERR_IO_PENDING, writes_.size() + reads_.size()));
121 provider_.reset(new SequencedSocketData(&reads_[0], reads_.size(), 116 provider_.reset(new SequencedSocketData(&reads_[0], reads_.size(),
122 &writes_[0], writes_.size())); 117 &writes_[0], writes_.size()));
123 if (use_tcp_) { 118 if (use_tcp_) {
124 provider_->set_connect_data(MockConnect(reads_[0].mode, OK)); 119 provider_->set_connect_data(MockConnect(reads_[0].mode, OK));
125 } 120 }
126 return provider_.get(); 121 return provider_.get();
127 } 122 }
128 123
129 uint16_t query_id() const { return query_->id(); } 124 uint16 query_id() const {
125 return query_->id();
126 }
130 127
131 private: 128 private:
132 size_t num_reads_and_writes() const { return reads_.size() + writes_.size(); } 129 size_t num_reads_and_writes() const { return reads_.size() + writes_.size(); }
133 130
134 scoped_ptr<DnsQuery> query_; 131 scoped_ptr<DnsQuery> query_;
135 bool use_tcp_; 132 bool use_tcp_;
136 std::vector<scoped_ptr<uint16_t>> lengths_; 133 std::vector<scoped_ptr<uint16>> lengths_;
137 std::vector<scoped_ptr<DnsResponse>> responses_; 134 std::vector<scoped_ptr<DnsResponse>> responses_;
138 std::vector<MockWrite> writes_; 135 std::vector<MockWrite> writes_;
139 std::vector<MockRead> reads_; 136 std::vector<MockRead> reads_;
140 scoped_ptr<SequencedSocketData> provider_; 137 scoped_ptr<SequencedSocketData> provider_;
141 138
142 DISALLOW_COPY_AND_ASSIGN(DnsSocketData); 139 DISALLOW_COPY_AND_ASSIGN(DnsSocketData);
143 }; 140 };
144 141
145 class TestSocketFactory; 142 class TestSocketFactory;
146 143
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 int TestUDPClientSocket::Connect(const IPEndPoint& endpoint) { 213 int TestUDPClientSocket::Connect(const IPEndPoint& endpoint) {
217 factory_->OnConnect(endpoint); 214 factory_->OnConnect(endpoint);
218 return MockUDPClientSocket::Connect(endpoint); 215 return MockUDPClientSocket::Connect(endpoint);
219 } 216 }
220 217
221 // Helper class that holds a DnsTransaction and handles OnTransactionComplete. 218 // Helper class that holds a DnsTransaction and handles OnTransactionComplete.
222 class TransactionHelper { 219 class TransactionHelper {
223 public: 220 public:
224 // If |expected_answer_count| < 0 then it is the expected net error. 221 // If |expected_answer_count| < 0 then it is the expected net error.
225 TransactionHelper(const char* hostname, 222 TransactionHelper(const char* hostname,
226 uint16_t qtype, 223 uint16 qtype,
227 int expected_answer_count) 224 int expected_answer_count)
228 : hostname_(hostname), 225 : hostname_(hostname),
229 qtype_(qtype), 226 qtype_(qtype),
230 expected_answer_count_(expected_answer_count), 227 expected_answer_count_(expected_answer_count),
231 cancel_in_callback_(false), 228 cancel_in_callback_(false),
232 quit_in_callback_(false), 229 quit_in_callback_(false),
233 completed_(false) {} 230 completed_(false) {
231 }
234 232
235 // Mark that the transaction shall be destroyed immediately upon callback. 233 // Mark that the transaction shall be destroyed immediately upon callback.
236 void set_cancel_in_callback() { 234 void set_cancel_in_callback() {
237 cancel_in_callback_ = true; 235 cancel_in_callback_ = true;
238 } 236 }
239 237
240 // Mark to call MessageLoop::QuitWhenIdle() upon callback. 238 // Mark to call MessageLoop::QuitWhenIdle() upon callback.
241 void set_quit_in_callback() { 239 void set_quit_in_callback() {
242 quit_in_callback_ = true; 240 quit_in_callback_ = true;
243 } 241 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Use when some of the responses are timeouts. 307 // Use when some of the responses are timeouts.
310 bool RunUntilDone(DnsTransactionFactory* factory) { 308 bool RunUntilDone(DnsTransactionFactory* factory) {
311 set_quit_in_callback(); 309 set_quit_in_callback();
312 StartTransaction(factory); 310 StartTransaction(factory);
313 base::MessageLoop::current()->Run(); 311 base::MessageLoop::current()->Run();
314 return has_completed(); 312 return has_completed();
315 } 313 }
316 314
317 private: 315 private:
318 std::string hostname_; 316 std::string hostname_;
319 uint16_t qtype_; 317 uint16 qtype_;
320 scoped_ptr<DnsTransaction> transaction_; 318 scoped_ptr<DnsTransaction> transaction_;
321 int expected_answer_count_; 319 int expected_answer_count_;
322 bool cancel_in_callback_; 320 bool cancel_in_callback_;
323 bool quit_in_callback_; 321 bool quit_in_callback_;
324 322
325 bool completed_; 323 bool completed_;
326 }; 324 };
327 325
328 class DnsTransactionTest : public testing::Test { 326 class DnsTransactionTest : public testing::Test {
329 public: 327 public:
(...skipping 29 matching lines...) Expand all
359 void AddSocketData(scoped_ptr<DnsSocketData> data) { 357 void AddSocketData(scoped_ptr<DnsSocketData> data) {
360 CHECK(socket_factory_.get()); 358 CHECK(socket_factory_.get());
361 transaction_ids_.push_back(data->query_id()); 359 transaction_ids_.push_back(data->query_id());
362 socket_factory_->AddSocketDataProvider(data->GetProvider()); 360 socket_factory_->AddSocketDataProvider(data->GetProvider());
363 socket_data_.push_back(data.Pass()); 361 socket_data_.push_back(data.Pass());
364 } 362 }
365 363
366 // Add expected query for |dotted_name| and |qtype| with |id| and response 364 // Add expected query for |dotted_name| and |qtype| with |id| and response
367 // taken verbatim from |data| of |data_length| bytes. The transaction id in 365 // taken verbatim from |data| of |data_length| bytes. The transaction id in
368 // |data| should equal |id|, unless testing mismatched response. 366 // |data| should equal |id|, unless testing mismatched response.
369 void AddQueryAndResponse(uint16_t id, 367 void AddQueryAndResponse(uint16 id,
370 const char* dotted_name, 368 const char* dotted_name,
371 uint16_t qtype, 369 uint16 qtype,
372 const uint8_t* response_data, 370 const uint8* response_data,
373 size_t response_length, 371 size_t response_length,
374 IoMode mode, 372 IoMode mode,
375 bool use_tcp) { 373 bool use_tcp) {
376 CHECK(socket_factory_.get()); 374 CHECK(socket_factory_.get());
377 scoped_ptr<DnsSocketData> data( 375 scoped_ptr<DnsSocketData> data(
378 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp)); 376 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp));
379 data->AddResponseData(response_data, response_length, mode); 377 data->AddResponseData(response_data, response_length, mode);
380 AddSocketData(data.Pass()); 378 AddSocketData(data.Pass());
381 } 379 }
382 380
383 void AddAsyncQueryAndResponse(uint16_t id, 381 void AddAsyncQueryAndResponse(uint16 id,
384 const char* dotted_name, 382 const char* dotted_name,
385 uint16_t qtype, 383 uint16 qtype,
386 const uint8_t* data, 384 const uint8* data,
387 size_t data_length) { 385 size_t data_length) {
388 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, ASYNC, 386 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, ASYNC,
389 false); 387 false);
390 } 388 }
391 389
392 void AddSyncQueryAndResponse(uint16_t id, 390 void AddSyncQueryAndResponse(uint16 id,
393 const char* dotted_name, 391 const char* dotted_name,
394 uint16_t qtype, 392 uint16 qtype,
395 const uint8_t* data, 393 const uint8* data,
396 size_t data_length) { 394 size_t data_length) {
397 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, SYNCHRONOUS, 395 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, SYNCHRONOUS,
398 false); 396 false);
399 } 397 }
400 398
401 // Add expected query of |dotted_name| and |qtype| and no response. 399 // Add expected query of |dotted_name| and |qtype| and no response.
402 void AddQueryAndTimeout(const char* dotted_name, uint16_t qtype) { 400 void AddQueryAndTimeout(const char* dotted_name, uint16 qtype) {
403 uint16_t id = base::RandInt(0, std::numeric_limits<uint16_t>::max()); 401 uint16 id = base::RandInt(0, kuint16max);
404 scoped_ptr<DnsSocketData> data( 402 scoped_ptr<DnsSocketData> data(
405 new DnsSocketData(id, dotted_name, qtype, ASYNC, false)); 403 new DnsSocketData(id, dotted_name, qtype, ASYNC, false));
406 AddSocketData(data.Pass()); 404 AddSocketData(data.Pass());
407 } 405 }
408 406
409 // Add expected query of |dotted_name| and |qtype| and matching response with 407 // Add expected query of |dotted_name| and |qtype| and matching response with
410 // no answer and RCODE set to |rcode|. The id will be generated randomly. 408 // no answer and RCODE set to |rcode|. The id will be generated randomly.
411 void AddQueryAndRcode(const char* dotted_name, 409 void AddQueryAndRcode(const char* dotted_name,
412 uint16_t qtype, 410 uint16 qtype,
413 int rcode, 411 int rcode,
414 IoMode mode, 412 IoMode mode,
415 bool use_tcp) { 413 bool use_tcp) {
416 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode); 414 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode);
417 uint16_t id = base::RandInt(0, std::numeric_limits<uint16_t>::max()); 415 uint16 id = base::RandInt(0, kuint16max);
418 scoped_ptr<DnsSocketData> data( 416 scoped_ptr<DnsSocketData> data(
419 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp)); 417 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp));
420 data->AddRcode(rcode, mode); 418 data->AddRcode(rcode, mode);
421 AddSocketData(data.Pass()); 419 AddSocketData(data.Pass());
422 } 420 }
423 421
424 void AddAsyncQueryAndRcode(const char* dotted_name, 422 void AddAsyncQueryAndRcode(const char* dotted_name, uint16 qtype, int rcode) {
425 uint16_t qtype,
426 int rcode) {
427 AddQueryAndRcode(dotted_name, qtype, rcode, ASYNC, false); 423 AddQueryAndRcode(dotted_name, qtype, rcode, ASYNC, false);
428 } 424 }
429 425
430 void AddSyncQueryAndRcode(const char* dotted_name, 426 void AddSyncQueryAndRcode(const char* dotted_name, uint16 qtype, int rcode) {
431 uint16_t qtype,
432 int rcode) {
433 AddQueryAndRcode(dotted_name, qtype, rcode, SYNCHRONOUS, false); 427 AddQueryAndRcode(dotted_name, qtype, rcode, SYNCHRONOUS, false);
434 } 428 }
435 429
436 // Checks if the sockets were connected in the order matching the indices in 430 // Checks if the sockets were connected in the order matching the indices in
437 // |servers|. 431 // |servers|.
438 void CheckServerOrder(const unsigned* servers, size_t num_attempts) { 432 void CheckServerOrder(const unsigned* servers, size_t num_attempts) {
439 ASSERT_EQ(num_attempts, socket_factory_->remote_endpoints_.size()); 433 ASSERT_EQ(num_attempts, socket_factory_->remote_endpoints_.size());
440 for (size_t i = 0; i < num_attempts; ++i) { 434 for (size_t i = 0; i < num_attempts; ++i) {
441 EXPECT_EQ(socket_factory_->remote_endpoints_[i], 435 EXPECT_EQ(socket_factory_->remote_endpoints_[i],
442 session_->config().nameservers[servers[i]]); 436 session_->config().nameservers[servers[i]]);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 ERR_NAME_NOT_RESOLVED); 777 ERR_NAME_NOT_RESOLVED);
784 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 778 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
785 779
786 TransactionHelper helper1("x.y", dns_protocol::kTypeA, ERR_NAME_NOT_RESOLVED); 780 TransactionHelper helper1("x.y", dns_protocol::kTypeA, ERR_NAME_NOT_RESOLVED);
787 EXPECT_TRUE(helper1.Run(transaction_factory_.get())); 781 EXPECT_TRUE(helper1.Run(transaction_factory_.get()));
788 782
789 TransactionHelper helper2("x", dns_protocol::kTypeA, ERR_NAME_NOT_RESOLVED); 783 TransactionHelper helper2("x", dns_protocol::kTypeA, ERR_NAME_NOT_RESOLVED);
790 EXPECT_TRUE(helper2.Run(transaction_factory_.get())); 784 EXPECT_TRUE(helper2.Run(transaction_factory_.get()));
791 } 785 }
792 786
793 const uint8_t kResponseNoData[] = { 787 const uint8 kResponseNoData[] = {
794 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 788 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
795 // Question 789 // Question
796 0x01, 'x', 0x01, 'y', 0x01, 'z', 0x01, 'b', 0x00, 0x00, 0x01, 0x00, 0x01, 790 0x01, 'x', 0x01, 'y', 0x01, 'z', 0x01, 'b', 0x00, 0x00, 0x01, 0x00, 0x01,
797 // Authority section, SOA record, TTL 0x3E6 791 // Authority section, SOA record, TTL 0x3E6
798 0x01, 'z', 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x03, 0xE6, 792 0x01, 'z', 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x03, 0xE6,
799 // Minimal RDATA, 18 bytes 793 // Minimal RDATA, 18 bytes
800 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 794 0x00, 0x12,
801 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 795 0x00, 0x00,
796 0x00, 0x00, 0x00, 0x00,
797 0x00, 0x00, 0x00, 0x00,
798 0x00, 0x00, 0x00, 0x00,
799 0x00, 0x00, 0x00, 0x00,
802 }; 800 };
803 801
804 TEST_F(DnsTransactionTest, SuffixSearchStop) { 802 TEST_F(DnsTransactionTest, SuffixSearchStop) {
805 config_.ndots = 2; 803 config_.ndots = 2;
806 config_.search.push_back("a"); 804 config_.search.push_back("a");
807 config_.search.push_back("b"); 805 config_.search.push_back("b");
808 config_.search.push_back("c"); 806 config_.search.push_back("c");
809 ConfigureFactory(); 807 ConfigureFactory();
810 808
811 AddAsyncQueryAndRcode("x.y.z", dns_protocol::kTypeA, 809 AddAsyncQueryAndRcode("x.y.z", dns_protocol::kTypeA,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 scoped_ptr<DnsSocketData> data( 908 scoped_ptr<DnsSocketData> data(
911 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); 909 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true));
912 // Valid response but length too short. 910 // Valid response but length too short.
913 // This must be truncated in the question section. The DnsResponse doesn't 911 // This must be truncated in the question section. The DnsResponse doesn't
914 // examine the answer section until asked to parse it, so truncating it in 912 // examine the answer section until asked to parse it, so truncating it in
915 // the answer section would result in the DnsTransaction itself succeeding. 913 // the answer section would result in the DnsTransaction itself succeeding.
916 data->AddResponseWithLength( 914 data->AddResponseWithLength(
917 make_scoped_ptr( 915 make_scoped_ptr(
918 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), 916 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram),
919 arraysize(kT0ResponseDatagram), 0)), 917 arraysize(kT0ResponseDatagram), 0)),
920 ASYNC, static_cast<uint16_t>(kT0QuerySize - 1)); 918 ASYNC,
919 static_cast<uint16>(kT0QuerySize - 1));
921 AddSocketData(data.Pass()); 920 AddSocketData(data.Pass());
922 921
923 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_DNS_MALFORMED_RESPONSE); 922 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_DNS_MALFORMED_RESPONSE);
924 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 923 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
925 } 924 }
926 925
927 TEST_F(DnsTransactionTest, TCPTimeout) { 926 TEST_F(DnsTransactionTest, TCPTimeout) {
928 config_.timeout = TestTimeouts::tiny_timeout(); 927 config_.timeout = TestTimeouts::tiny_timeout();
929 ConfigureFactory(); 928 ConfigureFactory();
930 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, 929 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
931 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); 930 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
932 AddSocketData(make_scoped_ptr( 931 AddSocketData(make_scoped_ptr(
933 new DnsSocketData(1 /* id */, kT0HostName, kT0Qtype, ASYNC, true))); 932 new DnsSocketData(1 /* id */, kT0HostName, kT0Qtype, ASYNC, true)));
934 933
935 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_DNS_TIMED_OUT); 934 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_DNS_TIMED_OUT);
936 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); 935 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get()));
937 } 936 }
938 937
939 TEST_F(DnsTransactionTest, TCPReadReturnsZeroAsync) { 938 TEST_F(DnsTransactionTest, TCPReadReturnsZeroAsync) {
940 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, 939 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
941 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); 940 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
942 scoped_ptr<DnsSocketData> data( 941 scoped_ptr<DnsSocketData> data(
943 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); 942 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true));
944 // Return all but the last byte of the response. 943 // Return all but the last byte of the response.
945 data->AddResponseWithLength( 944 data->AddResponseWithLength(
946 make_scoped_ptr( 945 make_scoped_ptr(
947 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), 946 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram),
948 arraysize(kT0ResponseDatagram) - 1, 0)), 947 arraysize(kT0ResponseDatagram) - 1, 0)),
949 ASYNC, static_cast<uint16_t>(arraysize(kT0ResponseDatagram))); 948 ASYNC,
949 static_cast<uint16>(arraysize(kT0ResponseDatagram)));
950 // Then return a 0-length read. 950 // Then return a 0-length read.
951 data->AddReadError(0, ASYNC); 951 data->AddReadError(0, ASYNC);
952 AddSocketData(data.Pass()); 952 AddSocketData(data.Pass());
953 953
954 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); 954 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED);
955 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 955 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
956 } 956 }
957 957
958 TEST_F(DnsTransactionTest, TCPReadReturnsZeroSynchronous) { 958 TEST_F(DnsTransactionTest, TCPReadReturnsZeroSynchronous) {
959 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, 959 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
960 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); 960 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
961 scoped_ptr<DnsSocketData> data( 961 scoped_ptr<DnsSocketData> data(
962 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); 962 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true));
963 // Return all but the last byte of the response. 963 // Return all but the last byte of the response.
964 data->AddResponseWithLength( 964 data->AddResponseWithLength(
965 make_scoped_ptr( 965 make_scoped_ptr(
966 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), 966 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram),
967 arraysize(kT0ResponseDatagram) - 1, 0)), 967 arraysize(kT0ResponseDatagram) - 1, 0)),
968 SYNCHRONOUS, static_cast<uint16_t>(arraysize(kT0ResponseDatagram))); 968 SYNCHRONOUS,
969 static_cast<uint16>(arraysize(kT0ResponseDatagram)));
969 // Then return a 0-length read. 970 // Then return a 0-length read.
970 data->AddReadError(0, SYNCHRONOUS); 971 data->AddReadError(0, SYNCHRONOUS);
971 AddSocketData(data.Pass()); 972 AddSocketData(data.Pass());
972 973
973 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); 974 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED);
974 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 975 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
975 } 976 }
976 977
977 TEST_F(DnsTransactionTest, TCPConnectionClosedAsync) { 978 TEST_F(DnsTransactionTest, TCPConnectionClosedAsync) {
978 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, 979 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
(...skipping 23 matching lines...) Expand all
1002 config_.timeout = TestTimeouts::tiny_timeout(); 1003 config_.timeout = TestTimeouts::tiny_timeout();
1003 ConfigureFactory(); 1004 ConfigureFactory();
1004 1005
1005 TransactionHelper helper0(".", dns_protocol::kTypeA, ERR_INVALID_ARGUMENT); 1006 TransactionHelper helper0(".", dns_protocol::kTypeA, ERR_INVALID_ARGUMENT);
1006 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 1007 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
1007 } 1008 }
1008 1009
1009 } // namespace 1010 } // namespace
1010 1011
1011 } // namespace net 1012 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_session.cc ('k') | net/test/spawned_test_server/base_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698