Chromium Code Reviews| Index: net/dns/dns_transaction_unittest.cc |
| diff --git a/net/dns/dns_transaction_unittest.cc b/net/dns/dns_transaction_unittest.cc |
| index 67a045719b054f08a865799fe6e4bcf44bcfe38a..c8976fc971d4274448d73ead6190706009919c4d 100644 |
| --- a/net/dns/dns_transaction_unittest.cc |
| +++ b/net/dns/dns_transaction_unittest.cc |
| @@ -100,6 +100,11 @@ class DnsSocketData { |
| AddResponse(response.Pass(), mode); |
| } |
| + // Add error response. |
| + void AddReadError(int error, IoMode mode) { |
| + reads_.push_back(MockRead(mode, error)); |
| + } |
| + |
| // Build, if needed, and return the SocketDataProvider. No new responses |
| // should be added afterwards. |
| SocketDataProvider* GetProvider() { |
| @@ -902,6 +907,9 @@ TEST_F(DnsTransactionTest, TCPMalformed) { |
| scoped_ptr<DnsSocketData> data( |
| new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); |
| // Valid response but length too short. |
| + // This is truncated in the question section since the DnsResponse doesn't |
| + // examine the answer section until asked to parse it, so the transaction |
| + // itself succeeds. |
|
mmenke
2014/08/04 15:44:28
Add a period after section, and capitalize since.
mmenke
2014/08/04 15:44:28
Also, should the "question section" be replaced wi
Deprecated (see juliatuttle)
2014/08/04 19:29:23
Done.
Deprecated (see juliatuttle)
2014/08/04 19:29:23
Done.
|
| data->AddResponseWithLength( |
| make_scoped_ptr( |
| new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), |
| @@ -926,6 +934,70 @@ TEST_F(DnsTransactionTest, TCPTimeout) { |
| EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); |
| } |
| +TEST_F(DnsTransactionTest, TCPReadReturnsZeroAsync) { |
| + AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, |
| + dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); |
| + scoped_ptr<DnsSocketData> data( |
| + new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); |
| + // Return all but the last byte of the response. |
| + data->AddResponseWithLength( |
| + make_scoped_ptr( |
| + new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), |
| + arraysize(kT0ResponseDatagram) - 1, 0)), |
| + ASYNC, |
| + static_cast<uint16>(arraysize(kT0ResponseDatagram))); |
| + // Then return a 0-length read. |
| + data->AddReadError(0, ASYNC); |
| + AddSocketData(data.Pass()); |
| + |
| + TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); |
| + EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| +} |
| + |
| +TEST_F(DnsTransactionTest, TCPReadReturnsZeroSynchronous) { |
| + AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, |
| + dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); |
| + scoped_ptr<DnsSocketData> data( |
| + new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); |
| + // Return all but the last byte of the response. |
| + data->AddResponseWithLength( |
| + make_scoped_ptr( |
| + new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), |
| + arraysize(kT0ResponseDatagram) - 1, 0)), |
| + SYNCHRONOUS, |
| + static_cast<uint16>(arraysize(kT0ResponseDatagram))); |
| + // Then return a 0-length read. |
| + data->AddReadError(0, SYNCHRONOUS); |
| + AddSocketData(data.Pass()); |
| + |
| + TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); |
| + EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| +} |
| + |
| +TEST_F(DnsTransactionTest, TCPConnectionClosedAsync) { |
| + AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, |
| + dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); |
| + scoped_ptr<DnsSocketData> data( |
| + new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); |
| + data->AddReadError(ERR_CONNECTION_CLOSED, ASYNC); |
| + AddSocketData(data.Pass()); |
| + |
| + TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); |
| + EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| +} |
| + |
| +TEST_F(DnsTransactionTest, TCPConnectionClosedSynchronous) { |
| + AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, |
| + dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); |
| + scoped_ptr<DnsSocketData> data( |
| + new DnsSocketData(0 /* id */, kT0HostName, kT0Qtype, ASYNC, true)); |
| + data->AddReadError(ERR_CONNECTION_CLOSED, SYNCHRONOUS); |
| + AddSocketData(data.Pass()); |
| + |
| + TransactionHelper helper0(kT0HostName, kT0Qtype, ERR_CONNECTION_CLOSED); |
| + EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| +} |
| + |
| TEST_F(DnsTransactionTest, InvalidQuery) { |
| config_.timeout = TestTimeouts::tiny_timeout(); |
| ConfigureFactory(); |