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