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

Side by Side Diff: net/spdy/spdy_network_transaction_spdy3_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 5671 matching lines...) Expand 10 before | Expand all | Expand 10 after
5682 EXPECT_TRUE(response2.headers->HasHeaderValue("version", "HTTP/1.1")); 5682 EXPECT_TRUE(response2.headers->HasHeaderValue("version", "HTTP/1.1"));
5683 5683
5684 // Read the final EOF (which will close the session) 5684 // Read the final EOF (which will close the session)
5685 data.RunFor(1); 5685 data.RunFor(1);
5686 5686
5687 // Verify that we consumed all test data. 5687 // Verify that we consumed all test data.
5688 EXPECT_TRUE(data.at_read_eof()); 5688 EXPECT_TRUE(data.at_read_eof());
5689 EXPECT_TRUE(data.at_write_eof()); 5689 EXPECT_TRUE(data.at_write_eof());
5690 } 5690 }
5691 5691
5692 TEST_P(SpdyNetworkTransactionSpdy3Test, ServerPushWithNoStatusHeaderFrames) {
5693 // We push a stream and attempt to claim it before the headers come down.
5694 static const unsigned char kPushBodyFrame[] = {
5695 0x00, 0x00, 0x00, 0x02, // header, ID
5696 0x01, 0x00, 0x00, 0x06, // FIN, length
5697 'p', 'u', 's', 'h', 'e', 'd' // "pushed"
5698 };
5699 scoped_ptr<SpdyFrame>
5700 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
5701 scoped_ptr<SpdyFrame>
5702 stream1_body(ConstructSpdyBodyFrame(1, true));
5703 MockWrite writes[] = {
5704 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS),
5705 };
5706
5707 static const char* const kInitialHeaders[] = {
5708 ":scheme", "http",
5709 ":host", "www.google.com",
5710 ":path", "/foo.dat"
5711 };
5712 static const char* const kMiddleHeaders[] = {
5713 "hello",
5714 "bye",
5715 };
5716 scoped_ptr<SpdyFrame>
5717 stream2_syn(ConstructSpdyControlFrame(kInitialHeaders,
5718 arraysize(kInitialHeaders) / 2,
5719 false,
5720 2,
5721 LOWEST,
5722 SYN_STREAM,
5723 CONTROL_FLAG_NONE,
5724 NULL,
5725 0,
5726 1));
5727 scoped_ptr<SpdyFrame>
5728 stream2_headers1(ConstructSpdyControlFrame(kMiddleHeaders,
5729 arraysize(kMiddleHeaders) / 2,
5730 false,
5731 2,
5732 LOWEST,
5733 HEADERS,
5734 CONTROL_FLAG_NONE,
5735 NULL,
5736 0,
5737 0));
5738
5739 scoped_ptr<SpdyFrame>
5740 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1));
5741 MockRead reads[] = {
5742 CreateMockRead(*stream1_reply, 1),
5743 CreateMockRead(*stream2_syn, 2),
5744 CreateMockRead(*stream1_body, 3),
5745 CreateMockRead(*stream2_headers1, 4),
5746 MockRead(ASYNC, reinterpret_cast<const char*>(kPushBodyFrame),
5747 arraysize(kPushBodyFrame), 5),
5748 MockRead(ASYNC, 0, 6), // EOF
5749 };
5750
5751 DeterministicSocketData data(reads, arraysize(reads),
5752 writes, arraysize(writes));
5753
5754 NormalSpdyTransactionHelper helper(CreateGetRequest(),
5755 BoundNetLog(), GetParam(), NULL);
5756 helper.SetDeterministic();
5757 helper.AddDeterministicData(&data);
5758 helper.RunPreTestSetup();
5759
5760 HttpNetworkTransaction* trans = helper.trans();
5761
5762 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM,
5763 // the first HEADERS frame, and the body of the primary stream, but before
5764 // we've received the final HEADERS for the pushed stream.
5765 data.SetStop(4);
5766
5767 // Start the transaction.
5768 TestCompletionCallback callback;
5769 int rv = trans->Start(
5770 &CreateGetRequest(), callback.callback(), BoundNetLog());
5771 EXPECT_EQ(ERR_IO_PENDING, rv);
5772 data.Run();
5773 rv = callback.WaitForResult();
5774 EXPECT_EQ(0, rv);
5775
5776 // Request the pushed path. At this point, we've received the push, but the
5777 // headers are not yet complete.
5778 scoped_ptr<HttpNetworkTransaction> trans2(
5779 new HttpNetworkTransaction(helper.session()));
5780 rv = trans2->Start(
5781 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
5782 EXPECT_EQ(ERR_IO_PENDING, rv);
5783 data.RunFor(2);
5784 MessageLoop::current()->RunAllPending();
5785
5786 // Read the server push body.
5787 std::string result2;
5788 ReadResult(trans2.get(), &data, &result2);
5789 // Read the response body.
5790 std::string result;
5791 ReadResult(trans, &data, &result);
5792 EXPECT_EQ("hello!", result);
5793
5794 // Verify that we haven't received any push data.
5795 EXPECT_EQ("", result2);
5796
5797 // Verify the SYN_REPLY.
5798 // Copy the response info, because trans goes away.
5799 HttpResponseInfo response = *trans->GetResponseInfo();
5800 ASSERT_TRUE(trans2->GetResponseInfo() == NULL);
5801
5802 VerifyStreamsClosed(helper);
5803
5804 // Verify the SYN_REPLY.
5805 EXPECT_TRUE(response.headers != NULL);
5806 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
5807
5808 // Read the final EOF (which will close the session).
5809 data.RunFor(1);
5810
5811 // Verify that we consumed all test data.
5812 EXPECT_TRUE(data.at_read_eof());
5813 EXPECT_TRUE(data.at_write_eof());
5814 }
5815
5692 TEST_P(SpdyNetworkTransactionSpdy3Test, SynReplyWithHeaders) { 5816 TEST_P(SpdyNetworkTransactionSpdy3Test, SynReplyWithHeaders) {
5693 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 5817 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
5694 MockWrite writes[] = { CreateMockWrite(*req) }; 5818 MockWrite writes[] = { CreateMockWrite(*req) };
5695 5819
5696 static const char* const kInitialHeaders[] = { 5820 static const char* const kInitialHeaders[] = {
5697 ":status", 5821 ":status",
5698 "200 OK", 5822 "200 OK",
5699 ":version", 5823 ":version",
5700 "HTTP/1.1" 5824 "HTTP/1.1"
5701 }; 5825 };
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
6106 // And now we can allow everything else to run to completion. 6230 // And now we can allow everything else to run to completion.
6107 data.SetStop(10); 6231 data.SetStop(10);
6108 data.Run(); 6232 data.Run();
6109 EXPECT_EQ(OK, callback2.WaitForResult()); 6233 EXPECT_EQ(OK, callback2.WaitForResult());
6110 EXPECT_EQ(OK, callback3.WaitForResult()); 6234 EXPECT_EQ(OK, callback3.WaitForResult());
6111 6235
6112 helper.VerifyDataConsumed(); 6236 helper.VerifyDataConsumed();
6113 } 6237 }
6114 6238
6115 } // namespace net 6239 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_spdy2_unittest.cc ('k') | net/spdy/spdy_proxy_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698