| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
| 17 #include "base/run_loop.h" |
| 17 #include "base/sys_byteorder.h" | 18 #include "base/sys_byteorder.h" |
| 18 #include "base/test/test_timeouts.h" | 19 #include "base/test/test_timeouts.h" |
| 19 #include "net/base/ip_address.h" | 20 #include "net/base/ip_address.h" |
| 20 #include "net/dns/dns_protocol.h" | 21 #include "net/dns/dns_protocol.h" |
| 21 #include "net/dns/dns_query.h" | 22 #include "net/dns/dns_query.h" |
| 22 #include "net/dns/dns_response.h" | 23 #include "net/dns/dns_response.h" |
| 23 #include "net/dns/dns_session.h" | 24 #include "net/dns/dns_session.h" |
| 24 #include "net/dns/dns_test_util.h" | 25 #include "net/dns/dns_test_util.h" |
| 25 #include "net/dns/dns_util.h" | 26 #include "net/dns/dns_util.h" |
| 26 #include "net/log/net_log.h" | 27 #include "net/log/net_log.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 } | 298 } |
| 298 | 299 |
| 299 bool has_completed() const { | 300 bool has_completed() const { |
| 300 return completed_; | 301 return completed_; |
| 301 } | 302 } |
| 302 | 303 |
| 303 // Shorthands for commonly used commands. | 304 // Shorthands for commonly used commands. |
| 304 | 305 |
| 305 bool Run(DnsTransactionFactory* factory) { | 306 bool Run(DnsTransactionFactory* factory) { |
| 306 StartTransaction(factory); | 307 StartTransaction(factory); |
| 307 base::MessageLoop::current()->RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
| 308 return has_completed(); | 309 return has_completed(); |
| 309 } | 310 } |
| 310 | 311 |
| 311 // Use when some of the responses are timeouts. | 312 // Use when some of the responses are timeouts. |
| 312 bool RunUntilDone(DnsTransactionFactory* factory) { | 313 bool RunUntilDone(DnsTransactionFactory* factory) { |
| 313 set_quit_in_callback(); | 314 set_quit_in_callback(); |
| 314 StartTransaction(factory); | 315 StartTransaction(factory); |
| 315 base::MessageLoop::current()->Run(); | 316 base::RunLoop().Run(); |
| 316 return has_completed(); | 317 return has_completed(); |
| 317 } | 318 } |
| 318 | 319 |
| 319 private: | 320 private: |
| 320 std::string hostname_; | 321 std::string hostname_; |
| 321 uint16_t qtype_; | 322 uint16_t qtype_; |
| 322 std::unique_ptr<DnsTransaction> transaction_; | 323 std::unique_ptr<DnsTransaction> transaction_; |
| 323 int expected_answer_count_; | 324 int expected_answer_count_; |
| 324 bool cancel_in_callback_; | 325 bool cancel_in_callback_; |
| 325 bool quit_in_callback_; | 326 bool quit_in_callback_; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 491 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
| 491 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | 492 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); |
| 492 AddAsyncQueryAndResponse(1 /* id */, kT1HostName, kT1Qtype, | 493 AddAsyncQueryAndResponse(1 /* id */, kT1HostName, kT1Qtype, |
| 493 kT1ResponseDatagram, arraysize(kT1ResponseDatagram)); | 494 kT1ResponseDatagram, arraysize(kT1ResponseDatagram)); |
| 494 | 495 |
| 495 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 496 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
| 496 helper0.StartTransaction(transaction_factory_.get()); | 497 helper0.StartTransaction(transaction_factory_.get()); |
| 497 TransactionHelper helper1(kT1HostName, kT1Qtype, kT1RecordCount); | 498 TransactionHelper helper1(kT1HostName, kT1Qtype, kT1RecordCount); |
| 498 helper1.StartTransaction(transaction_factory_.get()); | 499 helper1.StartTransaction(transaction_factory_.get()); |
| 499 | 500 |
| 500 base::MessageLoop::current()->RunUntilIdle(); | 501 base::RunLoop().RunUntilIdle(); |
| 501 | 502 |
| 502 EXPECT_TRUE(helper0.has_completed()); | 503 EXPECT_TRUE(helper0.has_completed()); |
| 503 EXPECT_TRUE(helper1.has_completed()); | 504 EXPECT_TRUE(helper1.has_completed()); |
| 504 } | 505 } |
| 505 | 506 |
| 506 TEST_F(DnsTransactionTest, CancelLookup) { | 507 TEST_F(DnsTransactionTest, CancelLookup) { |
| 507 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 508 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
| 508 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | 509 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); |
| 509 AddAsyncQueryAndResponse(1 /* id */, kT1HostName, kT1Qtype, | 510 AddAsyncQueryAndResponse(1 /* id */, kT1HostName, kT1Qtype, |
| 510 kT1ResponseDatagram, arraysize(kT1ResponseDatagram)); | 511 kT1ResponseDatagram, arraysize(kT1ResponseDatagram)); |
| 511 | 512 |
| 512 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 513 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
| 513 helper0.StartTransaction(transaction_factory_.get()); | 514 helper0.StartTransaction(transaction_factory_.get()); |
| 514 TransactionHelper helper1(kT1HostName, kT1Qtype, kT1RecordCount); | 515 TransactionHelper helper1(kT1HostName, kT1Qtype, kT1RecordCount); |
| 515 helper1.StartTransaction(transaction_factory_.get()); | 516 helper1.StartTransaction(transaction_factory_.get()); |
| 516 | 517 |
| 517 helper0.Cancel(); | 518 helper0.Cancel(); |
| 518 | 519 |
| 519 base::MessageLoop::current()->RunUntilIdle(); | 520 base::RunLoop().RunUntilIdle(); |
| 520 | 521 |
| 521 EXPECT_FALSE(helper0.has_completed()); | 522 EXPECT_FALSE(helper0.has_completed()); |
| 522 EXPECT_TRUE(helper1.has_completed()); | 523 EXPECT_TRUE(helper1.has_completed()); |
| 523 } | 524 } |
| 524 | 525 |
| 525 TEST_F(DnsTransactionTest, DestroyFactory) { | 526 TEST_F(DnsTransactionTest, DestroyFactory) { |
| 526 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 527 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
| 527 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | 528 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); |
| 528 | 529 |
| 529 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 530 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
| 530 helper0.StartTransaction(transaction_factory_.get()); | 531 helper0.StartTransaction(transaction_factory_.get()); |
| 531 | 532 |
| 532 // Destroying the client does not affect running requests. | 533 // Destroying the client does not affect running requests. |
| 533 transaction_factory_.reset(NULL); | 534 transaction_factory_.reset(NULL); |
| 534 | 535 |
| 535 base::MessageLoop::current()->RunUntilIdle(); | 536 base::RunLoop().RunUntilIdle(); |
| 536 | 537 |
| 537 EXPECT_TRUE(helper0.has_completed()); | 538 EXPECT_TRUE(helper0.has_completed()); |
| 538 } | 539 } |
| 539 | 540 |
| 540 TEST_F(DnsTransactionTest, CancelFromCallback) { | 541 TEST_F(DnsTransactionTest, CancelFromCallback) { |
| 541 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 542 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
| 542 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | 543 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); |
| 543 | 544 |
| 544 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 545 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
| 545 helper0.set_cancel_in_callback(); | 546 helper0.set_cancel_in_callback(); |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 config_.timeout = TestTimeouts::tiny_timeout(); | 994 config_.timeout = TestTimeouts::tiny_timeout(); |
| 994 ConfigureFactory(); | 995 ConfigureFactory(); |
| 995 | 996 |
| 996 TransactionHelper helper0(".", dns_protocol::kTypeA, ERR_INVALID_ARGUMENT); | 997 TransactionHelper helper0(".", dns_protocol::kTypeA, ERR_INVALID_ARGUMENT); |
| 997 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); | 998 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| 998 } | 999 } |
| 999 | 1000 |
| 1000 } // namespace | 1001 } // namespace |
| 1001 | 1002 |
| 1002 } // namespace net | 1003 } // namespace net |
| OLD | NEW |