Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: net/spdy/spdy_network_transaction_spdy2_unittest.cc

Issue 10836084: SPDY - Handle incomplete headers during server push. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 5112 matching lines...) Expand 10 before | Expand all | Expand 10 after
5123 EXPECT_TRUE(response2.headers->HasHeaderValue("version", "HTTP/1.1")); 5123 EXPECT_TRUE(response2.headers->HasHeaderValue("version", "HTTP/1.1"));
5124 5124
5125 // Read the final EOF (which will close the session) 5125 // Read the final EOF (which will close the session)
5126 data.RunFor(1); 5126 data.RunFor(1);
5127 5127
5128 // Verify that we consumed all test data. 5128 // Verify that we consumed all test data.
5129 EXPECT_TRUE(data.at_read_eof()); 5129 EXPECT_TRUE(data.at_read_eof());
5130 EXPECT_TRUE(data.at_write_eof()); 5130 EXPECT_TRUE(data.at_write_eof());
5131 } 5131 }
5132 5132
5133 TEST_P(SpdyNetworkTransactionSpdy2Test, ServerPushWithNoStatusHeaderFrames) {
Ryan Hamilton 2012/08/03 19:52:14 I want to confirm that if you run this test with t
ramant (doing other things) 2012/08/03 20:50:40 Yes it does. It crashes the code.
5134 // We push a stream and attempt to claim it before the headers come down.
5135 static const unsigned char kPushBodyFrame[] = {
5136 0x00, 0x00, 0x00, 0x02, // header, ID
5137 0x01, 0x00, 0x00, 0x06, // FIN, length
5138 'p', 'u', 's', 'h', 'e', 'd' // "pushed"
5139 };
5140 scoped_ptr<SpdyFrame>
5141 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
5142 scoped_ptr<SpdyFrame>
5143 stream1_body(ConstructSpdyBodyFrame(1, true));
5144 MockWrite writes[] = {
5145 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS),
5146 };
5147
5148 static const char* const kInitialHeaders[] = {
5149 "url",
5150 "http://www.google.com/foo.dat",
5151 };
5152 static const char* const kMiddleHeaders[] = {
5153 "hello",
5154 "bye",
5155 };
5156 scoped_ptr<SpdyFrame>
5157 stream2_syn(ConstructSpdyControlFrame(kInitialHeaders,
5158 arraysize(kInitialHeaders) / 2,
5159 false,
5160 2,
5161 LOWEST,
5162 SYN_STREAM,
5163 CONTROL_FLAG_NONE,
5164 NULL,
5165 0,
5166 1));
5167 scoped_ptr<SpdyFrame>
5168 stream2_headers1(ConstructSpdyControlFrame(kMiddleHeaders,
5169 arraysize(kMiddleHeaders) / 2,
5170 false,
5171 2,
5172 LOWEST,
5173 HEADERS,
5174 CONTROL_FLAG_NONE,
5175 NULL,
5176 0,
5177 0));
5178
5179 scoped_ptr<SpdyFrame>
5180 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1));
5181 MockRead reads[] = {
5182 CreateMockRead(*stream1_reply, 1),
5183 CreateMockRead(*stream2_syn, 2),
5184 CreateMockRead(*stream1_body, 3),
5185 CreateMockRead(*stream2_headers1, 4),
5186 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame),
5187 arraysize(kPushBodyFrame), 5),
5188 MockRead(ASYNC, 0, 6), // EOF
5189 };
5190
5191 DeterministicSocketData data(reads, arraysize(reads),
5192 writes, arraysize(writes));
5193
5194 NormalSpdyTransactionHelper helper(CreateGetRequest(),
5195 BoundNetLog(), GetParam(), NULL);
5196 helper.SetDeterministic();
5197 helper.AddDeterministicData(&data);
5198 helper.RunPreTestSetup();
5199
5200 HttpNetworkTransaction* trans = helper.trans();
5201
5202 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM,
5203 // the first HEADERS frame, and the body of the primary stream, but before
5204 // we've received the final HEADERS for the pushed stream.
5205 data.SetStop(4);
5206
5207 // Start the transaction.
5208 TestCompletionCallback callback;
5209 int rv = trans->Start(
5210 &CreateGetRequest(), callback.callback(), BoundNetLog());
5211 EXPECT_EQ(ERR_IO_PENDING, rv);
5212 data.Run();
5213 rv = callback.WaitForResult();
5214 EXPECT_EQ(0, rv);
5215
5216 // Request the pushed path. At this point, we've received the push, but the
5217 // headers are not yet complete.
5218 scoped_ptr<HttpNetworkTransaction> trans2(
5219 new HttpNetworkTransaction(helper.session()));
5220 rv = trans2->Start(
5221 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
5222 EXPECT_EQ(ERR_IO_PENDING, rv);
5223 data.RunFor(2);
5224 MessageLoop::current()->RunAllPending();
5225
5226 // Read the server push body.
5227 std::string result2;
5228 ReadResult(trans2.get(), &data, &result2);
5229 // Read the response body.
5230 std::string result;
5231 ReadResult(trans, &data, &result);
5232 EXPECT_EQ("hello!", result);
5233
5234 // Verify that we haven't received any push data.
5235 EXPECT_EQ("", result2);
5236
5237 // Verify the SYN_REPLY.
5238 // Copy the response info, because trans goes away.
5239 HttpResponseInfo response = *trans->GetResponseInfo();
5240 ASSERT_TRUE(trans2->GetResponseInfo() == NULL);
5241
5242 VerifyStreamsClosed(helper);
5243
5244 // Verify the SYN_REPLY.
5245 EXPECT_TRUE(response.headers != NULL);
5246 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
5247
5248 // Read the final EOF (which will close the session).
5249 data.RunFor(1);
5250
5251 // Verify that we consumed all test data.
5252 EXPECT_TRUE(data.at_read_eof());
5253 EXPECT_TRUE(data.at_write_eof());
5254 }
5255
5133 TEST_P(SpdyNetworkTransactionSpdy2Test, SynReplyWithHeaders) { 5256 TEST_P(SpdyNetworkTransactionSpdy2Test, SynReplyWithHeaders) {
5134 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 5257 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
5135 MockWrite writes[] = { CreateMockWrite(*req) }; 5258 MockWrite writes[] = { CreateMockWrite(*req) };
5136 5259
5137 static const char* const kInitialHeaders[] = { 5260 static const char* const kInitialHeaders[] = {
5138 "status", 5261 "status",
5139 "200 OK", 5262 "200 OK",
5140 "version", 5263 "version",
5141 "HTTP/1.1" 5264 "HTTP/1.1"
5142 }; 5265 };
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
5547 // And now we can allow everything else to run to completion. 5670 // And now we can allow everything else to run to completion.
5548 data.SetStop(10); 5671 data.SetStop(10);
5549 data.Run(); 5672 data.Run();
5550 EXPECT_EQ(OK, callback2.WaitForResult()); 5673 EXPECT_EQ(OK, callback2.WaitForResult());
5551 EXPECT_EQ(OK, callback3.WaitForResult()); 5674 EXPECT_EQ(OK, callback3.WaitForResult());
5552 5675
5553 helper.VerifyDataConsumed(); 5676 helper.VerifyDataConsumed();
5554 } 5677 }
5555 5678
5556 } // namespace net 5679 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698