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

Unified Diff: net/spdy/spdy_test_util_spdy3.cc

Issue 12743006: [SPDY] Refactor tests in preparation for a fix for a session flow control bug (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« net/spdy/spdy_test_util_spdy2.h ('K') | « net/spdy/spdy_test_util_spdy3.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_test_util_spdy3.cc
diff --git a/net/spdy/spdy_test_util_spdy3.cc b/net/spdy/spdy_test_util_spdy3.cc
index 660c19dc0610d400793d73cd3ad7ecb3729a31f5..506c81b10f5590ec66e8ae01bb395f5a7001004b 100644
--- a/net/spdy/spdy_test_util_spdy3.cc
+++ b/net/spdy/spdy_test_util_spdy3.cc
@@ -134,9 +134,9 @@ MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks) {
// where the even entries are the header names, and the odd entries are the
// header values.
// |headers| gets filled in from |extra_headers|.
-void AppendHeadersToSpdyFrame(const char* const extra_headers[],
- int extra_header_count,
- SpdyHeaderBlock* headers) {
+void AppendToHeaderBlock(const char* const extra_headers[],
+ int extra_header_count,
+ SpdyHeaderBlock* headers) {
std::string this_header;
std::string this_value;
@@ -176,6 +176,21 @@ void AppendHeadersToSpdyFrame(const char* const extra_headers[],
}
}
+scoped_ptr<SpdyHeaderBlock> ConstructHeaderBlock(base::StringPiece url) {
+ std::string scheme, host, path;
+ ParseUrl(url.data(), &scheme, &host, &path);
+ const char* const headers[] = {
+ ":method", "GET",
+ ":path", path.c_str(),
+ ":host", host.c_str(),
+ ":scheme", scheme.c_str(),
+ ":version", "HTTP/1.1"
+ };
+ scoped_ptr<SpdyHeaderBlock> header_block(new SpdyHeaderBlock());
+ AppendToHeaderBlock(headers, arraysize(headers) / 2, header_block.get());
+ return header_block.Pass();
+}
+
// Writes |val| to a location of size |len|, in big-endian format.
// in the buffer pointed to by |buffer_handle|.
// Updates the |*buffer_handle| pointer by |len|
@@ -201,26 +216,9 @@ int AppendToBuffer(int val,
return len;
}
-// Construct a SPDY packet.
-// |head| is the start of the packet, up to but not including
-// the header value pairs.
-// |extra_headers| are the extra header-value pairs, which typically
-// will vary the most between calls.
-// |tail| is any (relatively constant) header-value pairs to add.
-// |buffer| is the buffer we're filling in.
-// Returns a SpdyFrame.
SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
- const char* const extra_headers[],
- int extra_header_count,
- const char* const tail[],
- int tail_header_count) {
- BufferedSpdyFramer framer(3, header_info.compressed);
- SpdyHeaderBlock headers;
- // Copy in the extra headers to our map.
- AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers);
- // Copy in the tail headers to our map.
- if (tail && tail_header_count)
- AppendHeadersToSpdyFrame(tail, tail_header_count, &headers);
+ scoped_ptr<SpdyHeaderBlock> headers) {
+ BufferedSpdyFramer framer(kSpdyVersion3, header_info.compressed);
SpdyFrame* frame = NULL;
switch (header_info.kind) {
case SYN_STREAM:
@@ -228,18 +226,18 @@ SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
header_info.priority,
header_info.credential_slot,
header_info.control_flags,
- header_info.compressed, &headers);
+ header_info.compressed, headers.get());
break;
case SYN_REPLY:
frame = framer.CreateSynReply(header_info.id, header_info.control_flags,
- header_info.compressed, &headers);
+ header_info.compressed, headers.get());
break;
case RST_STREAM:
frame = framer.CreateRstStream(header_info.id, header_info.status);
break;
case HEADERS:
frame = framer.CreateHeaders(header_info.id, header_info.control_flags,
- header_info.compressed, &headers);
+ header_info.compressed, headers.get());
break;
default:
frame = framer.CreateDataFrame(header_info.id, header_info.data,
@@ -250,6 +248,18 @@ SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
return frame;
}
+SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
+ const char* const extra_headers[],
+ int extra_header_count,
+ const char* const tail[],
+ int tail_header_count) {
+ scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
+ AppendToHeaderBlock(extra_headers, extra_header_count, headers.get());
+ if (tail && tail_header_count)
+ AppendToHeaderBlock(tail, tail_header_count, headers.get());
+ return ConstructSpdyPacket(header_info, headers.Pass());
+}
+
// Construct an expected SPDY SETTINGS frame.
// |settings| are the settings to set.
// Returns the constructed frame. The caller takes ownership of the frame.
@@ -412,22 +422,7 @@ SpdyFrame* ConstructSpdyGet(const char* const url,
0, // Length
DATA_FLAG_NONE // Data Flags
};
-
- std::string scheme, host, path;
- ParseUrl(url, &scheme, &host, &path);
- const char* const headers[] = {
- ":method", "GET",
- ":path", path.c_str(),
- ":host", host.c_str(),
- ":scheme", scheme.c_str(),
- ":version", "HTTP/1.1"
- };
- return ConstructSpdyPacket(
- kSynStartHeader,
- NULL,
- 0,
- headers,
- arraysize(headers) / 2);
+ return ConstructSpdyPacket(kSynStartHeader, ConstructHeaderBlock(url));
}
// Constructs a standard SPDY GET SYN packet, optionally compressed.
@@ -774,7 +769,7 @@ int ConstructSpdyReplyString(const char* const extra_headers[],
if (!buffer || !buffer_length)
return 0;
// Copy in the extra headers.
- AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers);
+ AppendToHeaderBlock(extra_headers, extra_header_count, &headers);
// The iterator gets us the list of header/value pairs in sorted order.
SpdyHeaderBlock::iterator next = headers.begin();
SpdyHeaderBlock::iterator last = headers.end();
« net/spdy/spdy_test_util_spdy2.h ('K') | « net/spdy/spdy_test_util_spdy3.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698