Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / http / http_status_line_validator_unittest.cc
blob43a8bf2360f66e3708b65b68b3f3f0c263a09374
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/http/http_status_line_validator.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace net {
10 namespace {
12 using Status = HttpStatusLineValidator::StatusLineStatus;
14 struct ValidatorTestData {
15 const char* name;
16 const char* status_line;
17 const Status expected_status;
20 class ValidatorTest : public ::testing::Test,
21 public ::testing::WithParamInterface<ValidatorTestData> {
22 public:
23 ValidatorTest() {}
24 ~ValidatorTest() override {}
27 std::string TestName(testing::TestParamInfo<ValidatorTestData> info) {
28 return info.param.name;
31 TEST_P(ValidatorTest, Validate) {
32 const ValidatorTestData test = GetParam();
34 EXPECT_EQ(HttpStatusLineValidator::ValidateStatusLine(test.status_line),
35 test.expected_status);
38 const ValidatorTestData validator_tests[] = {
39 {"Http10_Ok", "HTTP/1.0 200 OK", Status::STATUS_LINE_OK},
40 {"Http11_Ok", "HTTP/1.1 200 OK", Status::STATUS_LINE_OK},
41 {"Empty", "", Status::STATUS_LINE_EMPTY},
42 {"NotHttp", "xyzzy", Status::STATUS_LINE_NOT_HTTP},
43 {"CaseMismatch", "HtTp/1.1 200 OK", Status::STATUS_LINE_HTTP_CASE_MISMATCH},
44 {"NoVersion", "HTTP 200 OK", Status::STATUS_LINE_HTTP_NO_VERSION},
45 {"InvalidVersion_0", "HTTP/a.b 200 OK",
46 Status::STATUS_LINE_INVALID_VERSION},
47 {"InvalidVersion_1", "HTTP/1.a 200 OK",
48 Status::STATUS_LINE_INVALID_VERSION},
49 {"InvalidVersion_2", "HTTP/a.1 200 OK",
50 Status::STATUS_LINE_INVALID_VERSION},
51 {"InvalidVersion_3", "HTTP/1 200 OK", Status::STATUS_LINE_INVALID_VERSION},
52 {"InvalidVersion_4", "HTTP/1. 200 OK", Status::STATUS_LINE_INVALID_VERSION},
53 {"MultiDigit_0", "HTTP/10.0 200 OK",
54 Status::STATUS_LINE_MULTI_DIGIT_VERSION},
55 {"MultiDigit_1", "HTTP/1.00 200 OK",
56 Status::STATUS_LINE_MULTI_DIGIT_VERSION},
57 {"UnknownVersion_0", "HTTP/1.2 200 OK",
58 Status::STATUS_LINE_UNKNOWN_VERSION},
59 {"UnknownVersion_1", "HTTP/2.0 200 OK",
60 Status::STATUS_LINE_UNKNOWN_VERSION},
61 {"Explicit09", "HTTP/0.9 200 OK", Status::STATUS_LINE_EXPLICIT_0_9},
62 {"MissingStatusCode", "HTTP/1.0", Status::STATUS_LINE_MISSING_STATUS_CODE},
63 {"InvalidStatusCode_0", "HTTP/1.0 abc OK",
64 Status::STATUS_LINE_INVALID_STATUS_CODE},
65 {"InvalidStatusCode_1", "HTTP/1.0 17 OK",
66 Status::STATUS_LINE_INVALID_STATUS_CODE},
67 {"StatusCodeTrailing", "HTTP/1.0 200a OK",
68 Status::STATUS_LINE_STATUS_CODE_TRAILING},
69 {"MissingReasonPhrase", "HTTP/1.0 200",
70 Status::STATUS_LINE_MISSING_REASON_PHRASE},
71 {"EmptyReasonPhrase_Ok", "HTTP/1.0 200 ", Status::STATUS_LINE_OK},
72 {"ReasonDisallowedCharacter", "HTTP/1.0 200 OK\x01",
73 Status::STATUS_LINE_REASON_DISALLOWED_CHARACTER},
74 {"ExcessWhitespace", "HTTP/1.0 200 OK",
75 Status::STATUS_LINE_EXCESS_WHITESPACE},
76 {"ReasonWhitespace_Ok", "HTTP/1.0 200 OK", Status::STATUS_LINE_OK},
77 {"ReservedStatusCode_0", "HTTP/1.0 099 OK",
78 Status::STATUS_LINE_RESERVED_STATUS_CODE},
79 {"ReservedStatusCode_1", "HTTP/1.0 600 OK",
80 Status::STATUS_LINE_RESERVED_STATUS_CODE}};
82 INSTANTIATE_TEST_CASE_P(HttpStatusLineValidator,
83 ValidatorTest,
84 testing::ValuesIn(validator_tests),
85 TestName);
87 } // namespace
88 } // namespace net