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

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

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