| 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 #include <limits> |
| 7 | 7 |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "net/http/http_util.h" | 9 #include "net/http/http_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 {"", false, -1, -1, -1}, | 988 {"", false, -1, -1, -1}, |
| 989 {"megabytes 0-10/50", false, -1, -1, -1}, | 989 {"megabytes 0-10/50", false, -1, -1, -1}, |
| 990 {"0-10/50", false, -1, -1, -1}, | 990 {"0-10/50", false, -1, -1, -1}, |
| 991 {"Bytes 0-50/51", true, 0, 50, 51}, | 991 {"Bytes 0-50/51", true, 0, 50, 51}, |
| 992 {"bytes 0-50/51", true, 0, 50, 51}, | 992 {"bytes 0-50/51", true, 0, 50, 51}, |
| 993 {"bytes\t0-50/51", false, -1, -1, -1}, | 993 {"bytes\t0-50/51", false, -1, -1, -1}, |
| 994 {" bytes 0-50/51", true, 0, 50, 51}, | 994 {" bytes 0-50/51", true, 0, 50, 51}, |
| 995 {" bytes 0 - 50 \t / \t51", true, 0, 50, 51}, | 995 {" bytes 0 - 50 \t / \t51", true, 0, 50, 51}, |
| 996 {"bytes 0\t-\t50\t/\t51\t", true, 0, 50, 51}, | 996 {"bytes 0\t-\t50\t/\t51\t", true, 0, 50, 51}, |
| 997 {" \tbytes\t\t\t 0\t-\t50\t/\t51\t", true, 0, 50, 51}, | 997 {" \tbytes\t\t\t 0\t-\t50\t/\t51\t", true, 0, 50, 51}, |
| 998 {"\t bytes \t 0 - 50 / 5 1", false, 0, 50, -1}, | 998 {"\t bytes \t 0 - 50 / 5 1", false, -1, -1, -1}, |
| 999 {"\t bytes \t 0 - 5 0 / 51", false, -1, -1, -1}, | 999 {"\t bytes \t 0 - 5 0 / 51", false, -1, -1, -1}, |
| 1000 {"bytes 50-0/51", false, 50, 0, -1}, | 1000 {"bytes 50-0/51", false, -1, -1, -1}, |
| 1001 {"bytes * /*", false, -1, -1, -1}, | 1001 {"bytes * /*", false, -1, -1, -1}, |
| 1002 {"bytes * / * ", false, -1, -1, -1}, | 1002 {"bytes * / * ", false, -1, -1, -1}, |
| 1003 {"bytes 0-50/*", false, 0, 50, -1}, | 1003 {"bytes 0-50/*", false, -1, -1, -1}, |
| 1004 {"bytes 0-50 / * ", false, 0, 50, -1}, | 1004 {"bytes 0-50 / * ", false, -1, -1, -1}, |
| 1005 {"bytes 0-10000000000/10000000001", true, 0, 10000000000ll, | 1005 {"bytes 0-10000000000/10000000001", true, 0, 10000000000ll, |
| 1006 10000000001ll}, | 1006 10000000001ll}, |
| 1007 {"bytes 0-10000000000/10000000000", false, 0, 10000000000ll, | 1007 {"bytes 0-10000000000/10000000000", false, -1, -1, -1}, |
| 1008 10000000000ll}, | |
| 1009 // 64 bit wraparound. | 1008 // 64 bit wraparound. |
| 1010 {"bytes 0 - 9223372036854775807 / 100", false, 0, | 1009 {"bytes 0 - 9223372036854775807 / 100", false, -1, -1, -1}, |
| 1011 std::numeric_limits<int64_t>::max(), 100}, | |
| 1012 // 64 bit wraparound. | 1010 // 64 bit wraparound. |
| 1013 {"bytes 0 - 100 / -9223372036854775808", false, 0, 100, | 1011 {"bytes 0 - 100 / -9223372036854775808", false, -1, -1, -1}, |
| 1014 std::numeric_limits<int64_t>::min()}, | 1012 {"bytes */50", false, -1, -1, -1}, |
| 1015 {"bytes */50", false, -1, -1, 50}, | 1013 {"bytes 0-50/10", false, -1, -1, -1}, |
| 1016 {"bytes 0-50/10", false, 0, 50, 10}, | 1014 {"bytes 40-50/45", false, -1, -1, -1}, |
| 1017 {"bytes 40-50/45", false, 40, 50, 45}, | 1015 {"bytes 0-50/-10", false, -1, -1, -1}, |
| 1018 {"bytes 0-50/-10", false, 0, 50, -10}, | |
| 1019 {"bytes 0-0/1", true, 0, 0, 1}, | 1016 {"bytes 0-0/1", true, 0, 0, 1}, |
| 1020 {"bytes 0-40000000000000000000/40000000000000000001", false, -1, -1, -1}, | 1017 {"bytes 0-40000000000000000000/40000000000000000001", false, -1, -1, -1}, |
| 1021 {"bytes 1-/100", false, -1, -1, -1}, | 1018 {"bytes 1-/100", false, -1, -1, -1}, |
| 1022 {"bytes -/100", false, -1, -1, -1}, | 1019 {"bytes -/100", false, -1, -1, -1}, |
| 1023 {"bytes -1/100", false, -1, -1, -1}, | 1020 {"bytes -1/100", false, -1, -1, -1}, |
| 1024 {"bytes 0-1233/*", false, 0, 1233, -1}, | 1021 {"bytes 0-1233/*", false, -1, -1, -1}, |
| 1025 {"bytes -123 - -1/100", false, -1, -1, -1}, | 1022 {"bytes -123 - -1/100", false, -1, -1, -1}, |
| 1026 }; | 1023 }; |
| 1027 | 1024 |
| 1028 for (const auto& test : tests) { | 1025 for (const auto& test : tests) { |
| 1029 int64_t first_byte_position, last_byte_position, instance_length; | 1026 int64_t first_byte_position, last_byte_position, instance_length; |
| 1030 EXPECT_EQ(test.expected_return_value, | 1027 EXPECT_EQ(test.expected_return_value, |
| 1031 HttpUtil::ParseContentRangeHeader( | 1028 HttpUtil::ParseContentRangeHeaderFor206( |
| 1032 test.content_range_header_spec, &first_byte_position, | 1029 test.content_range_header_spec, &first_byte_position, |
| 1033 &last_byte_position, &instance_length)) | 1030 &last_byte_position, &instance_length)) |
| 1034 << test.content_range_header_spec; | 1031 << test.content_range_header_spec; |
| 1035 EXPECT_EQ(test.expected_first_byte_position, first_byte_position) | 1032 EXPECT_EQ(test.expected_first_byte_position, first_byte_position) |
| 1036 << test.content_range_header_spec; | 1033 << test.content_range_header_spec; |
| 1037 EXPECT_EQ(test.expected_last_byte_position, last_byte_position) | 1034 EXPECT_EQ(test.expected_last_byte_position, last_byte_position) |
| 1038 << test.content_range_header_spec; | 1035 << test.content_range_header_spec; |
| 1039 EXPECT_EQ(test.expected_instance_length, instance_length) | 1036 EXPECT_EQ(test.expected_instance_length, instance_length) |
| 1040 << test.content_range_header_spec; | 1037 << test.content_range_header_spec; |
| 1041 } | 1038 } |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 EXPECT_FALSE(HttpUtil::IsLWS('a')); | 1490 EXPECT_FALSE(HttpUtil::IsLWS('a')); |
| 1494 EXPECT_FALSE(HttpUtil::IsLWS('.')); | 1491 EXPECT_FALSE(HttpUtil::IsLWS('.')); |
| 1495 EXPECT_FALSE(HttpUtil::IsLWS('\n')); | 1492 EXPECT_FALSE(HttpUtil::IsLWS('\n')); |
| 1496 EXPECT_FALSE(HttpUtil::IsLWS('\r')); | 1493 EXPECT_FALSE(HttpUtil::IsLWS('\r')); |
| 1497 | 1494 |
| 1498 EXPECT_TRUE(HttpUtil::IsLWS('\t')); | 1495 EXPECT_TRUE(HttpUtil::IsLWS('\t')); |
| 1499 EXPECT_TRUE(HttpUtil::IsLWS(' ')); | 1496 EXPECT_TRUE(HttpUtil::IsLWS(' ')); |
| 1500 } | 1497 } |
| 1501 | 1498 |
| 1502 } // namespace net | 1499 } // namespace net |
| OLD | NEW |