| Index: net/websockets/websocket_frame_parser_test.cc
|
| diff --git a/net/websockets/websocket_frame_parser_test.cc b/net/websockets/websocket_frame_parser_test.cc
|
| index 4eb036db28e90e6799c98db8ff55efc8d0892c35..05a45d327074b0d0b0790a11bb51cfbe7b15b3cd 100644
|
| --- a/net/websockets/websocket_frame_parser_test.cc
|
| +++ b/net/websockets/websocket_frame_parser_test.cc
|
| @@ -35,19 +35,18 @@ struct FrameHeaderTestCase {
|
| };
|
|
|
| const FrameHeaderTestCase kFrameHeaderTests[] = {
|
| - { "\x81\x00", 2, GG_UINT64_C(0), kWebSocketNormalClosure },
|
| - { "\x81\x7D", 2, GG_UINT64_C(125), kWebSocketNormalClosure },
|
| - { "\x81\x7E\x00\x7E", 4, GG_UINT64_C(126), kWebSocketNormalClosure },
|
| - { "\x81\x7E\xFF\xFF", 4, GG_UINT64_C(0xFFFF), kWebSocketNormalClosure },
|
| - { "\x81\x7F\x00\x00\x00\x00\x00\x01\x00\x00", 10, GG_UINT64_C(0x10000),
|
| - kWebSocketNormalClosure },
|
| - { "\x81\x7F\x00\x00\x00\x00\x7F\xFF\xFF\xFF", 10, GG_UINT64_C(0x7FFFFFFF),
|
| - kWebSocketNormalClosure },
|
| - { "\x81\x7F\x00\x00\x00\x00\x80\x00\x00\x00", 10, GG_UINT64_C(0x80000000),
|
| - kWebSocketErrorMessageTooBig },
|
| - { "\x81\x7F\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 10,
|
| - GG_UINT64_C(0x7FFFFFFFFFFFFFFF), kWebSocketErrorMessageTooBig }
|
| -};
|
| + {"\x81\x00", 2, GG_UINT64_C(0), kWebSocketNormalClosure},
|
| + {"\x81\x7D", 2, GG_UINT64_C(125), kWebSocketNormalClosure},
|
| + {"\x81\x7E\x00\x7E", 4, GG_UINT64_C(126), kWebSocketNormalClosure},
|
| + {"\x81\x7E\xFF\xFF", 4, GG_UINT64_C(0xFFFF), kWebSocketNormalClosure},
|
| + {"\x81\x7F\x00\x00\x00\x00\x00\x01\x00\x00", 10, GG_UINT64_C(0x10000),
|
| + kWebSocketNormalClosure},
|
| + {"\x81\x7F\x00\x00\x00\x00\x7F\xFF\xFF\xFF", 10, GG_UINT64_C(0x7FFFFFFF),
|
| + kWebSocketNormalClosure},
|
| + {"\x81\x7F\x00\x00\x00\x00\x80\x00\x00\x00", 10, GG_UINT64_C(0x80000000),
|
| + kWebSocketErrorMessageTooBig},
|
| + {"\x81\x7F\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 10,
|
| + GG_UINT64_C(0x7FFFFFFFFFFFFFFF), kWebSocketErrorMessageTooBig}};
|
| const int kNumFrameHeaderTests = arraysize(kFrameHeaderTests);
|
|
|
| TEST(WebSocketFrameParserTest, DecodeNormalFrame) {
|
| @@ -111,21 +110,40 @@ TEST(WebSocketFrameParserTest, DecodeManyFrames) {
|
| size_t expected_payload_length;
|
| };
|
| static const Input kInputs[] = {
|
| - // Each |frame| data is split into two string literals because C++ lexers
|
| - // consume unlimited number of hex characters in a hex character escape
|
| - // (e.g. "\x05F" is not treated as { '\x5', 'F', '\0' } but as
|
| - // { '\x5F', '\0' }).
|
| - { "\x81\x05" "First", 7, "First", 5 },
|
| - { "\x81\x06" "Second", 8, "Second", 6 },
|
| - { "\x81\x05" "Third", 7, "Third", 5 },
|
| - { "\x81\x06" "Fourth", 8, "Fourth", 6 },
|
| - { "\x81\x05" "Fifth", 7, "Fifth", 5 },
|
| - { "\x81\x05" "Sixth", 7, "Sixth", 5 },
|
| - { "\x81\x07" "Seventh", 9, "Seventh", 7 },
|
| - { "\x81\x06" "Eighth", 8, "Eighth", 6 },
|
| - { "\x81\x05" "Ninth", 7, "Ninth", 5 },
|
| - { "\x81\x05" "Tenth", 7, "Tenth", 5 }
|
| - };
|
| + // Each |frame| data is split into two string literals because C++ lexers
|
| + // consume unlimited number of hex characters in a hex character escape
|
| + // (e.g. "\x05F" is not treated as { '\x5', 'F', '\0' } but as
|
| + // { '\x5F', '\0' }).
|
| + {"\x81\x05"
|
| + "First",
|
| + 7, "First", 5},
|
| + {"\x81\x06"
|
| + "Second",
|
| + 8, "Second", 6},
|
| + {"\x81\x05"
|
| + "Third",
|
| + 7, "Third", 5},
|
| + {"\x81\x06"
|
| + "Fourth",
|
| + 8, "Fourth", 6},
|
| + {"\x81\x05"
|
| + "Fifth",
|
| + 7, "Fifth", 5},
|
| + {"\x81\x05"
|
| + "Sixth",
|
| + 7, "Sixth", 5},
|
| + {"\x81\x07"
|
| + "Seventh",
|
| + 9, "Seventh", 7},
|
| + {"\x81\x06"
|
| + "Eighth",
|
| + 8, "Eighth", 6},
|
| + {"\x81\x05"
|
| + "Ninth",
|
| + 7, "Ninth", 5},
|
| + {"\x81\x05"
|
| + "Tenth",
|
| + 7, "Tenth", 5}};
|
| static const int kNumInputs = ARRAYSIZE_UNSAFE(kInputs);
|
|
|
| std::vector<char> input;
|
| @@ -423,14 +441,14 @@ TEST(WebSocketFrameParserTest, InvalidLengthEncoding) {
|
| size_t frame_header_length;
|
| };
|
| static const TestCase kTests[] = {
|
| - // For frames with two-byte extended length field, the payload length
|
| - // should be 126 (0x7E) bytes or more.
|
| - { "\x81\x7E\x00\x00", 4 },
|
| - { "\x81\x7E\x00\x7D", 4 },
|
| - // For frames with eight-byte extended length field, the payload length
|
| - // should be 0x10000 bytes or more.
|
| - { "\x81\x7F\x00\x00\x00\x00\x00\x00\x00\x00", 10 },
|
| - { "\x81\x7E\x00\x00\x00\x00\x00\x00\xFF\xFF", 10 },
|
| + // For frames with two-byte extended length field, the payload length
|
| + // should be 126 (0x7E) bytes or more.
|
| + {"\x81\x7E\x00\x00", 4},
|
| + {"\x81\x7E\x00\x7D", 4},
|
| + // For frames with eight-byte extended length field, the payload length
|
| + // should be 0x10000 bytes or more.
|
| + {"\x81\x7F\x00\x00\x00\x00\x00\x00\x00\x00", 10},
|
| + {"\x81\x7E\x00\x00\x00\x00\x00\x00\xFF\xFF", 10},
|
| };
|
| static const int kNumTests = ARRAYSIZE_UNSAFE(kTests);
|
|
|
| @@ -461,25 +479,24 @@ TEST(WebSocketFrameParserTest, FrameTypes) {
|
| WebSocketFrameHeader::OpCode opcode;
|
| };
|
| static const TestCase kTests[] = {
|
| - { "\x80\x00", 2, WebSocketFrameHeader::kOpCodeContinuation },
|
| - { "\x81\x00", 2, WebSocketFrameHeader::kOpCodeText },
|
| - { "\x82\x00", 2, WebSocketFrameHeader::kOpCodeBinary },
|
| - { "\x88\x00", 2, WebSocketFrameHeader::kOpCodeClose },
|
| - { "\x89\x00", 2, WebSocketFrameHeader::kOpCodePing },
|
| - { "\x8A\x00", 2, WebSocketFrameHeader::kOpCodePong },
|
| - // These are undefined opcodes, but the parser needs to be able to parse
|
| - // them anyway.
|
| - { "\x83\x00", 2, 0x3 },
|
| - { "\x84\x00", 2, 0x4 },
|
| - { "\x85\x00", 2, 0x5 },
|
| - { "\x86\x00", 2, 0x6 },
|
| - { "\x87\x00", 2, 0x7 },
|
| - { "\x8B\x00", 2, 0xB },
|
| - { "\x8C\x00", 2, 0xC },
|
| - { "\x8D\x00", 2, 0xD },
|
| - { "\x8E\x00", 2, 0xE },
|
| - { "\x8F\x00", 2, 0xF }
|
| - };
|
| + {"\x80\x00", 2, WebSocketFrameHeader::kOpCodeContinuation},
|
| + {"\x81\x00", 2, WebSocketFrameHeader::kOpCodeText},
|
| + {"\x82\x00", 2, WebSocketFrameHeader::kOpCodeBinary},
|
| + {"\x88\x00", 2, WebSocketFrameHeader::kOpCodeClose},
|
| + {"\x89\x00", 2, WebSocketFrameHeader::kOpCodePing},
|
| + {"\x8A\x00", 2, WebSocketFrameHeader::kOpCodePong},
|
| + // These are undefined opcodes, but the parser needs to be able to parse
|
| + // them anyway.
|
| + {"\x83\x00", 2, 0x3},
|
| + {"\x84\x00", 2, 0x4},
|
| + {"\x85\x00", 2, 0x5},
|
| + {"\x86\x00", 2, 0x6},
|
| + {"\x87\x00", 2, 0x7},
|
| + {"\x8B\x00", 2, 0xB},
|
| + {"\x8C\x00", 2, 0xC},
|
| + {"\x8D\x00", 2, 0xD},
|
| + {"\x8E\x00", 2, 0xE},
|
| + {"\x8F\x00", 2, 0xF}};
|
| static const int kNumTests = ARRAYSIZE_UNSAFE(kTests);
|
|
|
| for (int i = 0; i < kNumTests; ++i) {
|
| @@ -524,15 +541,13 @@ TEST(WebSocketFrameParserTest, FinalBitAndReservedBits) {
|
| bool reserved2;
|
| bool reserved3;
|
| };
|
| - static const TestCase kTests[] = {
|
| - { "\x81\x00", 2, true, false, false, false },
|
| - { "\x01\x00", 2, false, false, false, false },
|
| - { "\xC1\x00", 2, true, true, false, false },
|
| - { "\xA1\x00", 2, true, false, true, false },
|
| - { "\x91\x00", 2, true, false, false, true },
|
| - { "\x71\x00", 2, false, true, true, true },
|
| - { "\xF1\x00", 2, true, true, true, true }
|
| - };
|
| + static const TestCase kTests[] = {{"\x81\x00", 2, true, false, false, false},
|
| + {"\x01\x00", 2, false, false, false, false},
|
| + {"\xC1\x00", 2, true, true, false, false},
|
| + {"\xA1\x00", 2, true, false, true, false},
|
| + {"\x91\x00", 2, true, false, false, true},
|
| + {"\x71\x00", 2, false, true, true, true},
|
| + {"\xF1\x00", 2, true, true, true, true}};
|
| static const int kNumTests = ARRAYSIZE_UNSAFE(kTests);
|
|
|
| for (int i = 0; i < kNumTests; ++i) {
|
|
|