summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorwtc@google.com <wtc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-26 19:44:25 +0000
committerwtc@google.com <wtc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-26 19:44:25 +0000
commit3d2a59b8aa0bfdc78a55bd291bacc099fc486763 (patch)
tree785f8285bc6a6b5a10bc5280ddf22119526cca83 /net
parentd5f942bab2af72892413a3080fb7468b0bbef713 (diff)
downloadchromium_src-3d2a59b8aa0bfdc78a55bd291bacc099fc486763.zip
chromium_src-3d2a59b8aa0bfdc78a55bd291bacc099fc486763.tar.gz
chromium_src-3d2a59b8aa0bfdc78a55bd291bacc099fc486763.tar.bz2
Add positive and negative test cases for whether we
should resend a request when we read nothing or get a read failure. R=darin,eroman BUG=2489 Review URL: http://codereview.chromium.org/4291 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2635 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_network_transaction_unittest.cc96
1 files changed, 86 insertions, 10 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 37670ed..93caaf5 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -169,6 +169,9 @@ class HttpNetworkTransactionTest : public PlatformTest {
mock_sockets[0] = NULL;
mock_sockets_index = 0;
}
+
+ protected:
+ void KeepAliveConnectionResendRequestTest(const MockRead& read_failure);
};
struct SimpleGetHelperResult {
@@ -278,8 +281,8 @@ TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) {
{ false, net::OK, NULL, 0 },
};
SimpleGetHelperResult out = SimpleGetHelper(data_reads);
- EXPECT_TRUE(out.status_line == "HTTP/0.9 200 OK");
- EXPECT_TRUE(out.response_data == "xxxxxHTTP/1.1 404 Not Found\nServer: blah");
+ EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
+ EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data);
}
// Same as StatusLineJunk4Bytes, except the read chunks are smaller.
@@ -364,12 +367,12 @@ TEST_F(HttpNetworkTransactionTest, ReuseConnection) {
EXPECT_TRUE(response != NULL);
EXPECT_TRUE(response->headers != NULL);
- EXPECT_TRUE(response->headers->GetStatusLine() == "HTTP/1.1 200 OK");
+ EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
std::string response_data;
rv = ReadTransaction(trans, &response_data);
EXPECT_EQ(net::OK, rv);
- EXPECT_TRUE(response_data == kExpectedResponseData[i]);
+ EXPECT_EQ(kExpectedResponseData[i], response_data);
trans->Destroy();
@@ -414,12 +417,12 @@ TEST_F(HttpNetworkTransactionTest, Ignores100) {
EXPECT_TRUE(response != NULL);
EXPECT_TRUE(response->headers != NULL);
- EXPECT_TRUE(response->headers->GetStatusLine() == "HTTP/1.0 200 OK");
+ EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
std::string response_data;
rv = ReadTransaction(trans, &response_data);
EXPECT_EQ(net::OK, rv);
- EXPECT_TRUE(response_data == "hello world");
+ EXPECT_EQ("hello world", response_data);
trans->Destroy();
@@ -427,7 +430,10 @@ TEST_F(HttpNetworkTransactionTest, Ignores100) {
MessageLoop::current()->RunAllPending();
}
-TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) {
+// read_failure specifies a read failure that should cause the network
+// transaction to resend the request.
+void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
+ const MockRead& read_failure) {
scoped_refptr<net::HttpNetworkSession> session = CreateSession();
net::HttpRequestInfo request;
@@ -438,7 +444,7 @@ TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) {
MockRead data1_reads[] = {
{ true, 0, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n", -1 },
{ true, 0, "hello", -1 },
- { true, net::ERR_CONNECTION_RESET, NULL, 0 },
+ read_failure, // Now, we reuse the connection and fail the first read.
};
MockSocket data1;
data1.connect.async = true;
@@ -477,12 +483,12 @@ TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) {
EXPECT_TRUE(response != NULL);
EXPECT_TRUE(response->headers != NULL);
- EXPECT_TRUE(response->headers->GetStatusLine() == "HTTP/1.1 200 OK");
+ EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
std::string response_data;
rv = ReadTransaction(trans, &response_data);
EXPECT_EQ(net::OK, rv);
- EXPECT_TRUE(response_data == kExpectedResponseData[i]);
+ EXPECT_EQ(kExpectedResponseData[i], response_data);
trans->Destroy();
@@ -490,3 +496,73 @@ TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) {
MessageLoop::current()->RunAllPending();
}
}
+
+TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) {
+ MockRead read_failure = { true, net::ERR_CONNECTION_RESET, NULL, 0 };
+ KeepAliveConnectionResendRequestTest(read_failure);
+}
+
+TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) {
+ MockRead read_failure = { false, net::OK, NULL, 0 }; // EOF
+ KeepAliveConnectionResendRequestTest(read_failure);
+}
+
+TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
+ net::HttpTransaction* trans = new net::HttpNetworkTransaction(
+ CreateSession(), &mock_socket_factory);
+
+ net::HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.google.com/");
+ request.load_flags = 0;
+
+ MockRead data_reads[] = {
+ { true, net::ERR_CONNECTION_RESET, NULL, 0 },
+ { true, 0, "HTTP/1.0 200 OK\r\n\r\n", -1 }, // Should not be used
+ { true, 0, "hello world", -1 },
+ { false, net::OK, NULL, 0 },
+ };
+ MockSocket data;
+ data.connect.async = true;
+ data.connect.result = net::OK;
+ data.reads = data_reads;
+ mock_sockets[0] = &data;
+ mock_sockets[1] = NULL;
+
+ TestCompletionCallback callback;
+
+ int rv = trans->Start(&request, &callback);
+ EXPECT_EQ(net::ERR_IO_PENDING, rv);
+
+ rv = callback.WaitForResult();
+ EXPECT_EQ(net::ERR_CONNECTION_RESET, rv);
+
+ const net::HttpResponseInfo* response = trans->GetResponseInfo();
+ EXPECT_TRUE(response == NULL);
+
+ trans->Destroy();
+
+ // Empty the current queue.
+ MessageLoop::current()->RunAllPending();
+}
+
+// What do various browsers do when the server closes a non-keepalive
+// connection without sending any response header or body?
+//
+// IE7: error page
+// Safari 3.1.2 (Windows): error page
+// Firefox 3.0.1: blank page
+// Opera 9.52: after five attempts, blank page
+// Us with WinHTTP: error page (net::ERR_INVALID_RESPONSE)
+// Us: blank page
+TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) {
+ MockRead data_reads[] = {
+ { false, net::OK, NULL, 0 }, // EOF
+ { true, 0, "HTTP/1.0 200 OK\r\n\r\n", -1 }, // Should not be used
+ { true, 0, "hello world", -1 },
+ { false, net::OK, NULL, 0 },
+ };
+ SimpleGetHelperResult out = SimpleGetHelper(data_reads);
+ EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
+ EXPECT_EQ("", out.response_data);
+}