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..65c26d9c81ab780865385a3b52395ce5450269ad 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 AddError(int error, IoMode mode) { |
|
mmenke
2014/08/01 15:38:42
Maybe AddReadError?
Deprecated (see juliatuttle)
2014/08/01 22:01:10
Done.
|
| + 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. |
| 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->AddError(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)), |
| + ASYNC, |
|
mmenke
2014/08/01 15:38:42
Maybe make this sync, too?
Deprecated (see juliatuttle)
2014/08/01 22:01:10
Done.
|
| + static_cast<uint16>(arraysize(kT0ResponseDatagram))); |
| + // Then return a 0-length read. |
| + data->AddError(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->AddError(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->AddError(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(); |