diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 12 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 156 | ||||
-rw-r--r-- | net/spdy/spdy_test_util.cc | 136 | ||||
-rw-r--r-- | net/spdy/spdy_test_util.h | 108 |
4 files changed, 226 insertions, 186 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index e0a679b..498ded3 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -5154,10 +5154,10 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { MockWrite spdy_writes[] = { CreateMockWrite(req.get()) }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame()); MockRead spdy_reads[] = { CreateMockRead(resp.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(data.get()), MockRead(true, 0, 0), }; @@ -5290,11 +5290,11 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame()); MockRead spdy_reads[] = { MockRead(true, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 CreateMockRead(resp.get(), 4), // 2, 4 - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), // 5 - arraysize(kGetBodyFrame), 4), + CreateMockRead(data.get(), 4), // 5 MockRead(true, 0, 0, 4), // 6 }; @@ -5384,10 +5384,10 @@ TEST_F(HttpNetworkTransactionTest, MockWrite spdy_writes[] = { CreateMockWrite(req.get()) }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> data(ConstructSpdyBodyFrame()); MockRead spdy_reads[] = { CreateMockRead(resp.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(data.get()), MockRead(true, 0, 0), }; diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index 8c3198a..915a4d4 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -197,10 +197,10 @@ TEST_F(SpdyNetworkTransactionTest, Get) { MockWrite writes[] = { CreateMockWrite(req.get()) }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(resp.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -217,27 +217,26 @@ TEST_F(SpdyNetworkTransactionTest, Get) { // Test that a simple POST works. TEST_F(SpdyNetworkTransactionTest, Post) { - static const char upload[] = { "hello world" }; + static const char upload[] = { "hello!" }; // Setup the request HttpRequestInfo request; request.method = "POST"; request.url = GURL("http://www.google.com/"); request.upload_data = new UploadData(); - request.upload_data->AppendBytes(upload, sizeof(upload)); + request.upload_data->AppendBytes(upload, strlen(upload)); + scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPost(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockWrite writes[] = { - MockWrite(true, reinterpret_cast<const char*>(kPostSyn), - arraysize(kPostSyn)), - MockWrite(true, reinterpret_cast<const char*>(kPostUploadFrame), - arraysize(kPostUploadFrame)), + CreateMockWrite(req.get()), + CreateMockWrite(body.get()), // POST upload frame }; + scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); MockRead reads[] = { - MockRead(true, reinterpret_cast<const char*>(kPostSynReply), - arraysize(kPostSynReply)), - MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), - arraysize(kPostBodyFrame)), + CreateMockRead(resp.get()), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -253,22 +252,6 @@ TEST_F(SpdyNetworkTransactionTest, Post) { // Test that a simple POST works. TEST_F(SpdyNetworkTransactionTest, EmptyPost) { - static const unsigned char kEmptyPostSyn[] = { - 0x80, 0x01, 0x00, 0x01, // header - 0x01, 0x00, 0x00, 0x4a, // flags, len - 0x00, 0x00, 0x00, 0x01, // stream id - 0x00, 0x00, 0x00, 0x00, // associated - 0xc0, 0x00, 0x00, 0x03, // 3 headers - 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', - 0x00, 0x04, 'P', 'O', 'S', 'T', - 0x00, 0x03, 'u', 'r', 'l', - 0x00, 0x16, 'h', 't', 't', 'p', ':', '/', '/', 'w', 'w', 'w', - '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', - 'm', '/', - 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', - 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', - }; - // Setup the request HttpRequestInfo request; request.method = "POST"; @@ -276,16 +259,18 @@ TEST_F(SpdyNetworkTransactionTest, EmptyPost) { // Create an empty UploadData. request.upload_data = new UploadData(); + scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPost(NULL, 0)); + // Set the FIN bit since there will be no body. + req->set_flags(spdy::CONTROL_FLAG_FIN); MockWrite writes[] = { - MockWrite(true, reinterpret_cast<const char*>(kEmptyPostSyn), - arraysize(kEmptyPostSyn)), + CreateMockWrite(req.get()), }; + scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { - MockRead(true, reinterpret_cast<const char*>(kPostSynReply), - arraysize(kPostSynReply)), - MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), - arraysize(kPostBodyFrame)), + CreateMockRead(resp.get()), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -301,7 +286,7 @@ TEST_F(SpdyNetworkTransactionTest, EmptyPost) { // While we're doing a post, the server sends back a SYN_REPLY. TEST_F(SpdyNetworkTransactionTest, PostWithEarlySynReply) { - static const char upload[] = { "hello world" }; + static const char upload[] = { "hello!" }; // Setup the request HttpRequestInfo request; @@ -310,18 +295,17 @@ TEST_F(SpdyNetworkTransactionTest, PostWithEarlySynReply) { request.upload_data = new UploadData(); request.upload_data->AppendBytes(upload, sizeof(upload)); - MockWrite writes[] = { - MockWrite(true, reinterpret_cast<const char*>(kPostSyn), - arraysize(kPostSyn), 2), - MockWrite(true, reinterpret_cast<const char*>(kPostUploadFrame), - arraysize(kPostUploadFrame), 3), + scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPost(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); + MockWrite writes[] = { + CreateMockWrite(req.get(), 2), + CreateMockWrite(body.get(), 3), // POST upload frame }; + scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); MockRead reads[] = { - MockRead(true, reinterpret_cast<const char*>(kPostSynReply), - arraysize(kPostSynReply), 2), - MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), - arraysize(kPostBodyFrame), 3), + CreateMockRead(resp.get(), 2), + CreateMockRead(body.get(), 3), MockRead(false, 0, 0) // EOF }; @@ -335,9 +319,9 @@ TEST_F(SpdyNetworkTransactionTest, PostWithEarlySynReply) { // Test that the transaction doesn't crash when we don't have a reply. TEST_F(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { - MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), - arraysize(kPostBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -362,11 +346,11 @@ TEST_F(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { MockWrite writes[] = { CreateMockWrite(req.get()) }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(resp.get()), CreateMockRead(resp.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -460,11 +444,11 @@ TEST_F(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { MockWrite writes[] = { CreateMockWrite(req.get()) }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(resp.get(), 2), MockRead(true, ERR_IO_PENDING, 3), // Force a pause - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame), 4), + CreateMockRead(body.get(), 4), MockRead(true, 0, 0, 5), // EOF }; @@ -587,11 +571,11 @@ TEST_F(SpdyNetworkTransactionTest, SynReplyHeaders) { scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); MockWrite writes[] = { CreateMockWrite(req.get()) }; + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), test_cases[i].syn_reply_length), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -717,17 +701,16 @@ TEST_F(SpdyNetworkTransactionTest, SynReplyHeadersVary) { // Construct the reply. scoped_ptr<spdy::SpdyFrame> frame_reply( - ConstructSpdyPacket(test_cases[i].syn_reply, + ConstructSpdyPacket(*test_cases[i].syn_reply, test_cases[i].extra_headers[1], test_cases[i].num_headers[1], NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(frame_reply.get()), - MockRead(true, - reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -828,11 +811,11 @@ TEST_F(SpdyNetworkTransactionTest, InvalidSynReply) { MockWrite(true, 0, 0) // EOF }; + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), test_cases[i].syn_reply_length), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -873,11 +856,11 @@ TEST_F(SpdyNetworkTransactionTest, CorruptFrameSessionError) { MockWrite(true, 0, 0) // EOF }; + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), test_cases[i].syn_reply_length), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -1060,11 +1043,11 @@ TEST_F(SpdyNetworkTransactionTest, ServerPush) { // This array is for request before and after push is received. The push // body is only one 'packet', to allow the initial transaction to read all // the push data before . + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads1[] = { MockRead(true, reinterpret_cast<const char*>(syn_reply), // 0 arraysize(syn_reply), 2), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), // 1 - arraysize(kGetBodyFrame), 3), + CreateMockRead(body.get(), 1), // 1 MockRead(true, ERR_IO_PENDING, 4), // Force a pause // 2 MockRead(true, reinterpret_cast<const char*>(syn_push), // 3 arraysize(syn_push), 5), @@ -1079,8 +1062,7 @@ TEST_F(SpdyNetworkTransactionTest, ServerPush) { MockRead reads2[] = { MockRead(true, reinterpret_cast<const char*>(syn_reply), // 0 arraysize(syn_reply), 2), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), // 1 - arraysize(kGetBodyFrame), 3), + CreateMockRead(body.get(), 3), // 1 MockRead(true, reinterpret_cast<const char*>(syn_push), // 2 arraysize(syn_push), 4), MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame1), // 3 @@ -1216,10 +1198,10 @@ TEST_F(SpdyNetworkTransactionTest, WriteError) { }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(resp.get(), 2), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -1241,10 +1223,10 @@ TEST_F(SpdyNetworkTransactionTest, PartialWrite) { scoped_array<MockWrite> writes(ChopFrame(req.get(), kChunks)); scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(resp.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -1275,10 +1257,10 @@ TEST_F(SpdyNetworkTransactionTest, ConnectFailure) { }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(resp.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -1295,23 +1277,23 @@ TEST_F(SpdyNetworkTransactionTest, ConnectFailure) { // In this test, we enable compression, but get a uncompressed SynReply from // the server. Verify that teardown is all clean. TEST_F(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { + // For this test, we turn on the normal compression. + EnableCompression(true); + + scoped_ptr<spdy::SpdyFrame> compressed(ConstructSpdyGet(NULL, 0, true)); MockWrite writes[] = { - MockWrite(true, reinterpret_cast<const char*>(kGetSynCompressed), - arraysize(kGetSynCompressed)), + CreateMockWrite(compressed.get()), MockWrite(true, 0, 0) // EOF }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(resp.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; - // For this test, we turn on the normal compression. - EnableCompression(true); - scoped_refptr<DelayedSocketData> data( new DelayedSocketData(1, reads, arraysize(reads), writes, arraysize(writes))); @@ -1330,10 +1312,10 @@ TEST_F(SpdyNetworkTransactionTest, NetLog) { MockWrite writes[] = { CreateMockWrite(req.get()) }; scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(resp.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -1905,7 +1887,7 @@ TEST_F(SpdyNetworkTransactionTest, SettingsSaved) { // Construct the reply. scoped_ptr<spdy::SpdyFrame> reply( - ConstructSpdyPacket(&kSynReplyInfo, + ConstructSpdyPacket(kSynReplyInfo, kExtraHeaders, arraysize(kExtraHeaders) / 2, NULL, @@ -1937,10 +1919,10 @@ TEST_F(SpdyNetworkTransactionTest, SettingsSaved) { settings_frame.reset(ConstructSpdySettings(settings)); } + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(reply.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), CreateMockRead(settings_frame.get()), MockRead(true, 0, 0) // EOF }; @@ -2041,16 +2023,16 @@ TEST_F(SpdyNetworkTransactionTest, SettingsPlayback) { // Construct the reply. scoped_ptr<spdy::SpdyFrame> reply( - ConstructSpdyPacket(&kSynReplyInfo, + ConstructSpdyPacket(kSynReplyInfo, kExtraHeaders, arraysize(kExtraHeaders) / 2, NULL, 0)); + scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame()); MockRead reads[] = { CreateMockRead(reply.get()), - MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), - arraysize(kGetBodyFrame)), + CreateMockRead(body.get()), MockRead(true, 0, 0) // EOF }; @@ -2090,9 +2072,9 @@ TEST_F(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0)); MockWrite writes[] = { CreateMockWrite(req.get()) }; + scoped_ptr<spdy::SpdyFrame> go_away(ConstructSpdyGoAway()); MockRead reads[] = { - MockRead(true, reinterpret_cast<const char*>(kGoAway), - arraysize(kGoAway)), + CreateMockRead(go_away.get()), MockRead(true, 0, 0) // EOF }; diff --git a/net/spdy/spdy_test_util.cc b/net/spdy/spdy_test_util.cc index bed7031..eaf48c5 100644 --- a/net/spdy/spdy_test_util.cc +++ b/net/spdy/spdy_test_util.cc @@ -114,7 +114,7 @@ int AppendToBuffer(int val, // |tail| is any (relatively constant) header-value pairs to add. // |buffer| is the buffer we're filling in. // Returns a SpdyFrame. -spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo* header_info, +spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, const char* const extra_headers[], int extra_header_count, const char* const tail[], @@ -127,24 +127,24 @@ spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo* header_info, if (tail && tail_header_count) AppendHeadersToSpdyFrame(tail, tail_header_count, &headers); spdy::SpdyFrame* frame = NULL; - switch (header_info->kind) { + switch (header_info.kind) { case spdy::SYN_STREAM: - frame = framer.CreateSynStream(header_info->id, header_info->assoc_id, - header_info->priority, - header_info->control_flags, - header_info->compressed, &headers); + frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, + header_info.priority, + header_info.control_flags, + header_info.compressed, &headers); break; case spdy::SYN_REPLY: - frame = framer.CreateSynReply(header_info->id, header_info->control_flags, - header_info->compressed, &headers); + frame = framer.CreateSynReply(header_info.id, header_info.control_flags, + header_info.compressed, &headers); break; case spdy::RST_STREAM: - frame = framer.CreateRstStream(header_info->id, header_info->status); + frame = framer.CreateRstStream(header_info.id, header_info.status); break; default: - frame = framer.CreateDataFrame(header_info->id, header_info->data, - header_info->data_length, - header_info->data_flags); + frame = framer.CreateDataFrame(header_info.id, header_info.data, + header_info.data_length, + header_info.data_flags); break; } return frame; @@ -158,6 +158,13 @@ spdy::SpdyFrame* ConstructSpdySettings(spdy::SpdySettings settings) { return framer.CreateSettings(settings); } +// Construct a SPDY GOAWAY frame. +// Returns the constructed frame. The caller takes ownership of the frame. +spdy::SpdyFrame* ConstructSpdyGoAway() { + spdy::SpdyFramer framer; + return framer.CreateGoAway(0); +} + // Construct a single SPDY header entry, for validation. // |extra_headers| are the extra header-value pairs. // |buffer| is the buffer we're filling in. @@ -198,19 +205,19 @@ int ConstructSpdyHeader(const char* const extra_headers[], return n; } -// Constructs a standard SPDY GET packet. +// Constructs a standard SPDY GET SYN packet, optionally compressed. // |extra_headers| are the extra header-value pairs, which typically // will vary the most between calls. // Returns a SpdyFrame. spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], - int extra_header_count) { - SpdyHeaderInfo SynStartHeader = { + int extra_header_count, bool compressed) { + const SpdyHeaderInfo kSynStartHeader = { spdy::SYN_STREAM, // Kind = Syn 1, // Stream ID 0, // Associated stream ID SPDY_PRIORITY_LOWEST, // Priority spdy::CONTROL_FLAG_FIN, // Control Flags - false, // Compressed + compressed, // Compressed spdy::INVALID, // Status NULL, // Data 0, // Length @@ -225,20 +232,99 @@ spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], "HTTP/1.1" }; return ConstructSpdyPacket( - &SynStartHeader, + kSynStartHeader, extra_headers, extra_header_count, kStandardGetHeaders, arraysize(kStandardGetHeaders) / 2); } +// Constructs a standard SPDY GET SYN packet, not compressed. +// |extra_headers| are the extra header-value pairs, which typically +// will vary the most between calls. +// Returns a SpdyFrame. +spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], + int extra_header_count) { + return ConstructSpdyGet(extra_headers, extra_header_count, false); +} + // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. // |extra_headers| are the extra header-value pairs, which typically // will vary the most between calls. // Returns a SpdyFrame. spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], int extra_header_count) { - SpdyHeaderInfo SynStartHeader = { + const SpdyHeaderInfo kSynStartHeader = { + spdy::SYN_REPLY, // Kind = SynReply + 1, // Stream ID + 0, // Associated stream ID + SPDY_PRIORITY_LOWEST, // Priority + spdy::CONTROL_FLAG_NONE, // Control Flags + false, // Compressed + spdy::INVALID, // Status + NULL, // Data + 0, // Length + spdy::DATA_FLAG_NONE // Data Flags + }; + static const char* const kStandardGetHeaders[] = { + "hello", + "bye", + "status", + "200", + "url", + "/index.php", + "version", + "HTTP/1.1" + }; + return ConstructSpdyPacket( + kSynStartHeader, + extra_headers, + extra_header_count, + kStandardGetHeaders, + arraysize(kStandardGetHeaders) / 2); +} + +// Constructs a standard SPDY POST SYN packet. +// |extra_headers| are the extra header-value pairs, which typically +// will vary the most between calls. +// Returns a SpdyFrame. +spdy::SpdyFrame* ConstructSpdyPost(const char* const extra_headers[], + int extra_header_count) { + const SpdyHeaderInfo kSynStartHeader = { + spdy::SYN_STREAM, // Kind = Syn + 1, // Stream ID + 0, // Associated stream ID + SPDY_PRIORITY_LOWEST, // Priority + spdy::CONTROL_FLAG_NONE, // Control Flags + false, // Compressed + spdy::INVALID, // Status + NULL, // Data + 0, // Length + spdy::DATA_FLAG_NONE // Data Flags + }; + static const char* const kStandardGetHeaders[] = { + "method", + "POST", + "url", + "http://www.google.com/", + "version", + "HTTP/1.1" + }; + return ConstructSpdyPacket( + kSynStartHeader, + extra_headers, + extra_header_count, + kStandardGetHeaders, + arraysize(kStandardGetHeaders) / 2); +} + +// Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. +// |extra_headers| are the extra header-value pairs, which typically +// will vary the most between calls. +// Returns a SpdyFrame. +spdy::SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], + int extra_header_count) { + const SpdyHeaderInfo kSynStartHeader = { spdy::SYN_REPLY, // Kind = SynReply 1, // Stream ID 0, // Associated stream ID @@ -261,13 +347,19 @@ spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], "HTTP/1.1" }; return ConstructSpdyPacket( - &SynStartHeader, + kSynStartHeader, extra_headers, extra_header_count, kStandardGetHeaders, arraysize(kStandardGetHeaders) / 2); } +// Constructs a single SPDY data frame with the contents "hello!" +spdy::SpdyFrame* ConstructSpdyBodyFrame() { + spdy::SpdyFramer framer; + return framer.CreateDataFrame(1, "hello!", 6, spdy::DATA_FLAG_FIN); +} + // Construct an expected SPDY reply string. // |extra_headers| are the extra header-value pairs, which typically // will vary the most between calls. @@ -352,6 +444,12 @@ MockWrite CreateMockWrite(spdy::SpdyFrame* req) { true, req->data(), req->length() + spdy::SpdyFrame::size()); } +// Create a MockWrite from the given SpdyFrame and sequence number. +MockWrite CreateMockWrite(spdy::SpdyFrame* req, int seq) { + return MockWrite( + true, req->data(), req->length() + spdy::SpdyFrame::size(), seq); +} + // Create a MockRead from the given SpdyFrame. MockRead CreateMockRead(spdy::SpdyFrame* resp) { return MockRead( diff --git a/net/spdy/spdy_test_util.h b/net/spdy/spdy_test_util.h index 3aa45ab..0ac8308 100644 --- a/net/spdy/spdy_test_util.h +++ b/net/spdy/spdy_test_util.h @@ -11,78 +11,6 @@ namespace net { -const uint8 kGetBodyFrame[] = { - 0x00, 0x00, 0x00, 0x01, // header - 0x01, 0x00, 0x00, 0x06, // FIN, length - 'h', 'e', 'l', 'l', 'o', '!', // "hello" -}; - -const uint8 kGetSynCompressed[] = { - 0x80, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x47, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x00, 0x38, 0xea, 0xdf, 0xa2, 0x51, 0xb2, - 0x62, 0x60, 0x66, 0x60, 0xcb, 0x05, 0xe6, 0xc3, - 0xfc, 0x14, 0x06, 0x66, 0x77, 0xd7, 0x10, 0x06, - 0x66, 0x90, 0xa0, 0x58, 0x46, 0x49, 0x49, 0x81, - 0x95, 0xbe, 0x3e, 0x30, 0xe2, 0xf5, 0xd2, 0xf3, - 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x92, 0xf3, 0x73, - 0xf5, 0x19, 0xd8, 0xa1, 0x1a, 0x19, 0x38, 0x60, - 0xe6, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff -}; - -const uint8 kPostSyn[] = { - 0x80, 0x01, 0x00, 0x01, // header - 0x00, 0x00, 0x00, 0x4a, // flags, len - 0x00, 0x00, 0x00, 0x01, // stream id - 0x00, 0x00, 0x00, 0x00, // associated - 0xc0, 0x00, 0x00, 0x03, // 4 headers - 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', - 0x00, 0x04, 'P', 'O', 'S', 'T', - 0x00, 0x03, 'u', 'r', 'l', - 0x00, 0x16, 'h', 't', 't', 'p', ':', '/', '/', 'w', 'w', 'w', - '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', - 'm', '/', - 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', - 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', -}; - -const uint8 kPostUploadFrame[] = { - 0x00, 0x00, 0x00, 0x01, // header - 0x01, 0x00, 0x00, 0x0c, // FIN flag - 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\0' -}; - -// The response -const uint8 kPostSynReply[] = { - 0x80, 0x01, 0x00, 0x02, // header - 0x00, 0x00, 0x00, 0x45, - 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x04, // 4 headers - 0x00, 0x05, 'h', 'e', 'l', 'l', 'o', // "hello" - 0x00, 0x03, 'b', 'y', 'e', // "bye" - 0x00, 0x06, 's', 't', 'a', 't', 'u', 's', // "status" - 0x00, 0x03, '2', '0', '0', // "200" - 0x00, 0x03, 'u', 'r', 'l', // "url" - // "/index.php" - 0x00, 0x0a, '/', 'i', 'n', 'd', 'e', 'x', '.', 'p', 'h', 'p', - 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', // "version" - 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', // "HTTP/1.1" -}; - -const uint8 kPostBodyFrame[] = { - 0x00, 0x00, 0x00, 0x01, // header - 0x01, 0x00, 0x00, 0x06, // FIN, length - 'h', 'e', 'l', 'l', 'o', '!', // "hello" -}; - -const uint8 kGoAway[] = { - 0x80, 0x01, 0x00, 0x07, // header - 0x00, 0x00, 0x00, 0x04, // flags, len - 0x00, 0x00, 0x00, 0x00, // last-accepted-stream-id -}; - -// ---------------------------------------------------------------------------- - // NOTE: In GCC, on a Mac, this can't be in an anonymous namespace! // This struct holds information used to construct spdy control and data frames. struct SpdyHeaderInfo { @@ -156,7 +84,7 @@ int AppendToBuffer(int val, // |tail| is any (relatively constant) header-value pairs to add. // |buffer| is the buffer we're filling in. // Returns a SpdyFrame. -spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo* header_info, +spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, const char* const extra_headers[], int extra_header_count, const char* const tail[], @@ -177,6 +105,10 @@ int ConstructSpdyReplyString(const char* const extra_headers[], // Returns the constructed frame. The caller takes ownership of the frame. spdy::SpdyFrame* ConstructSpdySettings(spdy::SpdySettings settings); +// Construct a SPDY GOAWAY frame. +// Returns the constructed frame. The caller takes ownership of the frame. +spdy::SpdyFrame* ConstructSpdyGoAway(); + // Construct a single SPDY header entry, for validation. // |extra_headers| are the extra header-value pairs. // |buffer| is the buffer we're filling in. @@ -188,7 +120,15 @@ int ConstructSpdyHeader(const char* const extra_headers[], int buffer_length, int index); -// Constructs a standard SPDY GET packet. +// Constructs a standard SPDY GET SYN packet, optionally compressed. +// |extra_headers| are the extra header-value pairs, which typically +// will vary the most between calls. +// Returns a SpdyFrame. +spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], + int extra_header_count, + bool compressed); + +// Constructs a standard SPDY GET SYN packet, with no compression. // |extra_headers| are the extra header-value pairs, which typically // will vary the most between calls. // Returns a SpdyFrame. @@ -202,9 +142,29 @@ spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], int extra_header_count); +// Constructs a standard SPDY POST SYN packet. +// |extra_headers| are the extra header-value pairs, which typically +// will vary the most between calls. +// Returns a SpdyFrame. +spdy::SpdyFrame* ConstructSpdyPost(const char* const extra_headers[], + int extra_header_count); + +// Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. +// |extra_headers| are the extra header-value pairs, which typically +// will vary the most between calls. +// Returns a SpdyFrame. +spdy::SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], + int extra_header_count); + +// Constructs a single SPDY data frame with the contents "hello!" +spdy::SpdyFrame* ConstructSpdyBodyFrame(); + // Create an async MockWrite from the given SpdyFrame. MockWrite CreateMockWrite(spdy::SpdyFrame* req); +// Create an async MockWrite from the given SpdyFrame and sequence number. +MockWrite CreateMockWrite(spdy::SpdyFrame* req, int seq); + // Create a MockRead from the given SpdyFrame. MockRead CreateMockRead(spdy::SpdyFrame* resp); |