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

Unified Diff: net/spdy/spdy_test_util_spdy2.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
Index: net/spdy/spdy_test_util_spdy2.cc
diff --git a/net/spdy/spdy_test_util_spdy2.cc b/net/spdy/spdy_test_util_spdy2.cc
index 8648ecac1840bfcd1936bc97fea5070ef41cbe05..f24b634dd238b72854c3ecbc46fbf52ab4ef3078 100644
--- a/net/spdy/spdy_test_util_spdy2.cc
+++ b/net/spdy/spdy_test_util_spdy2.cc
@@ -90,9 +90,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;
@@ -132,6 +132,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",
+ "url", 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|
@@ -157,44 +172,27 @@ 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(2, 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(kSpdyVersion2, header_info.compressed);
SpdyFrame* frame = NULL;
switch (header_info.kind) {
case SYN_STREAM:
frame = framer.CreateSynStream(header_info.id, header_info.assoc_id,
header_info.priority, 0,
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,
@@ -205,6 +203,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.
@@ -365,22 +375,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",
- "url", 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.
@@ -733,7 +728,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();

Powered by Google App Engine
This is Rietveld 408576698