diff options
Diffstat (limited to 'net/http/http_network_transaction_unittest.cc')
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 337f6c7..340dfe4 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -18,6 +18,10 @@ //----------------------------------------------------------------------------- +namespace net { + +// TODO(eroman): Now that this is inside the net namespace, remove the redundant +// net:: qualifiers. struct MockConnect { // Asynchronous connection success. @@ -2560,3 +2564,64 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { EXPECT_EQ(100, response->headers->GetContentLength()); } } + +// Test the ResetStateForRestart() private method. +TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { + // Create a transaction (the dependencies aren't important). + scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); + scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction( + CreateSession(proxy_service.get()), &mock_socket_factory)); + + // Setup some state (which we expect ResetStateForRestart() will clear). + trans->header_buf_.reset(static_cast<char*>(malloc(10))); + trans->header_buf_capacity_ = 10; + trans->header_buf_len_ = 3; + trans->header_buf_body_offset_ = 11; + trans->header_buf_http_offset_ = 0; + trans->response_body_length_ = 100; + trans->response_body_read_ = 1; + trans->read_buf_ = new IOBuffer(15); + trans->read_buf_len_ = 15; + trans->request_headers_ = "Authorization: NTLM"; + trans->request_headers_bytes_sent_ = 3; + + // Setup state in response_ + trans->response_.auth_challenge = new AuthChallengeInfo(); + trans->response_.ssl_info.cert_status = -15; + trans->response_.response_time = base::Time::Now(); + trans->response_.was_cached = true; // (Wouldn't ever actually be true...) + + { // Setup state for response_.vary_data + HttpRequestInfo request; + std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); + std::replace(temp.begin(), temp.end(), '\n', '\0'); + scoped_refptr<HttpResponseHeaders> response = new HttpResponseHeaders(temp); + request.extra_headers = "Foo: 1\nbar: 23"; + EXPECT_TRUE(trans->response_.vary_data.Init(request, *response)); + } + + // Cause the above state to be reset. + trans->ResetStateForRestart(); + + // Verify that the state that needed to be reset, has been reset. + EXPECT_EQ(NULL, trans->header_buf_.get()); + EXPECT_EQ(0, trans->header_buf_capacity_); + EXPECT_EQ(0, trans->header_buf_len_); + EXPECT_EQ(-1, trans->header_buf_body_offset_); + EXPECT_EQ(-1, trans->header_buf_http_offset_); + EXPECT_EQ(-1, trans->response_body_length_); + EXPECT_EQ(0, trans->response_body_read_); + EXPECT_EQ(NULL, trans->read_buf_.get()); + EXPECT_EQ(0, trans->read_buf_len_); + EXPECT_EQ("", trans->request_headers_); + EXPECT_EQ(0U, trans->request_headers_bytes_sent_); + EXPECT_EQ(NULL, trans->response_.auth_challenge.get()); + EXPECT_EQ(NULL, trans->response_.headers.get()); + EXPECT_EQ(false, trans->response_.was_cached); + EXPECT_EQ(base::kInvalidPlatformFileValue, + trans->response_.response_data_file); + EXPECT_EQ(0, trans->response_.ssl_info.cert_status); + EXPECT_FALSE(trans->response_.vary_data.is_valid()); +} + +} // namespace net |