| 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 <vector> |
| 6 | 7 |
| 7 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 9 #include "net/http/http_util.h" | 10 #include "net/http/http_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 using net::HttpUtil; | 13 using net::HttpUtil; |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 class HttpUtilTest : public testing::Test {}; | 16 class HttpUtilTest : public testing::Test {}; |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 ranges[j].first_byte_position()); | 844 ranges[j].first_byte_position()); |
| 844 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, | 845 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, |
| 845 ranges[j].last_byte_position()); | 846 ranges[j].last_byte_position()); |
| 846 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, | 847 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, |
| 847 ranges[j].suffix_length()); | 848 ranges[j].suffix_length()); |
| 848 } | 849 } |
| 849 } | 850 } |
| 850 } | 851 } |
| 851 } | 852 } |
| 852 | 853 |
| 854 TEST(HttpUtilTest, PrintRanges) { |
| 855 std::vector<net::HttpByteRange> ranges; |
| 856 ranges.push_back(net::HttpByteRange::Bounded(0, 100)); |
| 857 ranges.push_back(net::HttpByteRange::RightUnbounded(200)); |
| 858 EXPECT_EQ("bytes=0-100,200-", net::HttpUtil::PrintRanges(ranges)); |
| 859 |
| 860 ranges.clear(); |
| 861 ranges.push_back(net::HttpByteRange::Bounded(0, 100)); |
| 862 ranges.push_back(net::HttpByteRange::Suffix(1000)); |
| 863 EXPECT_EQ("bytes=0-100,-1000", net::HttpUtil::PrintRanges(ranges)); |
| 864 } |
| 865 |
| 853 namespace { | 866 namespace { |
| 854 void CheckCurrentNameValuePair(HttpUtil::NameValuePairsIterator* parser, | 867 void CheckCurrentNameValuePair(HttpUtil::NameValuePairsIterator* parser, |
| 855 bool expect_valid, | 868 bool expect_valid, |
| 856 std::string expected_name, | 869 std::string expected_name, |
| 857 std::string expected_value) { | 870 std::string expected_value) { |
| 858 ASSERT_EQ(expect_valid, parser->valid()); | 871 ASSERT_EQ(expect_valid, parser->valid()); |
| 859 if (!expect_valid) { | 872 if (!expect_valid) { |
| 860 return; | 873 return; |
| 861 } | 874 } |
| 862 | 875 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 TEST(HttpUtilTest, NameValuePairsIteratorMissingEndQuote) { | 1055 TEST(HttpUtilTest, NameValuePairsIteratorMissingEndQuote) { |
| 1043 std::string data = "name='value"; | 1056 std::string data = "name='value"; |
| 1044 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); | 1057 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
| 1045 EXPECT_TRUE(parser.valid()); | 1058 EXPECT_TRUE(parser.valid()); |
| 1046 | 1059 |
| 1047 ASSERT_NO_FATAL_FAILURE( | 1060 ASSERT_NO_FATAL_FAILURE( |
| 1048 CheckNextNameValuePair(&parser, true, true, "name", "value")); | 1061 CheckNextNameValuePair(&parser, true, true, "name", "value")); |
| 1049 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( | 1062 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( |
| 1050 &parser, false, true, std::string(), std::string())); | 1063 &parser, false, true, std::string(), std::string())); |
| 1051 } | 1064 } |
| OLD | NEW |