Commit 5b3e6d6c authored by rch@chromium.org's avatar rch@chromium.org

Clean up a raft of SPDY files to bring in sync with server

Review URL: http://codereview.chromium.org/10207001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133791 0039d316-1c4b-4281-b951-d872f2087c98
parent 812b95b4
...@@ -25,7 +25,7 @@ TEST(SpdyFrameReaderTest, ReadUInt16) { ...@@ -25,7 +25,7 @@ TEST(SpdyFrameReaderTest, ReadUInt16) {
uint16 uint16_val; uint16 uint16_val;
EXPECT_TRUE(frame_reader.ReadUInt16(&uint16_val)); EXPECT_TRUE(frame_reader.ReadUInt16(&uint16_val));
EXPECT_FALSE(frame_reader.IsDoneReading()); EXPECT_FALSE(frame_reader.IsDoneReading());
EXPECT_EQ(1u, uint16_val); EXPECT_EQ(1, uint16_val);
EXPECT_TRUE(frame_reader.ReadUInt16(&uint16_val)); EXPECT_TRUE(frame_reader.ReadUInt16(&uint16_val));
EXPECT_TRUE(frame_reader.IsDoneReading()); EXPECT_TRUE(frame_reader.IsDoneReading());
...@@ -49,7 +49,7 @@ TEST(SpdyFrameReaderTest, ReadUInt32) { ...@@ -49,7 +49,7 @@ TEST(SpdyFrameReaderTest, ReadUInt32) {
EXPECT_TRUE(frame_reader.ReadUInt32(&uint32_val)); EXPECT_TRUE(frame_reader.ReadUInt32(&uint32_val));
EXPECT_TRUE(frame_reader.IsDoneReading()); EXPECT_TRUE(frame_reader.IsDoneReading());
EXPECT_EQ(static_cast<uint32>(1<<31), uint32_val); EXPECT_EQ(1u<<31, uint32_val);
} }
TEST(SpdyFrameReaderTest, ReadStringPiece16) { TEST(SpdyFrameReaderTest, ReadStringPiece16) {
......
...@@ -64,7 +64,6 @@ const size_t SpdyFramer::kControlFrameBufferSize = ...@@ -64,7 +64,6 @@ const size_t SpdyFramer::kControlFrameBufferSize =
sizeof(SpdySynStreamControlFrameBlock); sizeof(SpdySynStreamControlFrameBlock);
const size_t SpdyFramer::kMaxControlFrameSize = 16 * 1024; const size_t SpdyFramer::kMaxControlFrameSize = 16 * 1024;
#ifdef DEBUG_SPDY_STATE_CHANGES #ifdef DEBUG_SPDY_STATE_CHANGES
#define CHANGE_STATE(newstate) \ #define CHANGE_STATE(newstate) \
do { \ do { \
...@@ -96,7 +95,7 @@ SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat(int version, ...@@ -96,7 +95,7 @@ SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat(int version,
SettingsFlagsAndId::SettingsFlagsAndId(uint8 flags, uint32 id) SettingsFlagsAndId::SettingsFlagsAndId(uint8 flags, uint32 id)
: flags_(flags), id_(id & 0x00ffffff) { : flags_(flags), id_(id & 0x00ffffff) {
DCHECK_GT(static_cast<uint32>(1 << 24), id); DCHECK_GT(1u << 24, id) << "SPDY setting ID too large.";
} }
uint32 SettingsFlagsAndId::GetWireFormat(int version) const { uint32 SettingsFlagsAndId::GetWireFormat(int version) const {
...@@ -360,7 +359,7 @@ size_t SpdyFramer::ProcessInput(const char* data, size_t len) { ...@@ -360,7 +359,7 @@ size_t SpdyFramer::ProcessInput(const char* data, size_t len) {
break; break;
} }
default: default:
LOG(ERROR) << "Invalid value for " << display_protocol_ LOG(DFATAL) << "Invalid value for " << display_protocol_
<< " framer state: " << state_; << " framer state: " << state_;
// This ensures that we don't infinite-loop if state_ gets an // This ensures that we don't infinite-loop if state_ gets an
// invalid value somehow, such as due to a SpdyFramer getting deleted // invalid value somehow, such as due to a SpdyFramer getting deleted
...@@ -529,7 +528,7 @@ void SpdyFramer::ProcessControlFrameHeader() { ...@@ -529,7 +528,7 @@ void SpdyFramer::ProcessControlFrameHeader() {
LOG(WARNING) << "Valid " << display_protocol_ LOG(WARNING) << "Valid " << display_protocol_
<< " control frame with unhandled type: " << " control frame with unhandled type: "
<< current_control_frame.type(); << current_control_frame.type();
DCHECK(false); DLOG(FATAL);
set_error(SPDY_INVALID_CONTROL_FRAME); set_error(SPDY_INVALID_CONTROL_FRAME);
break; break;
} }
...@@ -586,6 +585,7 @@ void SpdyFramer::ProcessControlFrameHeader() { ...@@ -586,6 +585,7 @@ void SpdyFramer::ProcessControlFrameHeader() {
if ((frame_size_without_variable_data == -1) && if ((frame_size_without_variable_data == -1) &&
(total_frame_size > kControlFrameBufferSize)) { (total_frame_size > kControlFrameBufferSize)) {
// We should already be in an error state. Double-check.
DCHECK_EQ(SPDY_ERROR, state_); DCHECK_EQ(SPDY_ERROR, state_);
if (state_ != SPDY_ERROR) { if (state_ != SPDY_ERROR) {
LOG(DFATAL) << display_protocol_ LOG(DFATAL) << display_protocol_
...@@ -674,6 +674,7 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data, ...@@ -674,6 +674,7 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
remaining_control_header_); remaining_control_header_);
remaining_control_header_ -= bytes_read; remaining_control_header_ -= bytes_read;
} }
if (remaining_control_header_ == 0) { if (remaining_control_header_ == 0) {
SpdyControlFrame control_frame(current_frame_buffer_.get(), false); SpdyControlFrame control_frame(current_frame_buffer_.get(), false);
DCHECK(control_frame.type() == SYN_STREAM || DCHECK(control_frame.type() == SYN_STREAM ||
...@@ -705,7 +706,6 @@ size_t SpdyFramer::ProcessControlFrameHeaderBlock(const char* data, ...@@ -705,7 +706,6 @@ size_t SpdyFramer::ProcessControlFrameHeaderBlock(const char* data,
control_frame.type() == SYN_REPLY || control_frame.type() == SYN_REPLY ||
control_frame.type() == HEADERS); control_frame.type() == HEADERS);
size_t process_bytes = std::min(data_len, remaining_control_payload_); size_t process_bytes = std::min(data_len, remaining_control_payload_);
if (process_bytes > 0) { if (process_bytes > 0) {
if (enable_compression_) { if (enable_compression_) {
processed_successfully = IncrementallyDecompressControlFrameHeaderData( processed_successfully = IncrementallyDecompressControlFrameHeaderData(
...@@ -714,6 +714,7 @@ size_t SpdyFramer::ProcessControlFrameHeaderBlock(const char* data, ...@@ -714,6 +714,7 @@ size_t SpdyFramer::ProcessControlFrameHeaderBlock(const char* data,
processed_successfully = IncrementallyDeliverControlFrameHeaderData( processed_successfully = IncrementallyDeliverControlFrameHeaderData(
&control_frame, data, process_bytes); &control_frame, data, process_bytes);
} }
remaining_control_payload_ -= process_bytes; remaining_control_payload_ -= process_bytes;
remaining_data_ -= process_bytes; remaining_data_ -= process_bytes;
} }
...@@ -747,7 +748,7 @@ size_t SpdyFramer::ProcessSettingsFramePayload(const char* data, ...@@ -747,7 +748,7 @@ size_t SpdyFramer::ProcessSettingsFramePayload(const char* data,
size_t data_len) { size_t data_len) {
DCHECK_EQ(SPDY_SETTINGS_FRAME_PAYLOAD, state_); DCHECK_EQ(SPDY_SETTINGS_FRAME_PAYLOAD, state_);
SpdyControlFrame control_frame(current_frame_buffer_.get(), false); SpdyControlFrame control_frame(current_frame_buffer_.get(), false);
DCHECK_EQ(control_frame.type(), SETTINGS); DCHECK_EQ(SETTINGS, control_frame.type());
size_t unprocessed_bytes = std::min(data_len, remaining_control_payload_); size_t unprocessed_bytes = std::min(data_len, remaining_control_payload_);
size_t processed_bytes = 0; size_t processed_bytes = 0;
...@@ -944,8 +945,7 @@ bool SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data, ...@@ -944,8 +945,7 @@ bool SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
<< num_headers << ")."; << num_headers << ").";
return false; return false;
} }
std::string name; std::string name = temp.as_string();
temp.CopyToString(&name);
// Read header value. // Read header value.
if ((spdy_version_ < 3) ? !reader.ReadStringPiece16(&temp) if ((spdy_version_ < 3) ? !reader.ReadStringPiece16(&temp)
...@@ -954,8 +954,7 @@ bool SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data, ...@@ -954,8 +954,7 @@ bool SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
<< num_headers << ")."; << num_headers << ").";
return false; return false;
} }
std::string value; std::string value = temp.as_string();
temp.CopyToString(&value);
// Ensure no duplicates. // Ensure no duplicates.
if (block->find(name) != block->end()) { if (block->find(name) != block->end()) {
...@@ -970,6 +969,7 @@ bool SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data, ...@@ -970,6 +969,7 @@ bool SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
return true; return true;
} }
// TODO(hkhalil): Remove, or move to test utils kit.
/* static */ /* static */
bool SpdyFramer::ParseSettings(const SpdySettingsControlFrame* frame, bool SpdyFramer::ParseSettings(const SpdySettingsControlFrame* frame,
SettingsMap* settings) { SettingsMap* settings) {
...@@ -1011,15 +1011,13 @@ bool SpdyFramer::ParseCredentialData(const char* data, size_t len, ...@@ -1011,15 +1011,13 @@ bool SpdyFramer::ParseCredentialData(const char* data, size_t len,
if (!parser.ReadStringPiece32(&temp)) { if (!parser.ReadStringPiece32(&temp)) {
return false; return false;
} }
temp.CopyToString(&credential->proof); credential->proof = temp.as_string();
while (!parser.IsDoneReading()) { while (!parser.IsDoneReading()) {
if (!parser.ReadStringPiece32(&temp)) { if (!parser.ReadStringPiece32(&temp)) {
return false; return false;
} }
std::string cert; credential->certs.push_back(temp.as_string());
temp.CopyToString(&cert);
credential->certs.push_back(cert);
} }
return true; return true;
} }
...@@ -1044,7 +1042,7 @@ SpdySynStreamControlFrame* SpdyFramer::CreateSynStream( ...@@ -1044,7 +1042,7 @@ SpdySynStreamControlFrame* SpdyFramer::CreateSynStream(
frame.WriteUInt32(associated_stream_id); frame.WriteUInt32(associated_stream_id);
// Cap as appropriate. // Cap as appropriate.
if (priority > GetLowestPriority()) { if (priority > GetLowestPriority()) {
DLOG(ERROR) << "Priority out-of-bounds."; DLOG(DFATAL) << "Priority out-of-bounds.";
priority = GetLowestPriority(); priority = GetLowestPriority();
} }
// Priority is 2 bits for <spdy3, 3 bits otherwise. // Priority is 2 bits for <spdy3, 3 bits otherwise.
...@@ -1242,7 +1240,6 @@ SpdyDataFrame* SpdyFramer::CreateDataFrame(SpdyStreamId stream_id, ...@@ -1242,7 +1240,6 @@ SpdyDataFrame* SpdyFramer::CreateDataFrame(SpdyStreamId stream_id,
const char* data, const char* data,
uint32 len, SpdyDataFlags flags) { uint32 len, SpdyDataFlags flags) {
DCHECK_EQ(0u, stream_id & ~kStreamIdMask); DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
size_t frame_size = SpdyDataFrame::size() + len; size_t frame_size = SpdyDataFrame::size() + len;
SpdyFrameBuilder frame(stream_id, flags, frame_size); SpdyFrameBuilder frame(stream_id, flags, frame_size);
frame.WriteBytes(data, len); frame.WriteBytes(data, len);
...@@ -1387,13 +1384,12 @@ SpdyControlFrame* SpdyFramer::CompressControlFrame( ...@@ -1387,13 +1384,12 @@ SpdyControlFrame* SpdyFramer::CompressControlFrame(
// Create an output frame. // Create an output frame.
int compressed_max_size = deflateBound(compressor, payload_length); int compressed_max_size = deflateBound(compressor, payload_length);
int new_frame_size = header_length + compressed_max_size; size_t new_frame_size = header_length + compressed_max_size;
if ((frame.type() == SYN_REPLY || frame.type() == HEADERS) && if ((frame.type() == SYN_REPLY || frame.type() == HEADERS) &&
spdy_version_ < 3) { spdy_version_ < 3) {
new_frame_size += 2; new_frame_size += 2;
} }
DCHECK_GE(new_frame_size, DCHECK_GE(new_frame_size, frame.length() + SpdyFrame::kHeaderSize);
static_cast<int>(frame.length() + SpdyFrame::kHeaderSize));
scoped_ptr<SpdyControlFrame> new_frame(new SpdyControlFrame(new_frame_size)); scoped_ptr<SpdyControlFrame> new_frame(new SpdyControlFrame(new_frame_size));
memcpy(new_frame->data(), frame.data(), memcpy(new_frame->data(), frame.data(),
frame.length() + SpdyFrame::kHeaderSize); frame.length() + SpdyFrame::kHeaderSize);
...@@ -1584,7 +1580,7 @@ size_t SpdyFramer::GetMinimumControlFrameSize(int version, ...@@ -1584,7 +1580,7 @@ size_t SpdyFramer::GetMinimumControlFrameSize(int version,
break; break;
} }
LOG(ERROR) << "Unknown control frame type " << type; LOG(ERROR) << "Unknown control frame type " << type;
return 0x7FFFFFFF; // Max signed 32bit int return std::numeric_limits<size_t>::max();
} }
/* static */ /* static */
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <limits>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "net/spdy/spdy_framer.h" #include "net/spdy/spdy_framer.h"
...@@ -12,6 +13,10 @@ ...@@ -12,6 +13,10 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
using std::string;
using std::max;
using std::min;
using std::numeric_limits;
using testing::_; using testing::_;
namespace net { namespace net {
...@@ -39,8 +44,9 @@ class MockVisitor : public SpdyFramerVisitorInterface { ...@@ -39,8 +44,9 @@ class MockVisitor : public SpdyFramerVisitorInterface {
class SpdyFramerTestUtil { class SpdyFramerTestUtil {
public: public:
// Decompress a single frame using the decompression context held by // Decompress a single frame using the decompression context held by
// the SpdyFramer. The implemention will CHECK fail if the input is anything // the SpdyFramer. The implemention is meant for use only in tests
// other than a single, well-formed compressed frame. // and will CHECK fail if the input is anything other than a single,
// well-formed compressed frame.
// //
// Returns a new decompressed SpdyFrame. // Returns a new decompressed SpdyFrame.
template<class SpdyFrameType> static SpdyFrame* DecompressFrame( template<class SpdyFrameType> static SpdyFrame* DecompressFrame(
...@@ -53,7 +59,7 @@ class SpdyFramerTestUtil { ...@@ -53,7 +59,7 @@ class SpdyFramerTestUtil {
framer->set_visitor(NULL); framer->set_visitor(NULL);
char* buffer = visitor.ReleaseBuffer(); char* buffer = visitor.ReleaseBuffer();
CHECK(buffer); CHECK(buffer != NULL);
SpdyFrame* decompressed_frame = new SpdyFrame(buffer, true); SpdyFrame* decompressed_frame = new SpdyFrame(buffer, true);
decompressed_frame->set_length(visitor.size() - SpdyFrame::kHeaderSize); decompressed_frame->set_length(visitor.size() - SpdyFrame::kHeaderSize);
return decompressed_frame; return decompressed_frame;
...@@ -67,8 +73,8 @@ class SpdyFramerTestUtil { ...@@ -67,8 +73,8 @@ class SpdyFramerTestUtil {
virtual void OnControl(const SpdyControlFrame* frame) { virtual void OnControl(const SpdyControlFrame* frame) {
CHECK(frame->has_header_block()); CHECK(frame->has_header_block());
CHECK(!buffer_.get()); CHECK(buffer_.get() == NULL);
CHECK_EQ(size_, 0u); CHECK_EQ(0u, size_);
CHECK(!finished_); CHECK(!finished_);
int32 control_frame_header_size = 0; int32 control_frame_header_size = 0;
...@@ -84,7 +90,6 @@ class SpdyFramerTestUtil { ...@@ -84,7 +90,6 @@ class SpdyFramerTestUtil {
break; break;
default: default:
LOG(FATAL); LOG(FATAL);
return;
} }
// Allocate space for the frame, and the copy header over. // Allocate space for the frame, and the copy header over.
...@@ -149,7 +154,7 @@ class SpdyFramerTestUtil { ...@@ -149,7 +154,7 @@ class SpdyFramerTestUtil {
DISALLOW_COPY_AND_ASSIGN(SpdyFramerTestUtil); DISALLOW_COPY_AND_ASSIGN(SpdyFramerTestUtil);
}; };
std::string HexDumpWithMarks(const unsigned char* data, int length, string HexDumpWithMarks(const unsigned char* data, int length,
const bool* marks, int mark_length) { const bool* marks, int mark_length) {
static const char kHexChars[] = "0123456789abcdef"; static const char kHexChars[] = "0123456789abcdef";
static const int kColumns = 4; static const int kColumns = 4;
...@@ -157,11 +162,11 @@ std::string HexDumpWithMarks(const unsigned char* data, int length, ...@@ -157,11 +162,11 @@ std::string HexDumpWithMarks(const unsigned char* data, int length,
const int kSizeLimit = 1024; const int kSizeLimit = 1024;
if (length > kSizeLimit || mark_length > kSizeLimit) { if (length > kSizeLimit || mark_length > kSizeLimit) {
LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes."; LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes.";
length = std::min(length, kSizeLimit); length = min(length, kSizeLimit);
mark_length = std::min(mark_length, kSizeLimit); mark_length = min(mark_length, kSizeLimit);
} }
std::string hex; string hex;
for (const unsigned char* row = data; length > 0; for (const unsigned char* row = data; length > 0;
row += kColumns, length -= kColumns) { row += kColumns, length -= kColumns) {
for (const unsigned char *p = row; p < row + 4; ++p) { for (const unsigned char *p = row; p < row + 4; ++p) {
...@@ -187,13 +192,13 @@ std::string HexDumpWithMarks(const unsigned char* data, int length, ...@@ -187,13 +192,13 @@ std::string HexDumpWithMarks(const unsigned char* data, int length,
} }
void CompareCharArraysWithHexError( void CompareCharArraysWithHexError(
const std::string& description, const string& description,
const unsigned char* actual, const unsigned char* actual,
const int actual_len, const int actual_len,
const unsigned char* expected, const unsigned char* expected,
const int expected_len) { const int expected_len) {
const int min_len = std::min(actual_len, expected_len); const int min_len = min(actual_len, expected_len);
const int max_len = std::max(actual_len, expected_len); const int max_len = max(actual_len, expected_len);
scoped_array<bool> marks(new bool[max_len]); scoped_array<bool> marks(new bool[max_len]);
bool identical = (actual_len == expected_len); bool identical = (actual_len == expected_len);
for (int i = 0; i < min_len; ++i) { for (int i = 0; i < min_len; ++i) {
...@@ -219,10 +224,10 @@ void CompareCharArraysWithHexError( ...@@ -219,10 +224,10 @@ void CompareCharArraysWithHexError(
class TestSpdyVisitor : public SpdyFramerVisitorInterface { class TestSpdyVisitor : public SpdyFramerVisitorInterface {
public: public:
static const size_t kDefaultHeaderBufferSize = 64 * 1024; static const size_t kDefaultHeaderBufferSize = 16 * 1024;
static const size_t kDefaultCredentialBufferSize = 16 * 1024; static const size_t kDefaultCredentialBufferSize = 16 * 1024;
TestSpdyVisitor(int version) explicit TestSpdyVisitor(int version)
: framer_(version), : framer_(version),
use_compression_(false), use_compression_(false),
error_count_(0), error_count_(0),
...@@ -375,7 +380,7 @@ class TestSpdyVisitor : public SpdyFramerVisitorInterface { ...@@ -375,7 +380,7 @@ class TestSpdyVisitor : public SpdyFramerVisitorInterface {
// the socket. // the socket.
const size_t kMaxReadSize = 32; const size_t kMaxReadSize = 32;
size_t bytes_read = size_t bytes_read =
(rand() % std::min(input_remaining, kMaxReadSize)) + 1; (rand() % min(input_remaining, kMaxReadSize)) + 1;
size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read);
input_remaining -= bytes_processed; input_remaining -= bytes_processed;
input_ptr += bytes_processed; input_ptr += bytes_processed;
...@@ -444,7 +449,7 @@ class TestSpdyVisitor : public SpdyFramerVisitorInterface { ...@@ -444,7 +449,7 @@ class TestSpdyVisitor : public SpdyFramerVisitorInterface {
SpdyCredential credential_; SpdyCredential credential_;
}; };
} // namespace test } // namespace net
using test::CompareCharArraysWithHexError; using test::CompareCharArraysWithHexError;
using test::SpdyFramerTestUtil; using test::SpdyFramerTestUtil;
...@@ -454,28 +459,26 @@ TEST(SpdyFrameBuilderTest, WriteLimits) { ...@@ -454,28 +459,26 @@ TEST(SpdyFrameBuilderTest, WriteLimits) {
SpdyFrameBuilder builder(1, DATA_FLAG_NONE, kLengthMask + 8); SpdyFrameBuilder builder(1, DATA_FLAG_NONE, kLengthMask + 8);
// Data frame header is 8 bytes // Data frame header is 8 bytes
EXPECT_EQ(8u, builder.length()); EXPECT_EQ(8u, builder.length());
const std::string kLargeData(kLengthMask, 'A'); const string kLargeData(kLengthMask, 'A');
builder.WriteUInt32(kLengthMask); builder.WriteUInt32(kLengthMask);
EXPECT_EQ(12u, builder.length()); EXPECT_EQ(12u, builder.length());
EXPECT_TRUE(builder.WriteBytes(kLargeData.data(), kLengthMask - 4)); EXPECT_TRUE(builder.WriteBytes(kLargeData.data(), kLengthMask - 4));
EXPECT_EQ(kLengthMask + 8, builder.length()); EXPECT_EQ(kLengthMask + 8u, builder.length());
} }
enum SpdyFramerTestTypes { enum SpdyFramerTestTypes {
SPDY2, SPDY2 = 2,
SPDY3, SPDY3 = 3,
}; };
class SpdyFramerTest class SpdyFramerTest
: public ::testing::TestWithParam<SpdyFramerTestTypes> { : public ::testing::TestWithParam<SpdyFramerTestTypes> {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
spdy_version_ = (GetParam() == SPDY2) ? 2 : 3; spdy_version_ = GetParam();
} }
virtual void TearDown() {} void CompareFrame(const string& description,
void CompareFrame(const std::string& description,
const SpdyFrame& actual_frame, const SpdyFrame& actual_frame,
const unsigned char* expected, const unsigned char* expected,
const int expected_len) { const int expected_len) {
...@@ -491,7 +494,7 @@ class SpdyFramerTest ...@@ -491,7 +494,7 @@ class SpdyFramerTest
const SpdyHeaderBlock* actual) { const SpdyHeaderBlock* actual) {
if (expected->size() != actual->size()) { if (expected->size() != actual->size()) {
LOG(ERROR) << "Expected " << expected->size() << " headers; actually got " LOG(ERROR) << "Expected " << expected->size() << " headers; actually got "
<< actual->size() << "." << std::endl; << actual->size() << ".";
return false; return false;
} }
for (SpdyHeaderBlock::const_iterator it = expected->begin(); for (SpdyHeaderBlock::const_iterator it = expected->begin();
...@@ -499,15 +502,14 @@ class SpdyFramerTest ...@@ -499,15 +502,14 @@ class SpdyFramerTest
++it) { ++it) {
SpdyHeaderBlock::const_iterator it2 = actual->find(it->first); SpdyHeaderBlock::const_iterator it2 = actual->find(it->first);
if (it2 == actual->end()) { if (it2 == actual->end()) {
LOG(ERROR) << "Expected header name '" << it->first << "'." LOG(ERROR) << "Expected header name '" << it->first << "'.";
<< std::endl;
return false; return false;
} }
if (it->second.compare(it2->second) != 0) { if (it->second.compare(it2->second) != 0) {
LOG(ERROR) << "Expected header named '" << it->first LOG(ERROR) << "Expected header named '" << it->first
<< "' to have a value of '" << it->second << "' to have a value of '" << it->second
<< "'. The actual value received was '" << it2->second << "'. The actual value received was '" << it2->second
<< "'." << std::endl; << "'.";
return false; return false;
} }
} }
...@@ -525,14 +527,12 @@ class SpdyFramerTest ...@@ -525,14 +527,12 @@ class SpdyFramerTest
settings->insert(std::make_pair(id, SettingsFlagsAndValue(flags, value))); settings->insert(std::make_pair(id, SettingsFlagsAndValue(flags, value)));
} }
bool IsSpdy2() { return spdy_version_ < 3; } bool IsSpdy2() { return spdy_version_ == SPDY2; }
// Version of SPDY protocol to be used. // Version of SPDY protocol to be used.
int spdy_version_; unsigned char spdy_version_;
}; };
//-----------------------------------------------------------------------------
// All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
INSTANTIATE_TEST_CASE_P(SpdyFramerTests, INSTANTIATE_TEST_CASE_P(SpdyFramerTests,
SpdyFramerTest, SpdyFramerTest,
...@@ -569,8 +569,7 @@ TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { ...@@ -569,8 +569,7 @@ TEST_P(SpdyFramerTest, HeaderBlockInBuffer) {
false, // compress false, // compress
&headers)); &headers));
EXPECT_TRUE(frame.get() != NULL); EXPECT_TRUE(frame.get() != NULL);
std::string serialized_headers(frame->header_block(), string serialized_headers(frame->header_block(), frame->header_block_len());
frame->header_block_len());
SpdyHeaderBlock new_headers; SpdyHeaderBlock new_headers;
EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(),
serialized_headers.size(), serialized_headers.size(),
...@@ -599,8 +598,7 @@ TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { ...@@ -599,8 +598,7 @@ TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) {
&headers)); &headers));
EXPECT_TRUE(frame.get() != NULL); EXPECT_TRUE(frame.get() != NULL);
std::string serialized_headers(frame->header_block(), string serialized_headers(frame->header_block(), frame->header_block_len());
frame->header_block_len());
SpdyHeaderBlock new_headers; SpdyHeaderBlock new_headers;
EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(),
serialized_headers.size() - 2, serialized_headers.size() - 2,
...@@ -634,7 +632,7 @@ TEST_P(SpdyFramerTest, OutOfOrderHeaders) { ...@@ -634,7 +632,7 @@ TEST_P(SpdyFramerTest, OutOfOrderHeaders) {
SpdyHeaderBlock new_headers; SpdyHeaderBlock new_headers;
scoped_ptr<SpdyFrame> control_frame(frame.take()); scoped_ptr<SpdyFrame> control_frame(frame.take());
SpdySynStreamControlFrame syn_frame(control_frame->data(), false); SpdySynStreamControlFrame syn_frame(control_frame->data(), false);
std::string serialized_headers(syn_frame.header_block(), string serialized_headers(syn_frame.header_block(),
syn_frame.header_block_len()); syn_frame.header_block_len());
SpdyFramer framer(spdy_version_); SpdyFramer framer(spdy_version_);
framer.set_enable_compression(false); framer.set_enable_compression(false);
...@@ -741,7 +739,7 @@ TEST_P(SpdyFramerTest, DuplicateHeader) { ...@@ -741,7 +739,7 @@ TEST_P(SpdyFramerTest, DuplicateHeader) {
SpdyHeaderBlock new_headers; SpdyHeaderBlock new_headers;
scoped_ptr<SpdyFrame> control_frame(frame.take()); scoped_ptr<SpdyFrame> control_frame(frame.take());
SpdySynStreamControlFrame syn_frame(control_frame->data(), false); SpdySynStreamControlFrame syn_frame(control_frame->data(), false);
std::string serialized_headers(syn_frame.header_block(), string serialized_headers(syn_frame.header_block(),
syn_frame.header_block_len()); syn_frame.header_block_len());
SpdyFramer framer(spdy_version_); SpdyFramer framer(spdy_version_);
framer.set_enable_compression(false); framer.set_enable_compression(false);
...@@ -759,7 +757,7 @@ TEST_P(SpdyFramerTest, MultiValueHeader) { ...@@ -759,7 +757,7 @@ TEST_P(SpdyFramerTest, MultiValueHeader) {
frame.WriteUInt32(0); // associated stream id frame.WriteUInt32(0); // associated stream id
frame.WriteUInt16(0); // Priority. frame.WriteUInt16(0); // Priority.
std::string value("value1\0value2"); string value("value1\0value2");
if (IsSpdy2()) { if (IsSpdy2()) {
frame.WriteUInt16(1); // Number of headers. frame.WriteUInt16(1); // Number of headers.
frame.WriteString("name"); frame.WriteString("name");
...@@ -775,7 +773,7 @@ TEST_P(SpdyFramerTest, MultiValueHeader) { ...@@ -775,7 +773,7 @@ TEST_P(SpdyFramerTest, MultiValueHeader) {
SpdyHeaderBlock new_headers; SpdyHeaderBlock new_headers;
scoped_ptr<SpdyFrame> control_frame(frame.take()); scoped_ptr<SpdyFrame> control_frame(frame.take());
SpdySynStreamControlFrame syn_frame(control_frame->data(), false); SpdySynStreamControlFrame syn_frame(control_frame->data(), false);
std::string serialized_headers(syn_frame.header_block(), string serialized_headers(syn_frame.header_block(),
syn_frame.header_block_len()); syn_frame.header_block_len());
SpdyFramer framer(spdy_version_); SpdyFramer framer(spdy_version_);
framer.set_enable_compression(false); framer.set_enable_compression(false);
...@@ -1158,7 +1156,7 @@ TEST_P(SpdyFramerTest, HeaderCompression) { ...@@ -1158,7 +1156,7 @@ TEST_P(SpdyFramerTest, HeaderCompression) {
// Now start decompressing // Now start decompressing
scoped_ptr<SpdyFrame> decompressed; scoped_ptr<SpdyFrame> decompressed;
scoped_ptr<SpdySynStreamControlFrame> syn_frame; scoped_ptr<SpdySynStreamControlFrame> syn_frame;
scoped_ptr<std::string> serialized_headers; scoped_ptr<string> serialized_headers;
SpdyHeaderBlock decompressed_headers; SpdyHeaderBlock decompressed_headers;
// Decompress SYN_STREAM #1 // Decompress SYN_STREAM #1
...@@ -1169,7 +1167,7 @@ TEST_P(SpdyFramerTest, HeaderCompression) { ...@@ -1169,7 +1167,7 @@ TEST_P(SpdyFramerTest, HeaderCompression) {
EXPECT_EQ(SYN_STREAM, EXPECT_EQ(SYN_STREAM,
reinterpret_cast<SpdyControlFrame*>(decompressed.get())->type()); reinterpret_cast<SpdyControlFrame*>(decompressed.get())->type());
syn_frame.reset(new SpdySynStreamControlFrame(decompressed->data(), false)); syn_frame.reset(new SpdySynStreamControlFrame(decompressed->data(), false));
serialized_headers.reset(new std::string(syn_frame->header_block(), serialized_headers.reset(new string(syn_frame->header_block(),
syn_frame->header_block_len())); syn_frame->header_block_len()));
EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers->c_str(), EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers->c_str(),
serialized_headers->size(), serialized_headers->size(),
...@@ -1186,7 +1184,7 @@ TEST_P(SpdyFramerTest, HeaderCompression) { ...@@ -1186,7 +1184,7 @@ TEST_P(SpdyFramerTest, HeaderCompression) {
EXPECT_EQ(SYN_STREAM, EXPECT_EQ(SYN_STREAM,
reinterpret_cast<SpdyControlFrame*>(decompressed.get())->type()); reinterpret_cast<SpdyControlFrame*>(decompressed.get())->type());
syn_frame.reset(new SpdySynStreamControlFrame(decompressed->data(), false)); syn_frame.reset(new SpdySynStreamControlFrame(decompressed->data(), false));
serialized_headers.reset(new std::string(syn_frame->header_block(), serialized_headers.reset(new string(syn_frame->header_block(),
syn_frame->header_block_len())); syn_frame->header_block_len()));
decompressed_headers.clear(); decompressed_headers.clear();
EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers->c_str(), EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers->c_str(),
...@@ -1343,7 +1341,7 @@ TEST_P(SpdyFramerTest, CreateDataFrame) { ...@@ -1343,7 +1341,7 @@ TEST_P(SpdyFramerTest, CreateDataFrame) {
}; };
const char bytes[] = "hello"; const char bytes[] = "hello";
scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame( scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame(
1, bytes, arraysize(bytes) - 1, DATA_FLAG_NONE)); 1, bytes, strlen(bytes), DATA_FLAG_NONE));
CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
} }
...@@ -1399,7 +1397,7 @@ TEST_P(SpdyFramerTest, CreateDataFrame) { ...@@ -1399,7 +1397,7 @@ TEST_P(SpdyFramerTest, CreateDataFrame) {
{ {
const char kDescription[] = "Large data frame"; const char kDescription[] = "Large data frame";
const int kDataSize = 4 * 1024 * 1024; // 4 MB const int kDataSize = 4 * 1024 * 1024; // 4 MB
const std::string kData(kDataSize, 'A'); const string kData(kDataSize, 'A');
const unsigned char kFrameHeader[] = { const unsigned char kFrameHeader[] = {
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x01, 0x40, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00,
...@@ -1428,8 +1426,8 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { ...@@ -1428,8 +1426,8 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) {
headers["bar"] = "foo"; headers["bar"] = "foo";
headers["foo"] = "bar"; headers["foo"] = "bar";
const unsigned char kPri = (IsSpdy2()) ? 0xC0 : 0xE0; const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0;
const unsigned char kCre = (IsSpdy2()) ? 0 : 2; const unsigned char kCre = IsSpdy2() ? 0 : 2;
const unsigned char kV2FrameData[] = { const unsigned char kV2FrameData[] = {
0x80, spdy_version_, 0x00, 0x01, 0x80, spdy_version_, 0x00, 0x01,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
...@@ -1530,7 +1528,7 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { ...@@ -1530,7 +1528,7 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) {
headers["bar"] = "foo"; headers["bar"] = "foo";
headers["foo"] = ""; headers["foo"] = "";
const unsigned char kPri = (spdy_version_ != 2) ? 0x20 : 0x40; const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20;
const unsigned char kV2FrameData[] = { const unsigned char kV2FrameData[] = {
0x80, spdy_version_, 0x00, 0x01, 0x80, spdy_version_, 0x00, 0x01,
0x01, 0x00, 0x00, 0x1D, 0x01, 0x00, 0x00, 0x1D,
...@@ -1584,7 +1582,7 @@ TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { ...@@ -1584,7 +1582,7 @@ TEST_P(SpdyFramerTest, CreateSynStreamCompressed) {
headers["bar"] = "foo"; headers["bar"] = "foo";
headers["foo"] = "bar"; headers["foo"] = "bar";
const SpdyPriority priority = (spdy_version_ != 2) ? 4 : 2; const SpdyPriority priority = IsSpdy2() ? 2 : 4;
const unsigned char kV2FrameData[] = { const unsigned char kV2FrameData[] = {
0x80, spdy_version_, 0x00, 0x01, 0x80, spdy_version_, 0x00, 0x01,
0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x25,
...@@ -1747,9 +1745,8 @@ TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { ...@@ -1747,9 +1745,8 @@ TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) {
0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); 0x7fffffff, CONTROL_FLAG_FIN, false, &headers));
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
(IsSpdy2()) ? kV2FrameData : kV3FrameData, IsSpdy2() ? kV2FrameData : kV3FrameData,
(IsSpdy2()) ? arraysize(kV2FrameData) IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
: arraysize(kV3FrameData));
} }
} }
...@@ -1794,9 +1791,8 @@ TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { ...@@ -1794,9 +1791,8 @@ TEST_P(SpdyFramerTest, CreateSynReplyCompressed) {
1, CONTROL_FLAG_NONE, true, &headers)); 1, CONTROL_FLAG_NONE, true, &headers));
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
(IsSpdy2()) ? kV2FrameData : kV3FrameData, IsSpdy2() ? kV2FrameData : kV3FrameData,
(IsSpdy2()) ? arraysize(kV2FrameData) IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
: arraysize(kV3FrameData));
} }
} }
...@@ -1879,7 +1875,7 @@ TEST_P(SpdyFramerTest, CreateSettings) { ...@@ -1879,7 +1875,7 @@ TEST_P(SpdyFramerTest, CreateSettings) {
scoped_ptr<SpdySettingsControlFrame> frame(framer.CreateSettings(settings)); scoped_ptr<SpdySettingsControlFrame> frame(framer.CreateSettings(settings));
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
(IsSpdy2()) ? kFrameDatav2 : kFrameDatav3, IsSpdy2() ? kFrameDatav2 : kFrameDatav3,
arraysize(kFrameDatav3)); // Size is unchanged among versions. arraysize(kFrameDatav3)); // Size is unchanged among versions.
EXPECT_EQ(SpdyFramer::kInvalidStream, EXPECT_EQ(SpdyFramer::kInvalidStream,
SpdyFramer::GetControlFrameStreamId(frame.get())); SpdyFramer::GetControlFrameStreamId(frame.get()));
...@@ -1987,8 +1983,7 @@ TEST_P(SpdyFramerTest, CreateGoAway) { ...@@ -1987,8 +1983,7 @@ TEST_P(SpdyFramerTest, CreateGoAway) {
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
IsSpdy2() ? kV2FrameData : kV3FrameData, IsSpdy2() ? kV2FrameData : kV3FrameData,
IsSpdy2() ? arraysize(kV2FrameData) IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
: arraysize(kV3FrameData));
EXPECT_EQ(SpdyFramer::kInvalidStream, EXPECT_EQ(SpdyFramer::kInvalidStream,
SpdyFramer::GetControlFrameStreamId(frame.get())); SpdyFramer::GetControlFrameStreamId(frame.get()));
} }
...@@ -2011,8 +2006,7 @@ TEST_P(SpdyFramerTest, CreateGoAway) { ...@@ -2011,8 +2006,7 @@ TEST_P(SpdyFramerTest, CreateGoAway) {
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
IsSpdy2() ? kV2FrameData : kV3FrameData, IsSpdy2() ? kV2FrameData : kV3FrameData,
IsSpdy2() ? arraysize(kV2FrameData) IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
: arraysize(kV3FrameData));
} }
} }
...@@ -2055,9 +2049,8 @@ TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { ...@@ -2055,9 +2049,8 @@ TEST_P(SpdyFramerTest, CreateHeadersUncompressed) {
1, CONTROL_FLAG_NONE, false, &headers)); 1, CONTROL_FLAG_NONE, false, &headers));
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
(IsSpdy2()) ? kV2FrameData : kV3FrameData, IsSpdy2() ? kV2FrameData : kV3FrameData,
(IsSpdy2()) ? arraysize(kV2FrameData) IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
: arraysize(kV3FrameData));
} }
{ {
...@@ -2097,8 +2090,7 @@ TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { ...@@ -2097,8 +2090,7 @@ TEST_P(SpdyFramerTest, CreateHeadersUncompressed) {
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
IsSpdy2() ? kV2FrameData : kV3FrameData, IsSpdy2() ? kV2FrameData : kV3FrameData,
IsSpdy2() ? arraysize(kV2FrameData) IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
: arraysize(kV3FrameData));
} }
{ {
...@@ -2138,8 +2130,7 @@ TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { ...@@ -2138,8 +2130,7 @@ TEST_P(SpdyFramerTest, CreateHeadersUncompressed) {
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
IsSpdy2() ? kV2FrameData : kV3FrameData, IsSpdy2() ? kV2FrameData : kV3FrameData,
IsSpdy2() ? arraysize(kV2FrameData) IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
: arraysize(kV3FrameData));
} }
} }
...@@ -2185,8 +2176,7 @@ TEST_P(SpdyFramerTest, CreateHeadersCompressed) { ...@@ -2185,8 +2176,7 @@ TEST_P(SpdyFramerTest, CreateHeadersCompressed) {
CompareFrame(kDescription, CompareFrame(kDescription,
*frame, *frame,
IsSpdy2() ? kV2FrameData : kV3FrameData, IsSpdy2() ? kV2FrameData : kV3FrameData,
IsSpdy2() ? arraysize(kV2FrameData) IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
: arraysize(kV3FrameData));
} }
} }
...@@ -2288,7 +2278,7 @@ TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { ...@@ -2288,7 +2278,7 @@ TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) {
visitor.use_compression_ = true; visitor.use_compression_ = true;
visitor.SimulateInFramer( visitor.SimulateInFramer(
reinterpret_cast<unsigned char*>(control_frame->data()), reinterpret_cast<unsigned char*>(control_frame->data()),
control_frame.get()->length() + SpdyControlFrame::kHeaderSize); control_frame->length() + SpdyControlFrame::kHeaderSize);
EXPECT_EQ(1, visitor.syn_reply_frame_count_); EXPECT_EQ(1, visitor.syn_reply_frame_count_);
EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
} }
...@@ -2308,7 +2298,7 @@ TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { ...@@ -2308,7 +2298,7 @@ TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) {
visitor.use_compression_ = true; visitor.use_compression_ = true;
visitor.SimulateInFramer( visitor.SimulateInFramer(
reinterpret_cast<unsigned char*>(control_frame->data()), reinterpret_cast<unsigned char*>(control_frame->data()),
control_frame.get()->length() + SpdyControlFrame::kHeaderSize); control_frame->length() + SpdyControlFrame::kHeaderSize);
EXPECT_EQ(1, visitor.headers_frame_count_); EXPECT_EQ(1, visitor.headers_frame_count_);
// control_frame_header_data_count_ depends on the random sequence // control_frame_header_data_count_ depends on the random sequence
// produced by rand(), so adding, removing or running single tests // produced by rand(), so adding, removing or running single tests
...@@ -2408,7 +2398,7 @@ TEST_P(SpdyFramerTest, ControlFrameTooLarge) { ...@@ -2408,7 +2398,7 @@ TEST_P(SpdyFramerTest, ControlFrameTooLarge) {
TestSpdyVisitor visitor(spdy_version_); TestSpdyVisitor visitor(spdy_version_);
visitor.SimulateInFramer( visitor.SimulateInFramer(
reinterpret_cast<unsigned char*>(control_frame->data()), reinterpret_cast<unsigned char*>(control_frame->data()),
control_frame.get()->length() + SpdyControlFrame::kHeaderSize); control_frame->length() + SpdyControlFrame::kHeaderSize);
EXPECT_FALSE(visitor.header_buffer_valid_); EXPECT_FALSE(visitor.header_buffer_valid_);
EXPECT_EQ(1, visitor.error_count_); EXPECT_EQ(1, visitor.error_count_);
EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE,
...@@ -2493,11 +2483,10 @@ TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { ...@@ -2493,11 +2483,10 @@ TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) {
// Create a GoAway frame that has a few extra bytes at the end. // Create a GoAway frame that has a few extra bytes at the end.
// We create enough overhead to overflow the framer's control frame buffer. // We create enough overhead to overflow the framer's control frame buffer.
size_t overhead = SpdyFramer::kControlFrameBufferSize; size_t overhead = SpdyFramer::kControlFrameBufferSize;
SpdyFramer framer(spdy_version_); SpdyFramer framer(spdy_version_);
scoped_ptr<SpdyGoAwayControlFrame> goaway(framer.CreateGoAway(1, GOAWAY_OK)); scoped_ptr<SpdyGoAwayControlFrame> goaway(framer.CreateGoAway(1, GOAWAY_OK));
goaway->set_length(goaway->length() + overhead); goaway->set_length(goaway->length() + overhead);
std::string pad('A', overhead); string pad('A', overhead);
TestSpdyVisitor visitor(spdy_version_); TestSpdyVisitor visitor(spdy_version_);
visitor.SimulateInFramer( visitor.SimulateInFramer(
...@@ -2506,6 +2495,7 @@ TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { ...@@ -2506,6 +2495,7 @@ TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) {
visitor.SimulateInFramer( visitor.SimulateInFramer(
reinterpret_cast<const unsigned char*>(pad.c_str()), reinterpret_cast<const unsigned char*>(pad.c_str()),
overhead); overhead);
EXPECT_EQ(1, visitor.error_count_); // This generated an error. EXPECT_EQ(1, visitor.error_count_); // This generated an error.
EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
visitor.framer_.error_code()); visitor.framer_.error_code());
...@@ -2521,7 +2511,7 @@ TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { ...@@ -2521,7 +2511,7 @@ TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) {
visitor.use_compression_ = false; visitor.use_compression_ = false;
visitor.SimulateInFramer( visitor.SimulateInFramer(
reinterpret_cast<unsigned char*>(control_frame->data()), reinterpret_cast<unsigned char*>(control_frame->data()),
control_frame.get()->length() + SpdyControlFrame::kHeaderSize); control_frame->length() + SpdyControlFrame::kHeaderSize);
// Should generate an error, since zero-len settings frames are unsupported. // Should generate an error, since zero-len settings frames are unsupported.
EXPECT_EQ(1, visitor.error_count_); EXPECT_EQ(1, visitor.error_count_);
} }
...@@ -2533,14 +2523,14 @@ TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { ...@@ -2533,14 +2523,14 @@ TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) {
// Add a setting to pad the frame so that we don't get a buffer overflow when // Add a setting to pad the frame so that we don't get a buffer overflow when
// calling SimulateInFramer() below. // calling SimulateInFramer() below.
settings[SETTINGS_UPLOAD_BANDWIDTH] = settings[SETTINGS_UPLOAD_BANDWIDTH] =
SettingsFlagsAndValue(SETTINGS_FLAG_NONE, 0x00000002); SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, 0x00000002);
scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings));
control_frame->set_length(5); control_frame->set_length(5);
TestSpdyVisitor visitor(spdy_version_); TestSpdyVisitor visitor(spdy_version_);
visitor.use_compression_ = false; visitor.use_compression_ = false;
visitor.SimulateInFramer( visitor.SimulateInFramer(
reinterpret_cast<unsigned char*>(control_frame->data()), reinterpret_cast<unsigned char*>(control_frame->data()),
control_frame.get()->length() + SpdyControlFrame::kHeaderSize); control_frame->length() + SpdyControlFrame::kHeaderSize);
// Should generate an error, since zero-len settings frames are unsupported. // Should generate an error, since zero-len settings frames are unsupported.
EXPECT_EQ(1, visitor.error_count_); EXPECT_EQ(1, visitor.error_count_);
} }
...@@ -2549,7 +2539,7 @@ TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { ...@@ -2549,7 +2539,7 @@ TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) {
TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) { TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) {
SpdyFramer framer(spdy_version_); SpdyFramer framer(spdy_version_);
SettingsMap settings; SettingsMap settings;
SpdySettingsFlags flags = SETTINGS_FLAG_NONE; SpdySettingsFlags flags = SETTINGS_FLAG_PLEASE_PERSIST;
settings[SETTINGS_UPLOAD_BANDWIDTH] = settings[SETTINGS_UPLOAD_BANDWIDTH] =
SettingsFlagsAndValue(flags, 0x00000002); SettingsFlagsAndValue(flags, 0x00000002);
settings[SETTINGS_DOWNLOAD_BANDWIDTH] = settings[SETTINGS_DOWNLOAD_BANDWIDTH] =
...@@ -2575,7 +2565,7 @@ TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) { ...@@ -2575,7 +2565,7 @@ TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) {
SpdyControlFrame::kHeaderSize; SpdyControlFrame::kHeaderSize;
size_t kReadChunkSize = 5; // Read five bytes at a time. size_t kReadChunkSize = 5; // Read five bytes at a time.
while (unframed_data > 0) { while (unframed_data > 0) {
size_t to_read = std::min(kReadChunkSize, unframed_data); size_t to_read = min(kReadChunkSize, unframed_data);
visitor.SimulateInFramer( visitor.SimulateInFramer(
reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), reinterpret_cast<unsigned char*>(control_frame->data() + framed_data),
to_read); to_read);
...@@ -2601,8 +2591,8 @@ TEST_P(SpdyFramerTest, ReadCredentialFrame) { ...@@ -2601,8 +2591,8 @@ TEST_P(SpdyFramerTest, ReadCredentialFrame) {
TestSpdyVisitor visitor(spdy_version_); TestSpdyVisitor visitor(spdy_version_);
visitor.use_compression_ = false; visitor.use_compression_ = false;
visitor.SimulateInFramer( visitor.SimulateInFramer(
reinterpret_cast<unsigned char*>(control_frame.get()->data()), reinterpret_cast<unsigned char*>(control_frame->data()),
control_frame.get()->length() + SpdyControlFrame::kHeaderSize); control_frame->length() + SpdyControlFrame::kHeaderSize);
EXPECT_EQ(0, visitor.error_count_); EXPECT_EQ(0, visitor.error_count_);
EXPECT_EQ(1, visitor.credential_count_); EXPECT_EQ(1, visitor.credential_count_);
EXPECT_EQ(control_frame->length(), visitor.credential_buffer_length_); EXPECT_EQ(control_frame->length(), visitor.credential_buffer_length_);
...@@ -2681,11 +2671,11 @@ TEST_P(SpdyFramerTest, ReadCredentialFrameWithCorruptProof) { ...@@ -2681,11 +2671,11 @@ TEST_P(SpdyFramerTest, ReadCredentialFrameWithCorruptProof) {
TestSpdyVisitor visitor(spdy_version_); TestSpdyVisitor visitor(spdy_version_);
visitor.use_compression_ = false; visitor.use_compression_ = false;
unsigned char* data = unsigned char* data =
reinterpret_cast<unsigned char*>(control_frame.get()->data()); reinterpret_cast<unsigned char*>(control_frame->data());
size_t offset = SpdyControlFrame::kHeaderSize + 4; size_t offset = SpdyControlFrame::kHeaderSize + 4;
data[offset] = 0xFF; // Proof length is past the end of the frame data[offset] = 0xFF; // Proof length is past the end of the frame
visitor.SimulateInFramer( visitor.SimulateInFramer(
data, control_frame.get()->length() + SpdyControlFrame::kHeaderSize); data, control_frame->length() + SpdyControlFrame::kHeaderSize);
EXPECT_EQ(1, visitor.error_count_); EXPECT_EQ(1, visitor.error_count_);
} }
...@@ -2703,11 +2693,11 @@ TEST_P(SpdyFramerTest, ReadCredentialFrameWithCorruptCertificate) { ...@@ -2703,11 +2693,11 @@ TEST_P(SpdyFramerTest, ReadCredentialFrameWithCorruptCertificate) {
TestSpdyVisitor visitor(spdy_version_); TestSpdyVisitor visitor(spdy_version_);
visitor.use_compression_ = false; visitor.use_compression_ = false;
unsigned char* data = unsigned char* data =
reinterpret_cast<unsigned char*>(control_frame.get()->data()); reinterpret_cast<unsigned char*>(control_frame->data());
size_t offset = SpdyControlFrame::kHeaderSize + credential.proof.length(); size_t offset = SpdyControlFrame::kHeaderSize + credential.proof.length();
data[offset] = 0xFF; // Certificate length is past the end of the frame data[offset] = 0xFF; // Certificate length is past the end of the frame
visitor.SimulateInFramer( visitor.SimulateInFramer(
data, control_frame.get()->length() + SpdyControlFrame::kHeaderSize); data, control_frame->length() + SpdyControlFrame::kHeaderSize);
EXPECT_EQ(1, visitor.error_count_); EXPECT_EQ(1, visitor.error_count_);
} }
...@@ -2883,7 +2873,7 @@ TEST_P(SpdyFramerTest, GetMinimumControlFrameSizeTest) { ...@@ -2883,7 +2873,7 @@ TEST_P(SpdyFramerTest, GetMinimumControlFrameSizeTest) {
EXPECT_EQ(SpdyCredentialControlFrame::size(), EXPECT_EQ(SpdyCredentialControlFrame::size(),
SpdyFramer::GetMinimumControlFrameSize(spdy_version_, SpdyFramer::GetMinimumControlFrameSize(spdy_version_,
CREDENTIAL)); CREDENTIAL));
EXPECT_EQ(static_cast<size_t>(0x7FFFFFFF), EXPECT_EQ(numeric_limits<size_t>::max(),
SpdyFramer::GetMinimumControlFrameSize(spdy_version_, SpdyFramer::GetMinimumControlFrameSize(spdy_version_,
NUM_CONTROL_FRAME_TYPES)); NUM_CONTROL_FRAME_TYPES));
} }
...@@ -2968,8 +2958,7 @@ TEST_P(SpdyFramerTest, EmptySynStream) { ...@@ -2968,8 +2958,7 @@ TEST_P(SpdyFramerTest, EmptySynStream) {
TEST_P(SpdyFramerTest, SettingsFlagsAndId) { TEST_P(SpdyFramerTest, SettingsFlagsAndId) {
const uint32 kId = 0x020304; const uint32 kId = 0x020304;
const uint32 kFlags = 0x01; const uint32 kFlags = 0x01;
const uint32 kWireFormat = const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304);
htonl(IsSpdy2() ? 0x04030201 : 0x01020304);
SettingsFlagsAndId id_and_flags = SettingsFlagsAndId id_and_flags =
SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat);
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
namespace { namespace {
enum SpdyProtocolTestTypes { enum SpdyProtocolTestTypes {
SPDY2, SPDY2 = 2,
SPDY3, SPDY3 = 3,
}; };
} // namespace } // namespace
...@@ -24,18 +24,15 @@ class SpdyProtocolTest ...@@ -24,18 +24,15 @@ class SpdyProtocolTest
: public ::testing::TestWithParam<SpdyProtocolTestTypes> { : public ::testing::TestWithParam<SpdyProtocolTestTypes> {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
spdy_version_ = (GetParam() == SPDY2) ? 2 : 3; spdy_version_ = GetParam();
} }
virtual void TearDown() {} bool IsSpdy2() { return spdy_version_ == SPDY2; }
bool IsSpdy2() { return spdy_version_ < 3; }
// Version of SPDY protocol to be used. // Version of SPDY protocol to be used.
int spdy_version_; int spdy_version_;
}; };
//-----------------------------------------------------------------------------
// All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
INSTANTIATE_TEST_CASE_P(SpdyProtocolTests, INSTANTIATE_TEST_CASE_P(SpdyProtocolTests,
SpdyProtocolTest, SpdyProtocolTest,
...@@ -274,10 +271,9 @@ TEST_P(SpdyProtocolTest, HasHeaderBlock) { ...@@ -274,10 +271,9 @@ TEST_P(SpdyProtocolTest, HasHeaderBlock) {
} }
} }
//-----------------------------------------------------------------------------
// All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
class SpdyProtocolDeathTest : public SpdyProtocolTest {}; class SpdyProtocolDeathTest : public SpdyProtocolTest {};
// All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
INSTANTIATE_TEST_CASE_P(SpdyProtocolDeathTests, INSTANTIATE_TEST_CASE_P(SpdyProtocolDeathTests,
SpdyProtocolDeathTest, SpdyProtocolDeathTest,
::testing::Values(SPDY2, SPDY3)); ::testing::Values(SPDY2, SPDY3));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment