OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace net { | 24 namespace net { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 std::string DomainFromDot(const base::StringPiece& dotted) { | 28 std::string DomainFromDot(const base::StringPiece& dotted) { |
29 std::string out; | 29 std::string out; |
30 EXPECT_TRUE(DNSDomainFromDot(dotted, &out)); | 30 EXPECT_TRUE(DNSDomainFromDot(dotted, &out)); |
31 return out; | 31 return out; |
32 } | 32 } |
33 | 33 |
34 // A SocketDataProvider builder for MockUDPClientSocket. Each socket used by a | 34 // A SocketDataProvider builder. |
35 // DnsTransaction expects only one write and zero or more reads. | |
36 class DnsSocketData { | 35 class DnsSocketData { |
37 public: | 36 public: |
38 // The ctor takes parameters for the DnsQuery. | 37 // The ctor takes parameters for the DnsQuery. |
39 DnsSocketData(uint16 id, const char* dotted_name, uint16 qtype, IoMode mode) | 38 DnsSocketData(uint16 id, |
| 39 const char* dotted_name, |
| 40 uint16 qtype, |
| 41 IoMode mode, |
| 42 bool use_tcp) |
40 : query_(new DnsQuery(id, DomainFromDot(dotted_name), qtype)), | 43 : query_(new DnsQuery(id, DomainFromDot(dotted_name), qtype)), |
41 write_(mode, query_->io_buffer()->data(), query_->io_buffer()->size()) { | 44 use_tcp_(use_tcp) { |
| 45 if (use_tcp_) { |
| 46 scoped_ptr<uint16> length(new uint16); |
| 47 *length = base::HostToNet16(query_->io_buffer()->size()); |
| 48 writes_.push_back(MockWrite(mode, |
| 49 reinterpret_cast<const char*>(length.get()), |
| 50 sizeof(uint16))); |
| 51 lengths_.push_back(length.release()); |
| 52 } |
| 53 writes_.push_back(MockWrite(mode, |
| 54 query_->io_buffer()->data(), |
| 55 query_->io_buffer()->size())); |
42 } | 56 } |
43 ~DnsSocketData() {} | 57 ~DnsSocketData() {} |
44 | 58 |
45 // All responses must be added before GetProvider. | 59 // All responses must be added before GetProvider. |
46 | 60 |
47 // Add pre-built DnsResponse. | 61 // Add pre-built DnsResponse. |
48 void AddResponse(scoped_ptr<DnsResponse> response, IoMode mode) { | 62 void AddResponse(scoped_ptr<DnsResponse> response, IoMode mode) { |
49 CHECK(!provider_.get()); | 63 CHECK(!provider_.get()); |
| 64 if (use_tcp_) { |
| 65 scoped_ptr<uint16> length(new uint16); |
| 66 *length = base::HostToNet16(response->io_buffer()->size()); |
| 67 reads_.push_back(MockRead(mode, |
| 68 reinterpret_cast<const char*>(length.get()), |
| 69 sizeof(uint16))); |
| 70 lengths_.push_back(length.release()); |
| 71 } |
50 reads_.push_back(MockRead(mode, | 72 reads_.push_back(MockRead(mode, |
51 response->io_buffer()->data(), | 73 response->io_buffer()->data(), |
52 response->io_buffer()->size())); | 74 response->io_buffer()->size())); |
53 responses_.push_back(response.release()); | 75 responses_.push_back(response.release()); |
54 } | 76 } |
55 | 77 |
56 // Adds pre-built response from |data| buffer. | 78 // Adds pre-built response from |data| buffer. |
57 void AddResponseData(const uint8* data, size_t length, IoMode mode) { | 79 void AddResponseData(const uint8* data, size_t length, IoMode mode) { |
58 CHECK(!provider_.get()); | 80 CHECK(!provider_.get()); |
59 AddResponse(make_scoped_ptr( | 81 AddResponse(make_scoped_ptr( |
(...skipping 10 matching lines...) Expand all Loading... |
70 reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data()); | 92 reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data()); |
71 header->flags |= base::HostToNet16(dns_protocol::kFlagResponse | rcode); | 93 header->flags |= base::HostToNet16(dns_protocol::kFlagResponse | rcode); |
72 AddResponse(response.Pass(), mode); | 94 AddResponse(response.Pass(), mode); |
73 } | 95 } |
74 | 96 |
75 // Build, if needed, and return the SocketDataProvider. No new responses | 97 // Build, if needed, and return the SocketDataProvider. No new responses |
76 // should be added afterwards. | 98 // should be added afterwards. |
77 SocketDataProvider* GetProvider() { | 99 SocketDataProvider* GetProvider() { |
78 if (provider_.get()) | 100 if (provider_.get()) |
79 return provider_.get(); | 101 return provider_.get(); |
80 if (reads_.empty()) { | 102 // Terminate the reads with ERR_IO_PENDING to prevent overrun and default to |
81 // Timeout. | 103 // timeout. |
82 provider_.reset(new DelayedSocketData(2, NULL, 0, &write_, 1)); | 104 reads_.push_back(MockRead(ASYNC, ERR_IO_PENDING)); |
83 } else { | 105 provider_.reset(new DelayedSocketData(1, &reads_[0], reads_.size(), |
84 // Terminate the reads with ERR_IO_PENDING to prevent overrun. | 106 &writes_[0], writes_.size())); |
85 reads_.push_back(MockRead(ASYNC, ERR_IO_PENDING)); | 107 if (use_tcp_) { |
86 provider_.reset(new DelayedSocketData(1, &reads_[0], reads_.size(), | 108 provider_->set_connect_data(MockConnect(reads_[0].mode, OK)); |
87 &write_, 1)); | |
88 } | 109 } |
89 return provider_.get(); | 110 return provider_.get(); |
90 } | 111 } |
91 | 112 |
92 uint16 query_id() const { | 113 uint16 query_id() const { |
93 return query_->id(); | 114 return query_->id(); |
94 } | 115 } |
95 | 116 |
96 // Returns true if the expected query was written to the socket. | 117 // Returns true if the expected query was written to the socket. |
97 bool was_written() const { | 118 bool was_written() const { |
98 CHECK(provider_.get()); | 119 CHECK(provider_.get()); |
99 return provider_->write_index() > 0; | 120 return provider_->write_index() > 0; |
100 } | 121 } |
101 | 122 |
102 private: | 123 private: |
103 scoped_ptr<DnsQuery> query_; | 124 scoped_ptr<DnsQuery> query_; |
| 125 bool use_tcp_; |
| 126 ScopedVector<uint16> lengths_; |
104 ScopedVector<DnsResponse> responses_; | 127 ScopedVector<DnsResponse> responses_; |
105 MockWrite write_; | 128 std::vector<MockWrite> writes_; |
106 std::vector<MockRead> reads_; | 129 std::vector<MockRead> reads_; |
107 scoped_ptr<DelayedSocketData> provider_; | 130 scoped_ptr<DelayedSocketData> provider_; |
108 | 131 |
109 DISALLOW_COPY_AND_ASSIGN(DnsSocketData); | 132 DISALLOW_COPY_AND_ASSIGN(DnsSocketData); |
110 }; | 133 }; |
111 | 134 |
112 class TestSocketFactory; | 135 class TestSocketFactory; |
113 | 136 |
114 // A variant of MockUDPClientSocket which always fails to Connect. | 137 // A variant of MockUDPClientSocket which always fails to Connect. |
115 class FailingUDPClientSocket : public MockUDPClientSocket { | 138 class FailingUDPClientSocket : public MockUDPClientSocket { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 socket_factory_.reset(new TestSocketFactory()); | 344 socket_factory_.reset(new TestSocketFactory()); |
322 session_ = new DnsSession( | 345 session_ = new DnsSession( |
323 config_, | 346 config_, |
324 DnsSocketPool::CreateNull(socket_factory_.get()), | 347 DnsSocketPool::CreateNull(socket_factory_.get()), |
325 base::Bind(&DnsTransactionTest::GetNextId, base::Unretained(this)), | 348 base::Bind(&DnsTransactionTest::GetNextId, base::Unretained(this)), |
326 NULL /* NetLog */); | 349 NULL /* NetLog */); |
327 transaction_factory_ = DnsTransactionFactory::CreateFactory(session_.get()); | 350 transaction_factory_ = DnsTransactionFactory::CreateFactory(session_.get()); |
328 } | 351 } |
329 | 352 |
330 void AddSocketData(scoped_ptr<DnsSocketData> data) { | 353 void AddSocketData(scoped_ptr<DnsSocketData> data) { |
| 354 CHECK(socket_factory_.get()); |
331 transaction_ids_.push_back(data->query_id()); | 355 transaction_ids_.push_back(data->query_id()); |
332 socket_factory_->AddSocketDataProvider(data->GetProvider()); | 356 socket_factory_->AddSocketDataProvider(data->GetProvider()); |
333 socket_data_.push_back(data.release()); | 357 socket_data_.push_back(data.release()); |
334 } | 358 } |
335 | 359 |
336 // Add expected query for |dotted_name| and |qtype| with |id| and response | 360 // Add expected query for |dotted_name| and |qtype| with |id| and response |
337 // taken verbatim from |data| of |data_length| bytes. The transaction id in | 361 // taken verbatim from |data| of |data_length| bytes. The transaction id in |
338 // |data| should equal |id|, unless testing mismatched response. | 362 // |data| should equal |id|, unless testing mismatched response. |
339 void AddQueryAndResponse(uint16 id, | 363 void AddQueryAndResponse(uint16 id, |
340 const char* dotted_name, | 364 const char* dotted_name, |
341 uint16 qtype, | 365 uint16 qtype, |
342 const uint8* response_data, | 366 const uint8* response_data, |
343 size_t response_length, | 367 size_t response_length, |
344 IoMode mode) { | 368 IoMode mode, |
| 369 bool use_tcp) { |
345 CHECK(socket_factory_.get()); | 370 CHECK(socket_factory_.get()); |
346 scoped_ptr<DnsSocketData> data( | 371 scoped_ptr<DnsSocketData> data( |
347 new DnsSocketData(id, dotted_name, qtype, mode)); | 372 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp)); |
348 data->AddResponseData(response_data, response_length, mode); | 373 data->AddResponseData(response_data, response_length, mode); |
349 AddSocketData(data.Pass()); | 374 AddSocketData(data.Pass()); |
350 } | 375 } |
351 | 376 |
352 void AddAsyncQueryAndResponse(uint16 id, | 377 void AddAsyncQueryAndResponse(uint16 id, |
353 const char* dotted_name, | 378 const char* dotted_name, |
354 uint16 qtype, | 379 uint16 qtype, |
355 const uint8* data, | 380 const uint8* data, |
356 size_t data_length) { | 381 size_t data_length) { |
357 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, ASYNC); | 382 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, ASYNC, |
| 383 false); |
358 } | 384 } |
359 | 385 |
360 void AddSyncQueryAndResponse(uint16 id, | 386 void AddSyncQueryAndResponse(uint16 id, |
361 const char* dotted_name, | 387 const char* dotted_name, |
362 uint16 qtype, | 388 uint16 qtype, |
363 const uint8* data, | 389 const uint8* data, |
364 size_t data_length) { | 390 size_t data_length) { |
365 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, SYNCHRONOUS); | 391 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, SYNCHRONOUS, |
| 392 false); |
366 } | 393 } |
367 | 394 |
368 // Add expected query of |dotted_name| and |qtype| and no response. | 395 // Add expected query of |dotted_name| and |qtype| and no response. |
369 void AddQueryAndTimeout(const char* dotted_name, uint16 qtype) { | 396 void AddQueryAndTimeout(const char* dotted_name, uint16 qtype) { |
370 CHECK(socket_factory_.get()); | |
371 uint16 id = base::RandInt(0, kuint16max); | 397 uint16 id = base::RandInt(0, kuint16max); |
372 scoped_ptr<DnsSocketData> data( | 398 scoped_ptr<DnsSocketData> data( |
373 new DnsSocketData(id, dotted_name, qtype, ASYNC)); | 399 new DnsSocketData(id, dotted_name, qtype, ASYNC, false)); |
374 AddSocketData(data.Pass()); | 400 AddSocketData(data.Pass()); |
375 } | 401 } |
376 | 402 |
377 // Add expected query of |dotted_name| and |qtype| and matching response with | 403 // Add expected query of |dotted_name| and |qtype| and matching response with |
378 // no answer and RCODE set to |rcode|. The id will be generated randomly. | 404 // no answer and RCODE set to |rcode|. The id will be generated randomly. |
379 void AddQueryAndRcode(const char* dotted_name, | 405 void AddQueryAndRcode(const char* dotted_name, |
380 uint16 qtype, | 406 uint16 qtype, |
381 int rcode, | 407 int rcode, |
382 IoMode mode) { | 408 IoMode mode, |
383 CHECK(socket_factory_.get()); | 409 bool use_tcp) { |
384 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode); | 410 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode); |
385 uint16 id = base::RandInt(0, kuint16max); | 411 uint16 id = base::RandInt(0, kuint16max); |
386 scoped_ptr<DnsSocketData> data( | 412 scoped_ptr<DnsSocketData> data( |
387 new DnsSocketData(id, dotted_name, qtype, mode)); | 413 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp)); |
388 data->AddRcode(rcode, mode); | 414 data->AddRcode(rcode, mode); |
389 AddSocketData(data.Pass()); | 415 AddSocketData(data.Pass()); |
390 } | 416 } |
391 | 417 |
392 void AddAsyncQueryAndRcode(const char* dotted_name, uint16 qtype, int rcode) { | 418 void AddAsyncQueryAndRcode(const char* dotted_name, uint16 qtype, int rcode) { |
393 AddQueryAndRcode(dotted_name, qtype, rcode, ASYNC); | 419 AddQueryAndRcode(dotted_name, qtype, rcode, ASYNC, false); |
394 } | 420 } |
395 | 421 |
396 void AddSyncQueryAndRcode(const char* dotted_name, uint16 qtype, int rcode) { | 422 void AddSyncQueryAndRcode(const char* dotted_name, uint16 qtype, int rcode) { |
397 AddQueryAndRcode(dotted_name, qtype, rcode, SYNCHRONOUS); | 423 AddQueryAndRcode(dotted_name, qtype, rcode, SYNCHRONOUS, false); |
398 } | 424 } |
399 | 425 |
400 // Checks if the sockets were connected in the order matching the indices in | 426 // Checks if the sockets were connected in the order matching the indices in |
401 // |servers|. | 427 // |servers|. |
402 void CheckServerOrder(const unsigned* servers, size_t num_attempts) { | 428 void CheckServerOrder(const unsigned* servers, size_t num_attempts) { |
403 ASSERT_EQ(num_attempts, socket_factory_->remote_endpoints_.size()); | 429 ASSERT_EQ(num_attempts, socket_factory_->remote_endpoints_.size()); |
404 for (size_t i = 0; i < num_attempts; ++i) { | 430 for (size_t i = 0; i < num_attempts; ++i) { |
405 EXPECT_EQ(socket_factory_->remote_endpoints_[i], | 431 EXPECT_EQ(socket_factory_->remote_endpoints_[i], |
406 session_->config().nameservers[servers[i]]); | 432 session_->config().nameservers[servers[i]]); |
407 } | 433 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 ScopedVector<DnsSocketData> socket_data_; | 465 ScopedVector<DnsSocketData> socket_data_; |
440 | 466 |
441 std::deque<int> transaction_ids_; | 467 std::deque<int> transaction_ids_; |
442 scoped_ptr<TestSocketFactory> socket_factory_; | 468 scoped_ptr<TestSocketFactory> socket_factory_; |
443 scoped_refptr<DnsSession> session_; | 469 scoped_refptr<DnsSession> session_; |
444 scoped_ptr<DnsTransactionFactory> transaction_factory_; | 470 scoped_ptr<DnsTransactionFactory> transaction_factory_; |
445 }; | 471 }; |
446 | 472 |
447 TEST_F(DnsTransactionTest, Lookup) { | 473 TEST_F(DnsTransactionTest, Lookup) { |
448 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 474 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
449 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | 475 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); |
450 | 476 |
451 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 477 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
452 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); | 478 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
453 } | 479 } |
454 | 480 |
455 // Concurrent lookup tests assume that DnsTransaction::Start immediately | 481 // Concurrent lookup tests assume that DnsTransaction::Start immediately |
456 // consumes a socket from ClientSocketFactory. | 482 // consumes a socket from ClientSocketFactory. |
457 TEST_F(DnsTransactionTest, ConcurrentLookup) { | 483 TEST_F(DnsTransactionTest, ConcurrentLookup) { |
458 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 484 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
459 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | 485 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); |
(...skipping 25 matching lines...) Expand all Loading... |
485 helper0.Cancel(); | 511 helper0.Cancel(); |
486 | 512 |
487 MessageLoop::current()->RunUntilIdle(); | 513 MessageLoop::current()->RunUntilIdle(); |
488 | 514 |
489 EXPECT_FALSE(helper0.has_completed()); | 515 EXPECT_FALSE(helper0.has_completed()); |
490 EXPECT_TRUE(helper1.has_completed()); | 516 EXPECT_TRUE(helper1.has_completed()); |
491 } | 517 } |
492 | 518 |
493 TEST_F(DnsTransactionTest, DestroyFactory) { | 519 TEST_F(DnsTransactionTest, DestroyFactory) { |
494 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 520 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
495 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | 521 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); |
496 | 522 |
497 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 523 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
498 helper0.StartTransaction(transaction_factory_.get()); | 524 helper0.StartTransaction(transaction_factory_.get()); |
499 | 525 |
500 // Destroying the client does not affect running requests. | 526 // Destroying the client does not affect running requests. |
501 transaction_factory_.reset(NULL); | 527 transaction_factory_.reset(NULL); |
502 | 528 |
503 MessageLoop::current()->RunUntilIdle(); | 529 MessageLoop::current()->RunUntilIdle(); |
504 | 530 |
505 EXPECT_TRUE(helper0.has_completed()); | 531 EXPECT_TRUE(helper0.has_completed()); |
506 } | 532 } |
507 | 533 |
508 TEST_F(DnsTransactionTest, CancelFromCallback) { | 534 TEST_F(DnsTransactionTest, CancelFromCallback) { |
509 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 535 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
510 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | 536 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); |
511 | 537 |
512 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 538 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
513 helper0.set_cancel_in_callback(); | 539 helper0.set_cancel_in_callback(); |
514 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); | 540 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
515 } | 541 } |
516 | 542 |
517 TEST_F(DnsTransactionTest, MismatchedResponseSync) { | 543 TEST_F(DnsTransactionTest, MismatchedResponseSync) { |
518 config_.attempts = 2; | 544 config_.attempts = 2; |
519 config_.timeout = TestTimeouts::tiny_timeout(); | 545 config_.timeout = TestTimeouts::tiny_timeout(); |
520 ConfigureFactory(); | 546 ConfigureFactory(); |
521 | 547 |
522 // Attempt receives mismatched response followed by valid response. | 548 // Attempt receives mismatched response followed by valid response. |
523 scoped_ptr<DnsSocketData> data( | 549 scoped_ptr<DnsSocketData> data( |
524 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, SYNCHRONOUS)); | 550 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, SYNCHRONOUS, false)); |
525 data->AddResponseData(kT1ResponseDatagram, | 551 data->AddResponseData(kT1ResponseDatagram, |
526 arraysize(kT1ResponseDatagram), SYNCHRONOUS); | 552 arraysize(kT1ResponseDatagram), SYNCHRONOUS); |
527 data->AddResponseData(kT0ResponseDatagram, | 553 data->AddResponseData(kT0ResponseDatagram, |
528 arraysize(kT0ResponseDatagram), SYNCHRONOUS); | 554 arraysize(kT0ResponseDatagram), SYNCHRONOUS); |
529 AddSocketData(data.Pass()); | 555 AddSocketData(data.Pass()); |
530 | 556 |
531 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 557 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
532 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); | 558 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); |
533 } | 559 } |
534 | 560 |
535 TEST_F(DnsTransactionTest, MismatchedResponseAsync) { | 561 TEST_F(DnsTransactionTest, MismatchedResponseAsync) { |
536 config_.attempts = 2; | 562 config_.attempts = 2; |
537 config_.timeout = TestTimeouts::tiny_timeout(); | 563 config_.timeout = TestTimeouts::tiny_timeout(); |
538 ConfigureFactory(); | 564 ConfigureFactory(); |
539 | 565 |
540 // First attempt receives mismatched response followed by valid response. | 566 // First attempt receives mismatched response followed by valid response. |
541 // Second attempt times out. | 567 // Second attempt times out. |
542 scoped_ptr<DnsSocketData> data( | 568 scoped_ptr<DnsSocketData> data( |
543 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC)); | 569 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, false)); |
544 data->AddResponseData(kT1ResponseDatagram, | 570 data->AddResponseData(kT1ResponseDatagram, |
545 arraysize(kT1ResponseDatagram), ASYNC); | 571 arraysize(kT1ResponseDatagram), ASYNC); |
546 data->AddResponseData(kT0ResponseDatagram, | 572 data->AddResponseData(kT0ResponseDatagram, |
547 arraysize(kT0ResponseDatagram), ASYNC); | 573 arraysize(kT0ResponseDatagram), ASYNC); |
548 AddSocketData(data.Pass()); | 574 AddSocketData(data.Pass()); |
549 AddQueryAndTimeout(kT0HostName, kT0Qtype); | 575 AddQueryAndTimeout(kT0HostName, kT0Qtype); |
550 | 576 |
551 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 577 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
552 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); | 578 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); |
553 } | 579 } |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 } | 850 } |
825 | 851 |
826 TEST_F(DnsTransactionTest, ConnectFailure) { | 852 TEST_F(DnsTransactionTest, ConnectFailure) { |
827 socket_factory_->create_failing_sockets_ = true; | 853 socket_factory_->create_failing_sockets_ = true; |
828 transaction_ids_.push_back(0); // Needed to make a DnsUDPAttempt. | 854 transaction_ids_.push_back(0); // Needed to make a DnsUDPAttempt. |
829 TransactionHelper helper0("www.chromium.org", dns_protocol::kTypeA, | 855 TransactionHelper helper0("www.chromium.org", dns_protocol::kTypeA, |
830 ERR_CONNECTION_REFUSED); | 856 ERR_CONNECTION_REFUSED); |
831 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); | 857 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
832 } | 858 } |
833 | 859 |
| 860 TEST_F(DnsTransactionTest, TCPLookup) { |
| 861 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, |
| 862 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); |
| 863 AddQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
| 864 kT0ResponseDatagram, arraysize(kT0ResponseDatagram), |
| 865 ASYNC, true /* use_tcp */); |
| 866 |
| 867 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
| 868 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| 869 } |
| 870 |
| 871 TEST_F(DnsTransactionTest, TCPFailure) { |
| 872 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, |
| 873 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); |
| 874 AddQueryAndRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeSERVFAIL, |
| 875 ASYNC, true /* use_tcp */); |
| 876 |
| 877 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_DNS_SERVER_FAILED); |
| 878 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| 879 } |
| 880 |
| 881 TEST_F(DnsTransactionTest, TCPTimeout) { |
| 882 config_.timeout = TestTimeouts::tiny_timeout(); |
| 883 ConfigureFactory(); |
| 884 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, |
| 885 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); |
| 886 AddSocketData(make_scoped_ptr( |
| 887 new DnsSocketData(1 /* id */, kT0HostName, kT0Qtype, ASYNC, true))); |
| 888 |
| 889 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_DNS_TIMED_OUT); |
| 890 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); |
| 891 } |
| 892 |
834 } // namespace | 893 } // namespace |
835 | 894 |
836 } // namespace net | 895 } // namespace net |
OLD | NEW |