This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "net/websockets/websocket_extension_parser.h"
#include <string>
#include "net/websockets/websocket_extension.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace {
TEST(WebSocketExtensionParserTest, ParseEmpty) {
WebSocketExtensionParser parser;
parser.Parse("", 0);
EXPECT_TRUE(parser.has_error());
}
TEST(WebSocketExtensionParserTest, ParseSimple) {
WebSocketExtensionParser parser;
WebSocketExtension expected("foo");
parser.Parse("foo");
ASSERT_FALSE(parser.has_error());
EXPECT_TRUE(expected.Equals(parser.extension()));
}
TEST(WebSocketExtensionParserTest, ParseOneExtensionWithOneParamWithoutValue) {
WebSocketExtensionParser parser;
WebSocketExtension expected("foo");
expected.Add(WebSocketExtension::Parameter("bar"));
parser.Parse("\tfoo ; bar");
ASSERT_FALSE(parser.has_error());
EXPECT_TRUE(expected.Equals(parser.extension()));
}
TEST(WebSocketExtensionParserTest, ParseOneExtensionWithOneParamWithValue) {
WebSocketExtensionParser parser;
WebSocketExtension expected("foo");
expected.Add(WebSocketExtension::Parameter("bar", "baz"));
parser.Parse("foo ; bar= baz\t");
ASSERT_FALSE(parser.has_error());
EXPECT_TRUE(expected.Equals(parser.extension()));
}
TEST(WebSocketExtensionParserTest, ParseOneExtensionWithParams) {
WebSocketExtensionParser parser;
WebSocketExtension expected("foo");
expected.Add(WebSocketExtension::Parameter("bar", "baz"));
expected.Add(WebSocketExtension::Parameter("hoge", "fuga"));
parser.Parse("foo ; bar= baz;\t \thoge\t\t=fuga");
ASSERT_FALSE(parser.has_error());
EXPECT_TRUE(expected.Equals(parser.extension()));
}
TEST(WebSocketExtensionParserTest, InvalidPatterns) {
const char* patterns[] = {
"fo\ao",
"fo\x01o",
"fo<o",
"foo/",
";bar",
"foo bar",
"foo;",
"foo; b\ar",
"foo; b\x7fr",
"foo; b[r",
"foo; ba:",
"foo; =baz",
"foo; bar=",
"foo; =",
"foo; bar=b\x02z",
"foo; bar=b@z",
"foo; bar=b\\z",
"foo; bar=b?z",
"\"foo\"",
"foo; \"bar\"",
"foo; bar=\"\a2\"",
"foo; bar=\"b@z\"",
"foo; bar=\"b\\\\z\"",
"foo; bar=\"\"",
"foo; bar=\"baz",
"foo; bar=\"baz \"",
"foo; bar baz",
"foo; bar - baz",
"foo; bar=\r\nbaz",
"foo; bar=\r\n baz",
"foo, bar"
};
for (size_t i = 0; i < arraysize(patterns); ++i) {
WebSocketExtensionParser parser;
parser.Parse(patterns[i]);
EXPECT_TRUE(parser.has_error());
}
}
TEST(WebSocketExtensionParserTest, QuotedParameterValue) {
WebSocketExtensionParser parser;
WebSocketExtension expected("foo");
expected.Add(WebSocketExtension::Parameter("bar", "baz"));
parser.Parse("foo; bar = \"ba\\z\" ");
ASSERT_FALSE(parser.has_error());
EXPECT_TRUE(expected.Equals(parser.extension()));
}
}
}