diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-21 03:46:06 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-21 03:46:06 +0000 |
commit | 89ceba9a484f853964e5504f14927a8cf7e72449 (patch) | |
tree | 5db8fb2d7cebebc53b107db44f521f078b66cf62 /net/http/http_network_transaction_unittest.cc | |
parent | d0ee935a4bdb1d111a4584ec4c0a03287bc43cd4 (diff) | |
download | chromium_src-89ceba9a484f853964e5504f14927a8cf7e72449.zip chromium_src-89ceba9a484f853964e5504f14927a8cf7e72449.tar.gz chromium_src-89ceba9a484f853964e5504f14927a8cf7e72449.tar.bz2 |
Fully reset HttpNetworkTransaction::response_ when restarting the transaction. The reset is done using the default constructor.
This is less fragile than resetting each member manually, and in fact not all members were being reset (for example, vary_data and ssl_info).
In the case of vary_data this could cause a subtle glitch, since calling HttpVaryData::Init() twice on the same object doesn't fully re-initialize.
The changes outside of http_network_transaction.cc are just a safety net -- it seemed reasonable to make HttpVaryData::Init() support the multiple-init model.
Review URL: http://codereview.chromium.org/50031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12243 0039d316-1c4b-4281-b951-d872f2087c98
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 |