OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "net/http/http_util.h" | 8 #include "net/http/http_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 EXPECT_EQ(std::string("foo"), it.name()); | 86 EXPECT_EQ(std::string("foo"), it.name()); |
87 EXPECT_EQ(std::string("1"), it.values()); | 87 EXPECT_EQ(std::string("1"), it.values()); |
88 | 88 |
89 ASSERT_TRUE(it.GetNext()); | 89 ASSERT_TRUE(it.GetNext()); |
90 EXPECT_EQ(std::string("bar"), it.name()); | 90 EXPECT_EQ(std::string("bar"), it.name()); |
91 EXPECT_EQ(std::string("4"), it.values()); | 91 EXPECT_EQ(std::string("4"), it.values()); |
92 | 92 |
93 EXPECT_FALSE(it.GetNext()); | 93 EXPECT_FALSE(it.GetNext()); |
94 } | 94 } |
95 | 95 |
| 96 TEST(HttpUtilTest, HeadersIterator_AdvanceTo) { |
| 97 std::string headers = "foo: 1\r\n: 2\r\n3\r\nbar: 4"; |
| 98 |
| 99 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
| 100 EXPECT_TRUE(it.AdvanceTo("foo")); |
| 101 EXPECT_EQ("foo", it.name()); |
| 102 EXPECT_TRUE(it.AdvanceTo("bar")); |
| 103 EXPECT_EQ("bar", it.name()); |
| 104 EXPECT_FALSE(it.AdvanceTo("blat")); |
| 105 EXPECT_FALSE(it.GetNext()); // should be at end of headers |
| 106 } |
| 107 |
96 TEST(HttpUtilTest, ValuesIterator) { | 108 TEST(HttpUtilTest, ValuesIterator) { |
97 std::string values = " must-revalidate, no-cache=\"foo, bar\"\t, private "; | 109 std::string values = " must-revalidate, no-cache=\"foo, bar\"\t, private "; |
98 | 110 |
99 HttpUtil::ValuesIterator it(values.begin(), values.end(), ','); | 111 HttpUtil::ValuesIterator it(values.begin(), values.end(), ','); |
100 | 112 |
101 ASSERT_TRUE(it.GetNext()); | 113 ASSERT_TRUE(it.GetNext()); |
102 EXPECT_EQ(std::string("must-revalidate"), it.value()); | 114 EXPECT_EQ(std::string("must-revalidate"), it.value()); |
103 | 115 |
104 ASSERT_TRUE(it.GetNext()); | 116 ASSERT_TRUE(it.GetNext()); |
105 EXPECT_EQ(std::string("no-cache=\"foo, bar\""), it.value()); | 117 EXPECT_EQ(std::string("no-cache=\"foo, bar\""), it.value()); |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 EXPECT_EQ(tests[i].expected_ranges[j].expected_first_byte_position, | 651 EXPECT_EQ(tests[i].expected_ranges[j].expected_first_byte_position, |
640 ranges[j].first_byte_position()); | 652 ranges[j].first_byte_position()); |
641 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, | 653 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, |
642 ranges[j].last_byte_position()); | 654 ranges[j].last_byte_position()); |
643 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, | 655 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, |
644 ranges[j].suffix_length()); | 656 ranges[j].suffix_length()); |
645 } | 657 } |
646 } | 658 } |
647 } | 659 } |
648 } | 660 } |
OLD | NEW |