| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 2041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2052 | 2052 |
| 2053 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 2053 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 2054 BoundNetLog(), GetParam(), NULL); | 2054 BoundNetLog(), GetParam(), NULL); |
| 2055 helper.RunToCompletion(&data); | 2055 helper.RunToCompletion(&data); |
| 2056 TransactionHelperResult out = helper.output(); | 2056 TransactionHelperResult out = helper.output(); |
| 2057 EXPECT_EQ(OK, out.rv); | 2057 EXPECT_EQ(OK, out.rv); |
| 2058 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 2058 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2059 EXPECT_EQ("hello!", out.response_data); | 2059 EXPECT_EQ("hello!", out.response_data); |
| 2060 } | 2060 } |
| 2061 | 2061 |
| 2062 // While we're doing a post, the server sends back a SYN_REPLY. | 2062 // While we're doing a post, the server sends the reply before upload completes. |
| 2063 TEST_P(SpdyNetworkTransactionTest, PostWithEarlySynReply) { | 2063 TEST_P(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { |
| 2064 static const char upload[] = { "hello!" }; | 2064 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 2065 ScopedVector<UploadElementReader> element_readers; | 2065 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2066 element_readers.push_back( | 2066 MockWrite writes[] = { |
| 2067 new UploadBytesElementReader(upload, sizeof(upload))); | 2067 CreateMockWrite(*req, 0), |
| 2068 UploadDataStream stream(element_readers.Pass(), 0); | 2068 CreateMockWrite(*body, 3), |
| 2069 | 2069 }; |
| 2070 // Setup the request | 2070 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 2071 HttpRequestInfo request; | |
| 2072 request.method = "POST"; | |
| 2073 request.url = GURL(kRequestUrl); | |
| 2074 request.upload_data_stream = &stream; | |
| 2075 | |
| 2076 scoped_ptr<SpdyFrame> stream_reply( | |
| 2077 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | |
| 2078 MockRead reads[] = { | 2071 MockRead reads[] = { |
| 2079 CreateMockRead(*stream_reply, 1), | 2072 CreateMockRead(*resp, 1), |
| 2073 CreateMockRead(*body, 2), |
| 2080 MockRead(ASYNC, 0, 4) // EOF | 2074 MockRead(ASYNC, 0, 4) // EOF |
| 2081 }; | 2075 }; |
| 2082 | 2076 |
| 2083 scoped_ptr<SpdyFrame> req( | 2077 // Write the request headers, and read the complete response |
| 2084 spdy_util_.ConstructSpdyPost( | 2078 // while still waiting for chunked request data. |
| 2085 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); | |
| 2086 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 2087 scoped_ptr<SpdyFrame> rst( | |
| 2088 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | |
| 2089 MockWrite writes[] = { | |
| 2090 CreateMockWrite(*req, 0), | |
| 2091 CreateMockWrite(*body, 2), | |
| 2092 CreateMockWrite(*rst, 3) | |
| 2093 }; | |
| 2094 | |
| 2095 DeterministicSocketData data(reads, arraysize(reads), | 2079 DeterministicSocketData data(reads, arraysize(reads), |
| 2096 writes, arraysize(writes)); | 2080 writes, arraysize(writes)); |
| 2097 NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, | 2081 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 2082 DEFAULT_PRIORITY, |
| 2098 BoundNetLog(), GetParam(), NULL); | 2083 BoundNetLog(), GetParam(), NULL); |
| 2099 helper.SetDeterministic(); | 2084 helper.SetDeterministic(); |
| 2100 helper.RunPreTestSetup(); | 2085 helper.RunPreTestSetup(); |
| 2101 helper.AddDeterministicData(&data); | 2086 helper.AddDeterministicData(&data); |
| 2102 HttpNetworkTransaction* trans = helper.trans(); | |
| 2103 | 2087 |
| 2104 TestCompletionCallback callback; | 2088 ASSERT_TRUE(helper.StartDefaultTest()); |
| 2105 int rv = trans->Start( | |
| 2106 &CreatePostRequest(), callback.callback(), BoundNetLog()); | |
| 2107 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 2108 | 2089 |
| 2109 data.RunFor(4); | 2090 // Process the request headers, SYN_REPLY, and response body. |
| 2110 rv = callback.WaitForResult(); | 2091 // The request body is still in flight. |
| 2111 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); | 2092 data.RunFor(3); |
| 2112 data.RunFor(1); | 2093 |
| 2094 const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 2095 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2096 |
| 2097 // Finish sending the request body. |
| 2098 helper.request().upload_data_stream->AppendChunk( |
| 2099 kUploadData, kUploadDataSize, true); |
| 2100 data.RunFor(2); |
| 2101 |
| 2102 std::string response_body; |
| 2103 EXPECT_EQ(OK, ReadTransaction(helper.trans(), &response_body)); |
| 2104 EXPECT_EQ(kUploadData, response_body); |
| 2105 helper.VerifyDataConsumed(); |
| 2113 } | 2106 } |
| 2114 | 2107 |
| 2115 // The client upon cancellation tries to send a RST_STREAM frame. The mock | 2108 // The client upon cancellation tries to send a RST_STREAM frame. The mock |
| 2116 // socket causes the TCP write to return zero. This test checks that the client | 2109 // socket causes the TCP write to return zero. This test checks that the client |
| 2117 // tries to queue up the RST_STREAM frame again. | 2110 // tries to queue up the RST_STREAM frame again. |
| 2118 TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { | 2111 TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
| 2119 scoped_ptr<SpdyFrame> req( | 2112 scoped_ptr<SpdyFrame> req( |
| 2120 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2113 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2121 scoped_ptr<SpdyFrame> rst( | 2114 scoped_ptr<SpdyFrame> rst( |
| 2122 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 2115 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| (...skipping 4381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6504 // since we're send-stalled. | 6497 // since we're send-stalled. |
| 6505 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); | 6498 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6506 | 6499 |
| 6507 // Read in WINDOW_UPDATE or SETTINGS frame. | 6500 // Read in WINDOW_UPDATE or SETTINGS frame. |
| 6508 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7); | 6501 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7); |
| 6509 rv = callback.WaitForResult(); | 6502 rv = callback.WaitForResult(); |
| 6510 helper.VerifyDataConsumed(); | 6503 helper.VerifyDataConsumed(); |
| 6511 } | 6504 } |
| 6512 | 6505 |
| 6513 } // namespace net | 6506 } // namespace net |
| OLD | NEW |