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

Unified Diff: net/websockets/websocket_frame_parser_unittest.cc

Issue 10824081: Add WebSocketError to indicate decoding failure reason (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/websockets/websocket_frame_parser_unittest.cc
diff --git a/net/websockets/websocket_frame_parser_unittest.cc b/net/websockets/websocket_frame_parser_unittest.cc
index 7bde1f5ca44bae22c958e9dac2d55e1e7790d7ab..c5324f9afe334cf3f7b9ec504f397a517d29b85b 100644
--- a/net/websockets/websocket_frame_parser_unittest.cc
+++ b/net/websockets/websocket_frame_parser_unittest.cc
@@ -30,22 +30,22 @@ struct FrameHeaderTestCase {
size_t frame_header_length;
uint64 frame_length;
bool failed;
+ net::WebSocketError error_code;
};
-// TODO(toyoshim): Provide error code and check if the reason is correct.
const FrameHeaderTestCase kFrameHeaderTests[] = {
- { "\x81\x00", 2, GG_UINT64_C(0), false },
- { "\x81\x7D", 2, GG_UINT64_C(125), false },
- { "\x81\x7E\x00\x7E", 4, GG_UINT64_C(126), false },
- { "\x81\x7E\xFF\xFF", 4, GG_UINT64_C(0xFFFF), false },
+ { "\x81\x00", 2, GG_UINT64_C(0), false, net::WS_OK },
+ { "\x81\x7D", 2, GG_UINT64_C(125), false, net::WS_OK },
+ { "\x81\x7E\x00\x7E", 4, GG_UINT64_C(126), false, net::WS_OK },
+ { "\x81\x7E\xFF\xFF", 4, GG_UINT64_C(0xFFFF), false, net::WS_OK },
{ "\x81\x7F\x00\x00\x00\x00\x00\x01\x00\x00", 10, GG_UINT64_C(0x10000),
- false },
+ false, net::WS_OK },
{ "\x81\x7F\x00\x00\x00\x00\x7F\xFF\xFF\xFF", 10, GG_UINT64_C(0x7FFFFFFF),
- false },
+ false, net::WS_OK },
{ "\x81\x7F\x00\x00\x00\x00\x80\x00\x00\x00", 10, GG_UINT64_C(0x80000000),
- true },
+ true, net::WS_ERR_MESSAGE_TOO_BIG },
{ "\x81\x7F\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 10,
- GG_UINT64_C(0x7FFFFFFFFFFFFFFF), true }
+ GG_UINT64_C(0x7FFFFFFFFFFFFFFF), true, net::WS_ERR_MESSAGE_TOO_BIG }
mmenke 2012/08/01 14:44:59 How about just moving this unnamed namespace into
Takashi Toyoshima 2012/08/02 08:11:35 Done.
};
const int kNumFrameHeaderTests = arraysize(kFrameHeaderTests);
@@ -330,6 +330,7 @@ TEST(WebSocketFrameParserTest, DecodeFramesOfVariousLengths) {
EXPECT_EQ(!kFrameHeaderTests[i].failed,
parser.Decode(&input.front(), input.size(), &frames));
EXPECT_EQ(kFrameHeaderTests[i].failed, parser.failed());
+ EXPECT_EQ(kFrameHeaderTests[i].error_code, parser.error_code());
if (kFrameHeaderTests[i].failed) {
EXPECT_EQ(0u, frames.size());
} else {
@@ -387,6 +388,10 @@ TEST(WebSocketFrameParserTest, DecodePartialHeader) {
bool failed = kFrameHeaderTests[i].failed && j == last_byte_offset;
EXPECT_EQ(!failed, parser.Decode(frame_header + j, 1, &frames));
EXPECT_EQ(failed, parser.failed());
+ if (failed)
+ EXPECT_EQ(kFrameHeaderTests[i].error_code, parser.error_code());
+ else
+ EXPECT_EQ(net::WS_OK, parser.error_code());
mmenke 2012/08/01 14:44:59 nit: Use braces here (And please add them just be
Takashi Toyoshima 2012/08/02 08:11:35 Done.
if (!kFrameHeaderTests[i].failed && j == last_byte_offset)
EXPECT_EQ(1u, frames.size());
else
@@ -445,12 +450,14 @@ TEST(WebSocketFrameParserTest, InvalidLengthEncoding) {
EXPECT_FALSE(parser.failed());
EXPECT_FALSE(parser.Decode(frame_header, frame_header_length, &frames));
EXPECT_TRUE(parser.failed());
+ EXPECT_EQ(net::WS_ERR_PROTOCOL_ERROR, parser.error_code());
EXPECT_EQ(0u, frames.size());
// Once the parser has failed, it no longer accepts any input (even if
// the input is empty).
EXPECT_FALSE(parser.Decode("", 0, &frames));
EXPECT_TRUE(parser.failed());
+ EXPECT_EQ(net::WS_ERR_PROTOCOL_ERROR, parser.error_code());
EXPECT_EQ(0u, frames.size());
}
}
« net/websockets/websocket_frame_parser.cc ('K') | « net/websockets/websocket_frame_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698