Commit abf7b949 authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Convert FrameParts to a class.

As the TODO in frame_parts.h, Convert FrameParts to a class,
hide the member variables, add getters/setters for them.

BUG=
Signed-off-by: default avatarZhuoyu Qian <zhuoyu.qian@samsung.com>
Change-Id: I897045b887842647e79cf9e8ff301b7faf8dcd90
Reviewed-on: https://chromium-review.googlesource.com/844499Reviewed-by: default avatarBence Béky <bnc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526925}
parent 2294ef78
......@@ -196,7 +196,7 @@ class Http2FrameDecoderTest : public RandomDecoderTest {
template <size_t N>
AssertionResult DecodePayloadExpectingFrameSizeError(const char (&buf)[N],
FrameParts expected) {
expected.has_frame_size_error = true;
expected.SetHasFrameSizeError(true);
VERIFY_AND_RETURN_SUCCESS(DecodePayloadExpectingError(buf, expected));
}
......@@ -260,7 +260,7 @@ TEST_F(Http2FrameDecoderTest, Priority) {
};
Http2FrameHeader header(5, Http2FrameType::PRIORITY, 0, 2);
FrameParts expected(header);
expected.opt_priority = Http2PriorityFields(1, 17, true);
expected.SetOptPriority(Http2PriorityFields(1, 17, true));
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -274,7 +274,7 @@ TEST_F(Http2FrameDecoderTest, RstStream) {
};
Http2FrameHeader header(4, Http2FrameType::RST_STREAM, 0, 1);
FrameParts expected(header);
expected.opt_rst_stream_error_code = Http2ErrorCode::PROTOCOL_ERROR;
expected.SetOptRstStreamErrorCode(Http2ErrorCode::PROTOCOL_ERROR);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -312,7 +312,7 @@ TEST_F(Http2FrameDecoderTest, PushPromiseMinimal) {
Http2FrameHeader header(4, Http2FrameType::PUSH_PROMISE,
Http2FrameFlag::END_HEADERS, 2);
FrameParts expected(header, "");
expected.opt_push_promise = Http2PushPromiseFields{1};
expected.SetOptPushPromise(Http2PushPromiseFields{1});
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -327,7 +327,8 @@ TEST_F(Http2FrameDecoderTest, Ping) {
};
Http2FrameHeader header(8, Http2FrameType::PING, 0, 0);
FrameParts expected(header);
expected.opt_ping = Http2PingFields{{'s', 'o', 'm', 'e', 'd', 'a', 't', 'a'}};
expected.SetOptPing(
Http2PingFields{{'s', 'o', 'm', 'e', 'd', 'a', 't', 'a'}});
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -342,7 +343,8 @@ TEST_F(Http2FrameDecoderTest, PingAck) {
};
Http2FrameHeader header(8, Http2FrameType::PING, Http2FrameFlag::ACK, 0);
FrameParts expected(header);
expected.opt_ping = Http2PingFields{{'s', 'o', 'm', 'e', 'd', 'a', 't', 'a'}};
expected.SetOptPing(
Http2PingFields{{'s', 'o', 'm', 'e', 'd', 'a', 't', 'a'}});
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -357,8 +359,8 @@ TEST_F(Http2FrameDecoderTest, GoAwayMinimal) {
};
Http2FrameHeader header(8, Http2FrameType::GOAWAY, 0, 1);
FrameParts expected(header);
expected.opt_goaway =
Http2GoAwayFields(255, Http2ErrorCode::COMPRESSION_ERROR);
expected.SetOptGoaway(
Http2GoAwayFields(255, Http2ErrorCode::COMPRESSION_ERROR));
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -372,7 +374,7 @@ TEST_F(Http2FrameDecoderTest, WindowUpdate) {
};
Http2FrameHeader header(4, Http2FrameType::WINDOW_UPDATE, 0, 1);
FrameParts expected(header);
expected.opt_window_update_increment = 1024;
expected.SetOptWindowUpdateIncrement(1024);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -398,8 +400,8 @@ TEST_F(Http2FrameDecoderTest, AltSvcMinimal) {
};
Http2FrameHeader header(2, Http2FrameType::ALTSVC, 0, 0);
FrameParts expected(header);
expected.opt_altsvc_origin_length = 0;
expected.opt_altsvc_value_length = 0;
expected.SetOptAltsvcOriginLength(0);
expected.SetOptAltsvcValueLength(0);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -458,7 +460,7 @@ TEST_F(Http2FrameDecoderTest, HeadersPriority) {
Http2FrameHeader header(5, Http2FrameType::HEADERS, Http2FrameFlag::PRIORITY,
2);
FrameParts expected(header);
expected.opt_priority = Http2PriorityFields(1, 256, false);
expected.SetOptPriority(Http2PriorityFields(1, 256, false));
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -475,9 +477,9 @@ TEST_F(Http2FrameDecoderTest, Settings) {
};
Http2FrameHeader header(12, Http2FrameType::SETTINGS, 0, 0);
FrameParts expected(header);
expected.settings.push_back(Http2SettingFields(
expected.AppendSetting(Http2SettingFields(
Http2SettingsParameter::INITIAL_WINDOW_SIZE, 168496141));
expected.settings.push_back(
expected.AppendSetting(
Http2SettingFields(Http2SettingsParameter::ENABLE_PUSH, 3));
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -494,7 +496,7 @@ TEST_F(Http2FrameDecoderTest, PushPromisePayload) {
Http2FrameHeader header(7, Http2FrameType::PUSH_PROMISE,
Http2FrameFlag::END_HEADERS, 255);
FrameParts expected(header, "abc");
expected.opt_push_promise = Http2PushPromiseFields{256};
expected.SetOptPushPromise(Http2PushPromiseFields{256});
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -510,8 +512,8 @@ TEST_F(Http2FrameDecoderTest, GoAwayOpaqueData) {
};
Http2FrameHeader header(14, Http2FrameType::GOAWAY, 0, 0);
FrameParts expected(header, "opaque");
expected.opt_goaway =
Http2GoAwayFields(256, Http2ErrorCode::FLOW_CONTROL_ERROR);
expected.SetOptGoaway(
Http2GoAwayFields(256, Http2ErrorCode::FLOW_CONTROL_ERROR));
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -615,7 +617,7 @@ TEST_F(Http2FrameDecoderTest, HeadersPayloadPriorityAndPadding) {
2);
size_t total_pad_length = 4; // Including the Pad Length field.
FrameParts expected(header, "abc", total_pad_length);
expected.opt_priority = Http2PriorityFields(1, 17, true);
expected.SetOptPriority(Http2PriorityFields(1, 17, true));
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -635,7 +637,7 @@ TEST_F(Http2FrameDecoderTest, PushPromisePayloadAndPadding) {
1);
size_t total_pad_length = 4; // Including the Pad Length field.
FrameParts expected(header, "abc", total_pad_length);
expected.opt_push_promise = Http2PushPromiseFields{2};
expected.SetOptPushPromise(Http2PushPromiseFields{2});
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(kFrameData, expected));
}
......@@ -651,7 +653,7 @@ TEST_F(Http2FrameDecoderTest, DataMissingPadLengthField) {
};
Http2FrameHeader header(0, Http2FrameType::DATA, Http2FrameFlag::PADDED, 1);
FrameParts expected(header);
expected.opt_missing_length = 1;
expected.SetOptMissingLength(1);
EXPECT_TRUE(DecodePayloadExpectingError(kFrameData, expected));
}
......@@ -667,7 +669,7 @@ TEST_F(Http2FrameDecoderTest, HeaderPaddingTooLong) {
Http2FrameHeader header(2, Http2FrameType::HEADERS, Http2FrameFlag::PADDED,
65536);
FrameParts expected(header);
expected.opt_missing_length = 254;
expected.SetOptMissingLength(254);
EXPECT_TRUE(DecodePayloadExpectingError(kFrameData, expected));
}
......@@ -723,7 +725,7 @@ TEST_F(Http2FrameDecoderTest, SettingsWrongSize) {
};
Http2FrameHeader header(9, Http2FrameType::SETTINGS, 0, 0);
FrameParts expected(header);
expected.settings.push_back(
expected.AppendSetting(
Http2SettingFields(Http2SettingsParameter::ENABLE_PUSH, 3));
EXPECT_TRUE(DecodePayloadExpectingFrameSizeError(kFrameData, expected));
}
......@@ -835,7 +837,7 @@ TEST_F(Http2FrameDecoderTest, BeyondMaximum) {
Http2FrameFlag::END_STREAM | Http2FrameFlag::PADDED,
2);
FrameParts expected(header);
expected.has_frame_size_error = true;
expected.SetHasFrameSizeError(true);
auto validator = [&expected, this](const DecodeBuffer& input,
DecodeStatus status) -> AssertionResult {
VERIFY_EQ(status, DecodeStatus::kDecodeError);
......
......@@ -98,7 +98,7 @@ TEST_P(GoAwayOpaqueDataLengthTests, ValidLength) {
RandStreamId());
set_frame_header(header);
FrameParts expected(header, opaque_data);
expected.opt_goaway = goaway;
expected.SetOptGoaway(goaway);
ASSERT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
}
......
......@@ -126,7 +126,7 @@ TEST_P(HeadersPayloadDecoderTest, VariousHpackPayloadSizes) {
ScrubFlagsOfHeader(&frame_header);
FrameParts expected(frame_header, hpack_payload, total_pad_length_);
if (has_priority) {
expected.opt_priority = priority;
expected.SetOptPriority(priority);
}
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(frame_builder_.buffer(),
expected));
......
......@@ -232,11 +232,11 @@ class AbstractPayloadDecoderTest : public PayloadDecoderBaseTest {
VERIFY_FALSE(listener_.IsInProgress());
VERIFY_EQ(1u, listener_.size());
const FrameParts* frame = listener_.frame(0);
VERIFY_EQ(header, frame->frame_header);
VERIFY_TRUE(frame->has_frame_size_error);
VERIFY_EQ(header, frame->GetFrameHeader());
VERIFY_TRUE(frame->GetHasFrameSizeError());
// Verify did not get OnPaddingTooLong, as we should only ever produce
// one of these two errors for a single frame.
VERIFY_FALSE(frame->opt_missing_length);
VERIFY_FALSE(frame->GetOptMissingLength());
return validator(input, status);
};
VERIFY_AND_RETURN_SUCCESS(
......@@ -403,11 +403,11 @@ class AbstractPaddablePayloadDecoderTest
VERIFY_FALSE(listener.IsInProgress());
VERIFY_EQ(1u, listener.size());
const FrameParts* frame = listener.frame(0);
VERIFY_EQ(header, frame->frame_header);
VERIFY_TRUE(frame->opt_missing_length);
VERIFY_EQ(expected_missing_length, frame->opt_missing_length.value());
VERIFY_EQ(header, frame->GetFrameHeader());
VERIFY_TRUE(frame->GetOptMissingLength());
VERIFY_EQ(expected_missing_length, frame->GetOptMissingLength().value());
// Verify did not get OnFrameSizeError.
VERIFY_FALSE(frame->has_frame_size_error);
VERIFY_FALSE(frame->GetHasFrameSizeError());
return ::testing::AssertionSuccess();
};
VERIFY_AND_RETURN_SUCCESS(
......
......@@ -85,7 +85,7 @@ TEST_F(PingPayloadDecoderTest, Ping) {
RandFlags() & ~Http2FrameFlag::ACK, RandStreamId());
set_frame_header(header);
FrameParts expected(header);
expected.opt_ping = fields;
expected.SetOptPing(fields);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
}
}
......@@ -100,7 +100,7 @@ TEST_F(PingPayloadDecoderTest, PingAck) {
RandFlags() | Http2FrameFlag::ACK, RandStreamId());
set_frame_header(header);
FrameParts expected(header);
expected.opt_ping = fields;
expected.SetOptPing(fields);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
}
}
......
......@@ -80,7 +80,7 @@ TEST_F(PriorityPayloadDecoderTest, VariousPayloads) {
RandStreamId());
set_frame_header(header);
FrameParts expected(header);
expected.opt_priority = fields;
expected.SetOptPriority(fields);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
}
}
......
......@@ -108,7 +108,7 @@ TEST_P(PushPromisePayloadDecoderTest, VariousHpackPayloadSizes) {
RandStreamId());
set_frame_header(frame_header);
FrameParts expected(frame_header, hpack_payload, total_pad_length_);
expected.opt_push_promise = push_promise;
expected.SetOptPushPromise(push_promise);
EXPECT_TRUE(
DecodePayloadAndValidateSeveralWays(frame_builder_.buffer(), expected));
}
......
......@@ -82,7 +82,7 @@ TEST_F(RstStreamPayloadDecoderTest, AllErrors) {
RandStreamId());
set_frame_header(header);
FrameParts expected(header);
expected.opt_rst_stream_error_code = error_code;
expected.SetOptRstStreamErrorCode(error_code);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
}
}
......
......@@ -129,7 +129,7 @@ TEST_F(SettingsPayloadDecoderTest, OneRealSetting) {
RandStreamId());
set_frame_header(header);
FrameParts expected(header);
expected.settings.push_back(fields);
expected.AppendSetting(fields);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
}
}
......@@ -149,7 +149,7 @@ TEST_F(SettingsPayloadDecoderTest, ManySettings) {
Http2SettingFields fields(static_cast<Http2SettingsParameter>(n),
Random().Rand32());
fb.Append(fields);
expected.settings.push_back(fields);
expected.AppendSetting(fields);
}
ASSERT_EQ(size, fb.size());
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
......
......@@ -86,7 +86,7 @@ TEST_F(WindowUpdatePayloadDecoderTest, VariousPayloads) {
RandFlags(), stream_id);
set_frame_header(header);
FrameParts expected(header);
expected.opt_window_update_increment = fields.window_size_increment;
expected.SetOptWindowUpdateIncrement(fields.window_size_increment);
EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
}
}
......
This diff is collapsed.
......@@ -10,9 +10,6 @@
// info that a test expects to be recorded during the decoding of a frame
// with the actual recorded value (i.e. by providing a comparator).
// TODO(jamessynge): Convert FrameParts to a class, hide the members, add
// getters/setters.
#include <stddef.h>
#include <vector>
......@@ -29,11 +26,8 @@
namespace net {
namespace test {
// Forward declarations.
struct FrameParts;
std::ostream& operator<<(std::ostream& out, const FrameParts& v);
struct FrameParts : public Http2FrameDecoderListener {
class FrameParts : public Http2FrameDecoderListener {
public:
// The first callback for every type of frame includes the frame header; this
// is the only constructor used during decoding of a frame.
explicit FrameParts(const Http2FrameHeader& header);
......@@ -113,36 +107,82 @@ struct FrameParts : public Http2FrameDecoderListener {
size_t missing_length) override;
void OnFrameSizeError(const Http2FrameHeader& header) override;
// The fields are public for access by tests.
const Http2FrameHeader frame_header;
Http2String payload;
Http2String padding;
Http2String altsvc_origin;
Http2String altsvc_value;
base::Optional<Http2PriorityFields> opt_priority;
base::Optional<Http2ErrorCode> opt_rst_stream_error_code;
base::Optional<Http2PushPromiseFields> opt_push_promise;
base::Optional<Http2PingFields> opt_ping;
base::Optional<Http2GoAwayFields> opt_goaway;
base::Optional<size_t> opt_pad_length;
base::Optional<size_t> opt_payload_length;
base::Optional<size_t> opt_missing_length;
base::Optional<size_t> opt_altsvc_origin_length;
base::Optional<size_t> opt_altsvc_value_length;
base::Optional<size_t> opt_window_update_increment;
bool has_frame_size_error = false;
std::vector<Http2SettingFields> settings;
// These booleans are not checked by CompareCollectedFrames.
bool got_start_callback = false;
bool got_end_callback = false;
void AppendSetting(const Http2SettingFields& setting_fields) {
settings_.push_back(setting_fields);
}
const Http2FrameHeader& GetFrameHeader() const { return frame_header_; }
base::Optional<Http2PriorityFields> GetOptPriority() const {
return opt_priority_;
}
base::Optional<Http2ErrorCode> GetOptRstStreamErrorCode() const {
return opt_rst_stream_error_code_;
}
base::Optional<Http2PushPromiseFields> GetOptPushPromise() const {
return opt_push_promise_;
}
base::Optional<Http2PingFields> GetOptPing() const { return opt_ping_; }
base::Optional<Http2GoAwayFields> GetOptGoaway() const { return opt_goaway_; }
base::Optional<size_t> GetOptPadLength() const { return opt_pad_length_; }
base::Optional<size_t> GetOptPayloadLength() const {
return opt_payload_length_;
}
base::Optional<size_t> GetOptMissingLength() const {
return opt_missing_length_;
}
base::Optional<size_t> GetOptAltsvcOriginLength() const {
return opt_altsvc_origin_length_;
}
base::Optional<size_t> GetOptAltsvcValueLength() const {
return opt_altsvc_value_length_;
}
base::Optional<size_t> GetOptWindowUpdateIncrement() const {
return opt_window_update_increment_;
}
bool GetHasFrameSizeError() const { return has_frame_size_error_; }
void SetOptPriority(base::Optional<Http2PriorityFields> opt_priority) {
opt_priority_ = opt_priority;
}
void SetOptRstStreamErrorCode(
base::Optional<Http2ErrorCode> opt_rst_stream_error_code) {
opt_rst_stream_error_code_ = opt_rst_stream_error_code;
}
void SetOptPushPromise(
base::Optional<Http2PushPromiseFields> opt_push_promise) {
opt_push_promise_ = opt_push_promise;
}
void SetOptPing(base::Optional<Http2PingFields> opt_ping) {
opt_ping_ = opt_ping;
}
void SetOptGoaway(base::Optional<Http2GoAwayFields> opt_goaway) {
opt_goaway_ = opt_goaway;
}
void SetOptPadLength(base::Optional<size_t> opt_pad_length) {
opt_pad_length_ = opt_pad_length;
}
void SetOptPayloadLength(base::Optional<size_t> opt_payload_length) {
opt_payload_length_ = opt_payload_length;
}
void SetOptMissingLength(base::Optional<size_t> opt_missing_length) {
opt_missing_length_ = opt_missing_length;
}
void SetOptAltsvcOriginLength(
base::Optional<size_t> opt_altsvc_origin_length) {
opt_altsvc_origin_length_ = opt_altsvc_origin_length;
}
void SetOptAltsvcValueLength(base::Optional<size_t> opt_altsvc_value_length) {
opt_altsvc_value_length_ = opt_altsvc_value_length;
}
void SetOptWindowUpdateIncrement(
base::Optional<size_t> opt_window_update_increment) {
opt_window_update_increment_ = opt_window_update_increment;
}
void SetHasFrameSizeError(bool has_frame_size_error) {
has_frame_size_error_ = has_frame_size_error;
}
private:
// ASSERT during an On* method that we're handling a frame of type
......@@ -169,8 +209,39 @@ struct FrameParts : public Http2FrameDecoderListener {
::testing::AssertionResult AppendString(Http2StringPiece source,
Http2String* target,
base::Optional<size_t>* opt_length);
const Http2FrameHeader frame_header_;
Http2String payload_;
Http2String padding_;
Http2String altsvc_origin_;
Http2String altsvc_value_;
base::Optional<Http2PriorityFields> opt_priority_;
base::Optional<Http2ErrorCode> opt_rst_stream_error_code_;
base::Optional<Http2PushPromiseFields> opt_push_promise_;
base::Optional<Http2PingFields> opt_ping_;
base::Optional<Http2GoAwayFields> opt_goaway_;
base::Optional<size_t> opt_pad_length_;
base::Optional<size_t> opt_payload_length_;
base::Optional<size_t> opt_missing_length_;
base::Optional<size_t> opt_altsvc_origin_length_;
base::Optional<size_t> opt_altsvc_value_length_;
base::Optional<size_t> opt_window_update_increment_;
bool has_frame_size_error_ = false;
std::vector<Http2SettingFields> settings_;
// These booleans are not checked by CompareCollectedFrames.
bool got_start_callback_ = false;
bool got_end_callback_ = false;
};
std::ostream& operator<<(std::ostream& out, const FrameParts& v);
} // namespace test
} // namespace net
......
......@@ -101,7 +101,7 @@ Http2FrameDecoderListener* FramePartsCollector::FrameError(
// frame before detecting the error; for example, the DATA payload decoder
// calls OnDataStart before it can detect padding errors, hence before it
// can call OnPaddingTooLong.
EXPECT_EQ(header, current_frame_->frame_header);
EXPECT_EQ(header, current_frame_->GetFrameHeader());
}
Http2FrameDecoderListener* result = current_frame();
collected_frames_.push_back(std::move(current_frame_));
......
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