| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <limits> |
| 6 | 7 |
| 7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 8 #include "net/http/http_util.h" | 9 #include "net/http/http_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 namespace net { | 12 namespace net { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 class HttpUtilTest : public testing::Test {}; | 15 class HttpUtilTest : public testing::Test {}; |
| 15 } | 16 } |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 ranges[j].first_byte_position()); | 957 ranges[j].first_byte_position()); |
| 957 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, | 958 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, |
| 958 ranges[j].last_byte_position()); | 959 ranges[j].last_byte_position()); |
| 959 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, | 960 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, |
| 960 ranges[j].suffix_length()); | 961 ranges[j].suffix_length()); |
| 961 } | 962 } |
| 962 } | 963 } |
| 963 } | 964 } |
| 964 } | 965 } |
| 965 | 966 |
| 967 TEST(HttpUtilTest, ParseContentRangeHeader) { |
| 968 const struct { |
| 969 const char* const content_range_header_spec; |
| 970 bool expected_return_value; |
| 971 int64_t expected_first_byte_position; |
| 972 int64_t expected_last_byte_position; |
| 973 int64_t expected_instance_length; |
| 974 } tests[] = { |
| 975 {"", false, -1, -1, -1}, |
| 976 {"megabytes 0-10/50", false, -1, -1, -1}, |
| 977 {"0-10/50", false, -1, -1, -1}, |
| 978 {"Bytes 0-50/51", true, 0, 50, 51}, |
| 979 {"bytes 0-50/51", true, 0, 50, 51}, |
| 980 {"bytes\t0-50/51", false, -1, -1, -1}, |
| 981 {" bytes 0-50/51", true, 0, 50, 51}, |
| 982 {" bytes 0 - 50 \t / \t51", true, 0, 50, 51}, |
| 983 {"bytes 0\t-\t50\t/\t51\t", true, 0, 50, 51}, |
| 984 {" \tbytes\t\t\t 0\t-\t50\t/\t51\t", true, 0, 50, 51}, |
| 985 {"\t bytes \t 0 - 50 / 5 1", false, 0, 50, -1}, |
| 986 {"\t bytes \t 0 - 5 0 / 51", false, -1, -1, -1}, |
| 987 {"bytes 50-0/51", false, 50, 0, -1}, |
| 988 {"bytes * /*", false, -1, -1, -1}, |
| 989 {"bytes * / * ", false, -1, -1, -1}, |
| 990 {"bytes 0-50/*", false, 0, 50, -1}, |
| 991 {"bytes 0-50 / * ", false, 0, 50, -1}, |
| 992 {"bytes 0-10000000000/10000000001", true, 0, 10000000000ll, |
| 993 10000000001ll}, |
| 994 {"bytes 0-10000000000/10000000000", false, 0, 10000000000ll, |
| 995 10000000000ll}, |
| 996 // 64 bit wraparound. |
| 997 {"bytes 0 - 9223372036854775807 / 100", false, 0, |
| 998 std::numeric_limits<int64_t>::max(), 100}, |
| 999 // 64 bit wraparound. |
| 1000 {"bytes 0 - 100 / -9223372036854775808", false, 0, 100, |
| 1001 std::numeric_limits<int64_t>::min()}, |
| 1002 {"bytes */50", false, -1, -1, 50}, |
| 1003 {"bytes 0-50/10", false, 0, 50, 10}, |
| 1004 {"bytes 40-50/45", false, 40, 50, 45}, |
| 1005 {"bytes 0-50/-10", false, 0, 50, -10}, |
| 1006 {"bytes 0-0/1", true, 0, 0, 1}, |
| 1007 {"bytes 0-40000000000000000000/40000000000000000001", false, -1, -1, -1}, |
| 1008 {"bytes 1-/100", false, -1, -1, -1}, |
| 1009 {"bytes -/100", false, -1, -1, -1}, |
| 1010 {"bytes -1/100", false, -1, -1, -1}, |
| 1011 {"bytes 0-1233/*", false, 0, 1233, -1}, |
| 1012 {"bytes -123 - -1/100", false, -1, -1, -1}, |
| 1013 }; |
| 1014 |
| 1015 for (const auto& test : tests) { |
| 1016 int64_t first_byte_position, last_byte_position, instance_length; |
| 1017 EXPECT_EQ(test.expected_return_value, |
| 1018 HttpUtil::ParseContentRangeHeader( |
| 1019 test.content_range_header_spec, &first_byte_position, |
| 1020 &last_byte_position, &instance_length)) |
| 1021 << test.content_range_header_spec; |
| 1022 EXPECT_EQ(test.expected_first_byte_position, first_byte_position) |
| 1023 << test.content_range_header_spec; |
| 1024 EXPECT_EQ(test.expected_last_byte_position, last_byte_position) |
| 1025 << test.content_range_header_spec; |
| 1026 EXPECT_EQ(test.expected_instance_length, instance_length) |
| 1027 << test.content_range_header_spec; |
| 1028 } |
| 1029 } |
| 1030 |
| 966 TEST(HttpUtilTest, ParseRetryAfterHeader) { | 1031 TEST(HttpUtilTest, ParseRetryAfterHeader) { |
| 967 base::Time::Exploded now_exploded = {2014, 11, 4, 5, 22, 39, 30, 0}; | 1032 base::Time::Exploded now_exploded = {2014, 11, 4, 5, 22, 39, 30, 0}; |
| 968 base::Time now = base::Time::FromUTCExploded(now_exploded); | 1033 base::Time now = base::Time::FromUTCExploded(now_exploded); |
| 969 | 1034 |
| 970 base::Time::Exploded later_exploded = {2015, 1, 5, 1, 12, 34, 56, 0}; | 1035 base::Time::Exploded later_exploded = {2015, 1, 5, 1, 12, 34, 56, 0}; |
| 971 base::Time later = base::Time::FromUTCExploded(later_exploded); | 1036 base::Time later = base::Time::FromUTCExploded(later_exploded); |
| 972 | 1037 |
| 973 const struct { | 1038 const struct { |
| 974 const char* retry_after_string; | 1039 const char* retry_after_string; |
| 975 bool expected_return_value; | 1040 bool expected_return_value; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 EXPECT_FALSE(HttpUtil::IsToken("hello, world")); | 1467 EXPECT_FALSE(HttpUtil::IsToken("hello, world")); |
| 1403 EXPECT_FALSE(HttpUtil::IsToken(" ")); | 1468 EXPECT_FALSE(HttpUtil::IsToken(" ")); |
| 1404 EXPECT_FALSE(HttpUtil::IsToken(base::StringPiece("\0", 1))); | 1469 EXPECT_FALSE(HttpUtil::IsToken(base::StringPiece("\0", 1))); |
| 1405 EXPECT_FALSE(HttpUtil::IsToken("\x01")); | 1470 EXPECT_FALSE(HttpUtil::IsToken("\x01")); |
| 1406 EXPECT_FALSE(HttpUtil::IsToken("\x7F")); | 1471 EXPECT_FALSE(HttpUtil::IsToken("\x7F")); |
| 1407 EXPECT_FALSE(HttpUtil::IsToken("\x80")); | 1472 EXPECT_FALSE(HttpUtil::IsToken("\x80")); |
| 1408 EXPECT_FALSE(HttpUtil::IsToken("\xff")); | 1473 EXPECT_FALSE(HttpUtil::IsToken("\xff")); |
| 1409 } | 1474 } |
| 1410 | 1475 |
| 1411 } // namespace net | 1476 } // namespace net |
| OLD | NEW |