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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months 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_transaction.cc ('k') | net/dns/host_resolver_impl.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> 7 #include <stdint.h>
8
9 #include <limits> 8 #include <limits>
9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/sys_byteorder.h" 15 #include "base/sys_byteorder.h"
16 #include "base/test/test_timeouts.h" 16 #include "base/test/test_timeouts.h"
17 #include "net/dns/dns_protocol.h" 17 #include "net/dns/dns_protocol.h"
18 #include "net/dns/dns_query.h" 18 #include "net/dns/dns_query.h"
19 #include "net/dns/dns_response.h" 19 #include "net/dns/dns_response.h"
(...skipping 24 matching lines...) Expand all
44 IoMode mode, 44 IoMode mode,
45 bool use_tcp) 45 bool use_tcp)
46 : query_(new DnsQuery(id, DomainFromDot(dotted_name), qtype)), 46 : query_(new DnsQuery(id, DomainFromDot(dotted_name), qtype)),
47 use_tcp_(use_tcp) { 47 use_tcp_(use_tcp) {
48 if (use_tcp_) { 48 if (use_tcp_) {
49 scoped_ptr<uint16_t> length(new uint16_t); 49 scoped_ptr<uint16_t> length(new uint16_t);
50 *length = base::HostToNet16(query_->io_buffer()->size()); 50 *length = base::HostToNet16(query_->io_buffer()->size());
51 writes_.push_back(MockWrite(mode, 51 writes_.push_back(MockWrite(mode,
52 reinterpret_cast<const char*>(length.get()), 52 reinterpret_cast<const char*>(length.get()),
53 sizeof(uint16_t), num_reads_and_writes())); 53 sizeof(uint16_t), num_reads_and_writes()));
54 lengths_.push_back(length.Pass()); 54 lengths_.push_back(std::move(length));
55 } 55 }
56 writes_.push_back(MockWrite(mode, query_->io_buffer()->data(), 56 writes_.push_back(MockWrite(mode, query_->io_buffer()->data(),
57 query_->io_buffer()->size(), 57 query_->io_buffer()->size(),
58 num_reads_and_writes())); 58 num_reads_and_writes()));
59 } 59 }
60 ~DnsSocketData() {} 60 ~DnsSocketData() {}
61 61
62 // All responses must be added before GetProvider. 62 // All responses must be added before GetProvider.
63 63
64 // Adds pre-built DnsResponse. |tcp_length| will be used in TCP mode only. 64 // Adds pre-built DnsResponse. |tcp_length| will be used in TCP mode only.
65 void AddResponseWithLength(scoped_ptr<DnsResponse> response, 65 void AddResponseWithLength(scoped_ptr<DnsResponse> response,
66 IoMode mode, 66 IoMode mode,
67 uint16_t tcp_length) { 67 uint16_t tcp_length) {
68 CHECK(!provider_.get()); 68 CHECK(!provider_.get());
69 if (use_tcp_) { 69 if (use_tcp_) {
70 scoped_ptr<uint16_t> length(new uint16_t); 70 scoped_ptr<uint16_t> length(new uint16_t);
71 *length = base::HostToNet16(tcp_length); 71 *length = base::HostToNet16(tcp_length);
72 reads_.push_back(MockRead(mode, 72 reads_.push_back(MockRead(mode,
73 reinterpret_cast<const char*>(length.get()), 73 reinterpret_cast<const char*>(length.get()),
74 sizeof(uint16_t), num_reads_and_writes())); 74 sizeof(uint16_t), num_reads_and_writes()));
75 lengths_.push_back(length.Pass()); 75 lengths_.push_back(std::move(length));
76 } 76 }
77 reads_.push_back(MockRead(mode, response->io_buffer()->data(), 77 reads_.push_back(MockRead(mode, response->io_buffer()->data(),
78 response->io_buffer()->size(), 78 response->io_buffer()->size(),
79 num_reads_and_writes())); 79 num_reads_and_writes()));
80 responses_.push_back(response.Pass()); 80 responses_.push_back(std::move(response));
81 } 81 }
82 82
83 // Adds pre-built DnsResponse. 83 // Adds pre-built DnsResponse.
84 void AddResponse(scoped_ptr<DnsResponse> response, IoMode mode) { 84 void AddResponse(scoped_ptr<DnsResponse> response, IoMode mode) {
85 uint16_t tcp_length = response->io_buffer()->size(); 85 uint16_t tcp_length = response->io_buffer()->size();
86 AddResponseWithLength(response.Pass(), mode, tcp_length); 86 AddResponseWithLength(std::move(response), mode, tcp_length);
87 } 87 }
88 88
89 // Adds pre-built response from |data| buffer. 89 // Adds pre-built response from |data| buffer.
90 void AddResponseData(const uint8_t* data, size_t length, IoMode mode) { 90 void AddResponseData(const uint8_t* data, size_t length, IoMode mode) {
91 CHECK(!provider_.get()); 91 CHECK(!provider_.get());
92 AddResponse(make_scoped_ptr( 92 AddResponse(make_scoped_ptr(
93 new DnsResponse(reinterpret_cast<const char*>(data), length, 0)), mode); 93 new DnsResponse(reinterpret_cast<const char*>(data), length, 0)), mode);
94 } 94 }
95 95
96 // Add no-answer (RCODE only) response matching the query. 96 // Add no-answer (RCODE only) response matching the query.
97 void AddRcode(int rcode, IoMode mode) { 97 void AddRcode(int rcode, IoMode mode) {
98 scoped_ptr<DnsResponse> response( 98 scoped_ptr<DnsResponse> response(
99 new DnsResponse(query_->io_buffer()->data(), 99 new DnsResponse(query_->io_buffer()->data(),
100 query_->io_buffer()->size(), 100 query_->io_buffer()->size(),
101 0)); 101 0));
102 dns_protocol::Header* header = 102 dns_protocol::Header* header =
103 reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data()); 103 reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data());
104 header->flags |= base::HostToNet16(dns_protocol::kFlagResponse | rcode); 104 header->flags |= base::HostToNet16(dns_protocol::kFlagResponse | rcode);
105 AddResponse(response.Pass(), mode); 105 AddResponse(std::move(response), mode);
106 } 106 }
107 107
108 // Add error response. 108 // Add error response.
109 void AddReadError(int error, IoMode mode) { 109 void AddReadError(int error, IoMode mode) {
110 reads_.push_back(MockRead(mode, error, num_reads_and_writes())); 110 reads_.push_back(MockRead(mode, error, num_reads_and_writes()));
111 } 111 }
112 112
113 // Build, if needed, and return the SocketDataProvider. No new responses 113 // Build, if needed, and return the SocketDataProvider. No new responses
114 // should be added afterwards. 114 // should be added afterwards.
115 SequencedSocketData* GetProvider() { 115 SequencedSocketData* GetProvider() {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 NetLog* net_log, 190 NetLog* net_log,
191 const NetLog::Source& source) override { 191 const NetLog::Source& source) override {
192 if (fail_next_socket_) { 192 if (fail_next_socket_) {
193 fail_next_socket_ = false; 193 fail_next_socket_ = false;
194 return scoped_ptr<DatagramClientSocket>( 194 return scoped_ptr<DatagramClientSocket>(
195 new FailingUDPClientSocket(&empty_data_, net_log)); 195 new FailingUDPClientSocket(&empty_data_, net_log));
196 } 196 }
197 SocketDataProvider* data_provider = mock_data().GetNext(); 197 SocketDataProvider* data_provider = mock_data().GetNext();
198 scoped_ptr<TestUDPClientSocket> socket( 198 scoped_ptr<TestUDPClientSocket> socket(
199 new TestUDPClientSocket(this, data_provider, net_log)); 199 new TestUDPClientSocket(this, data_provider, net_log));
200 return socket.Pass(); 200 return std::move(socket);
201 } 201 }
202 202
203 void OnConnect(const IPEndPoint& endpoint) { 203 void OnConnect(const IPEndPoint& endpoint) {
204 remote_endpoints_.push_back(endpoint); 204 remote_endpoints_.push_back(endpoint);
205 } 205 }
206 206
207 std::vector<IPEndPoint> remote_endpoints_; 207 std::vector<IPEndPoint> remote_endpoints_;
208 bool fail_next_socket_; 208 bool fail_next_socket_;
209 209
210 private: 210 private:
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 DnsSocketPool::CreateNull(socket_factory_.get()), 353 DnsSocketPool::CreateNull(socket_factory_.get()),
354 base::Bind(&DnsTransactionTest::GetNextId, base::Unretained(this)), 354 base::Bind(&DnsTransactionTest::GetNextId, base::Unretained(this)),
355 NULL /* NetLog */); 355 NULL /* NetLog */);
356 transaction_factory_ = DnsTransactionFactory::CreateFactory(session_.get()); 356 transaction_factory_ = DnsTransactionFactory::CreateFactory(session_.get());
357 } 357 }
358 358
359 void AddSocketData(scoped_ptr<DnsSocketData> data) { 359 void AddSocketData(scoped_ptr<DnsSocketData> data) {
360 CHECK(socket_factory_.get()); 360 CHECK(socket_factory_.get());
361 transaction_ids_.push_back(data->query_id()); 361 transaction_ids_.push_back(data->query_id());
362 socket_factory_->AddSocketDataProvider(data->GetProvider()); 362 socket_factory_->AddSocketDataProvider(data->GetProvider());
363 socket_data_.push_back(data.Pass()); 363 socket_data_.push_back(std::move(data));
364 } 364 }
365 365
366 // 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
367 // 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
368 // |data| should equal |id|, unless testing mismatched response. 368 // |data| should equal |id|, unless testing mismatched response.
369 void AddQueryAndResponse(uint16_t id, 369 void AddQueryAndResponse(uint16_t id,
370 const char* dotted_name, 370 const char* dotted_name,
371 uint16_t qtype, 371 uint16_t qtype,
372 const uint8_t* response_data, 372 const uint8_t* response_data,
373 size_t response_length, 373 size_t response_length,
374 IoMode mode, 374 IoMode mode,
375 bool use_tcp) { 375 bool use_tcp) {
376 CHECK(socket_factory_.get()); 376 CHECK(socket_factory_.get());
377 scoped_ptr<DnsSocketData> data( 377 scoped_ptr<DnsSocketData> data(
378 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp)); 378 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp));
379 data->AddResponseData(response_data, response_length, mode); 379 data->AddResponseData(response_data, response_length, mode);
380 AddSocketData(data.Pass()); 380 AddSocketData(std::move(data));
381 } 381 }
382 382
383 void AddAsyncQueryAndResponse(uint16_t id, 383 void AddAsyncQueryAndResponse(uint16_t id,
384 const char* dotted_name, 384 const char* dotted_name,
385 uint16_t qtype, 385 uint16_t qtype,
386 const uint8_t* data, 386 const uint8_t* data,
387 size_t data_length) { 387 size_t data_length) {
388 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, ASYNC, 388 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, ASYNC,
389 false); 389 false);
390 } 390 }
391 391
392 void AddSyncQueryAndResponse(uint16_t id, 392 void AddSyncQueryAndResponse(uint16_t id,
393 const char* dotted_name, 393 const char* dotted_name,
394 uint16_t qtype, 394 uint16_t qtype,
395 const uint8_t* data, 395 const uint8_t* data,
396 size_t data_length) { 396 size_t data_length) {
397 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, SYNCHRONOUS, 397 AddQueryAndResponse(id, dotted_name, qtype, data, data_length, SYNCHRONOUS,
398 false); 398 false);
399 } 399 }
400 400
401 // Add expected query of |dotted_name| and |qtype| and no response. 401 // Add expected query of |dotted_name| and |qtype| and no response.
402 void AddQueryAndTimeout(const char* dotted_name, uint16_t qtype) { 402 void AddQueryAndTimeout(const char* dotted_name, uint16_t qtype) {
403 uint16_t id = base::RandInt(0, std::numeric_limits<uint16_t>::max()); 403 uint16_t id = base::RandInt(0, std::numeric_limits<uint16_t>::max());
404 scoped_ptr<DnsSocketData> data( 404 scoped_ptr<DnsSocketData> data(
405 new DnsSocketData(id, dotted_name, qtype, ASYNC, false)); 405 new DnsSocketData(id, dotted_name, qtype, ASYNC, false));
406 AddSocketData(data.Pass()); 406 AddSocketData(std::move(data));
407 } 407 }
408 408
409 // 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
410 // 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.
411 void AddQueryAndRcode(const char* dotted_name, 411 void AddQueryAndRcode(const char* dotted_name,
412 uint16_t qtype, 412 uint16_t qtype,
413 int rcode, 413 int rcode,
414 IoMode mode, 414 IoMode mode,
415 bool use_tcp) { 415 bool use_tcp) {
416 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode); 416 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode);
417 uint16_t id = base::RandInt(0, std::numeric_limits<uint16_t>::max()); 417 uint16_t id = base::RandInt(0, std::numeric_limits<uint16_t>::max());
418 scoped_ptr<DnsSocketData> data( 418 scoped_ptr<DnsSocketData> data(
419 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp)); 419 new DnsSocketData(id, dotted_name, qtype, mode, use_tcp));
420 data->AddRcode(rcode, mode); 420 data->AddRcode(rcode, mode);
421 AddSocketData(data.Pass()); 421 AddSocketData(std::move(data));
422 } 422 }
423 423
424 void AddAsyncQueryAndRcode(const char* dotted_name, 424 void AddAsyncQueryAndRcode(const char* dotted_name,
425 uint16_t qtype, 425 uint16_t qtype,
426 int rcode) { 426 int rcode) {
427 AddQueryAndRcode(dotted_name, qtype, rcode, ASYNC, false); 427 AddQueryAndRcode(dotted_name, qtype, rcode, ASYNC, false);
428 } 428 }
429 429
430 void AddSyncQueryAndRcode(const char* dotted_name, 430 void AddSyncQueryAndRcode(const char* dotted_name,
431 uint16_t qtype, 431 uint16_t qtype,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 config_.timeout = TestTimeouts::tiny_timeout(); 555 config_.timeout = TestTimeouts::tiny_timeout();
556 ConfigureFactory(); 556 ConfigureFactory();
557 557
558 // Attempt receives mismatched response followed by valid response. 558 // Attempt receives mismatched response followed by valid response.
559 scoped_ptr<DnsSocketData> data( 559 scoped_ptr<DnsSocketData> data(
560 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, SYNCHRONOUS, false)); 560 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, SYNCHRONOUS, false));
561 data->AddResponseData(kT1ResponseDatagram, 561 data->AddResponseData(kT1ResponseDatagram,
562 arraysize(kT1ResponseDatagram), SYNCHRONOUS); 562 arraysize(kT1ResponseDatagram), SYNCHRONOUS);
563 data->AddResponseData(kT0ResponseDatagram, 563 data->AddResponseData(kT0ResponseDatagram,
564 arraysize(kT0ResponseDatagram), SYNCHRONOUS); 564 arraysize(kT0ResponseDatagram), SYNCHRONOUS);
565 AddSocketData(data.Pass()); 565 AddSocketData(std::move(data));
566 566
567 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); 567 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount);
568 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); 568 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get()));
569 } 569 }
570 570
571 TEST_F(DnsTransactionTest, MismatchedResponseAsync) { 571 TEST_F(DnsTransactionTest, MismatchedResponseAsync) {
572 config_.attempts = 2; 572 config_.attempts = 2;
573 config_.timeout = TestTimeouts::tiny_timeout(); 573 config_.timeout = TestTimeouts::tiny_timeout();
574 ConfigureFactory(); 574 ConfigureFactory();
575 575
576 // First attempt receives mismatched response followed by valid response. 576 // First attempt receives mismatched response followed by valid response.
577 // Second attempt times out. 577 // Second attempt times out.
578 scoped_ptr<DnsSocketData> data( 578 scoped_ptr<DnsSocketData> data(
579 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, false)); 579 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, false));
580 data->AddResponseData(kT1ResponseDatagram, 580 data->AddResponseData(kT1ResponseDatagram,
581 arraysize(kT1ResponseDatagram), ASYNC); 581 arraysize(kT1ResponseDatagram), ASYNC);
582 data->AddResponseData(kT0ResponseDatagram, 582 data->AddResponseData(kT0ResponseDatagram,
583 arraysize(kT0ResponseDatagram), ASYNC); 583 arraysize(kT0ResponseDatagram), ASYNC);
584 AddSocketData(data.Pass()); 584 AddSocketData(std::move(data));
585 AddQueryAndTimeout(kT0HostName, kT0Qtype); 585 AddQueryAndTimeout(kT0HostName, kT0Qtype);
586 586
587 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); 587 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount);
588 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); 588 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get()));
589 } 589 }
590 590
591 TEST_F(DnsTransactionTest, MismatchedResponseFail) { 591 TEST_F(DnsTransactionTest, MismatchedResponseFail) {
592 config_.timeout = TestTimeouts::tiny_timeout(); 592 config_.timeout = TestTimeouts::tiny_timeout();
593 ConfigureFactory(); 593 ConfigureFactory();
594 594
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); 906 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true));
907 // Valid response but length too short. 907 // Valid response but length too short.
908 // This must be truncated in the question section. The DnsResponse doesn't 908 // This must be truncated in the question section. The DnsResponse doesn't
909 // examine the answer section until asked to parse it, so truncating it in 909 // examine the answer section until asked to parse it, so truncating it in
910 // the answer section would result in the DnsTransaction itself succeeding. 910 // the answer section would result in the DnsTransaction itself succeeding.
911 data->AddResponseWithLength( 911 data->AddResponseWithLength(
912 make_scoped_ptr( 912 make_scoped_ptr(
913 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), 913 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram),
914 arraysize(kT0ResponseDatagram), 0)), 914 arraysize(kT0ResponseDatagram), 0)),
915 ASYNC, static_cast<uint16_t>(kT0QuerySize - 1)); 915 ASYNC, static_cast<uint16_t>(kT0QuerySize - 1));
916 AddSocketData(data.Pass()); 916 AddSocketData(std::move(data));
917 917
918 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_DNS_MALFORMED_RESPONSE); 918 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_DNS_MALFORMED_RESPONSE);
919 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 919 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
920 } 920 }
921 921
922 TEST_F(DnsTransactionTest, TCPTimeout) { 922 TEST_F(DnsTransactionTest, TCPTimeout) {
923 config_.timeout = TestTimeouts::tiny_timeout(); 923 config_.timeout = TestTimeouts::tiny_timeout();
924 ConfigureFactory(); 924 ConfigureFactory();
925 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, 925 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
926 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); 926 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
(...skipping 10 matching lines...) Expand all
937 scoped_ptr<DnsSocketData> data( 937 scoped_ptr<DnsSocketData> data(
938 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); 938 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true));
939 // Return all but the last byte of the response. 939 // Return all but the last byte of the response.
940 data->AddResponseWithLength( 940 data->AddResponseWithLength(
941 make_scoped_ptr( 941 make_scoped_ptr(
942 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), 942 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram),
943 arraysize(kT0ResponseDatagram) - 1, 0)), 943 arraysize(kT0ResponseDatagram) - 1, 0)),
944 ASYNC, static_cast<uint16_t>(arraysize(kT0ResponseDatagram))); 944 ASYNC, static_cast<uint16_t>(arraysize(kT0ResponseDatagram)));
945 // Then return a 0-length read. 945 // Then return a 0-length read.
946 data->AddReadError(0, ASYNC); 946 data->AddReadError(0, ASYNC);
947 AddSocketData(data.Pass()); 947 AddSocketData(std::move(data));
948 948
949 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); 949 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED);
950 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 950 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
951 } 951 }
952 952
953 TEST_F(DnsTransactionTest, TCPReadReturnsZeroSynchronous) { 953 TEST_F(DnsTransactionTest, TCPReadReturnsZeroSynchronous) {
954 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, 954 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
955 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); 955 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
956 scoped_ptr<DnsSocketData> data( 956 scoped_ptr<DnsSocketData> data(
957 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); 957 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true));
958 // Return all but the last byte of the response. 958 // Return all but the last byte of the response.
959 data->AddResponseWithLength( 959 data->AddResponseWithLength(
960 make_scoped_ptr( 960 make_scoped_ptr(
961 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), 961 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram),
962 arraysize(kT0ResponseDatagram) - 1, 0)), 962 arraysize(kT0ResponseDatagram) - 1, 0)),
963 SYNCHRONOUS, static_cast<uint16_t>(arraysize(kT0ResponseDatagram))); 963 SYNCHRONOUS, static_cast<uint16_t>(arraysize(kT0ResponseDatagram)));
964 // Then return a 0-length read. 964 // Then return a 0-length read.
965 data->AddReadError(0, SYNCHRONOUS); 965 data->AddReadError(0, SYNCHRONOUS);
966 AddSocketData(data.Pass()); 966 AddSocketData(std::move(data));
967 967
968 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); 968 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED);
969 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 969 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
970 } 970 }
971 971
972 TEST_F(DnsTransactionTest, TCPConnectionClosedAsync) { 972 TEST_F(DnsTransactionTest, TCPConnectionClosedAsync) {
973 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, 973 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
974 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); 974 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
975 scoped_ptr<DnsSocketData> data( 975 scoped_ptr<DnsSocketData> data(
976 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); 976 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true));
977 data->AddReadError(ERR_CONNECTION_CLOSED, ASYNC); 977 data->AddReadError(ERR_CONNECTION_CLOSED, ASYNC);
978 AddSocketData(data.Pass()); 978 AddSocketData(std::move(data));
979 979
980 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); 980 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED);
981 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 981 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
982 } 982 }
983 983
984 TEST_F(DnsTransactionTest, TCPConnectionClosedSynchronous) { 984 TEST_F(DnsTransactionTest, TCPConnectionClosedSynchronous) {
985 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, 985 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
986 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); 986 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
987 scoped_ptr<DnsSocketData> data( 987 scoped_ptr<DnsSocketData> data(
988 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); 988 new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true));
989 data->AddReadError(ERR_CONNECTION_CLOSED, SYNCHRONOUS); 989 data->AddReadError(ERR_CONNECTION_CLOSED, SYNCHRONOUS);
990 AddSocketData(data.Pass()); 990 AddSocketData(std::move(data));
991 991
992 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); 992 TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED);
993 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 993 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
994 } 994 }
995 995
996 TEST_F(DnsTransactionTest, InvalidQuery) { 996 TEST_F(DnsTransactionTest, InvalidQuery) {
997 config_.timeout = TestTimeouts::tiny_timeout(); 997 config_.timeout = TestTimeouts::tiny_timeout();
998 ConfigureFactory(); 998 ConfigureFactory();
999 999
1000 TransactionHelper helper0(".", dns_protocol::kTypeA, ERR_INVALID_ARGUMENT); 1000 TransactionHelper helper0(".", dns_protocol::kTypeA, ERR_INVALID_ARGUMENT);
1001 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 1001 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
1002 } 1002 }
1003 1003
1004 } // namespace 1004 } // namespace
1005 1005
1006 } // namespace net 1006 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_transaction.cc ('k') | net/dns/host_resolver_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698