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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 99 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
100 EXPECT_TRUE(it.AdvanceTo("foo")); | 100 EXPECT_TRUE(it.AdvanceTo("foo")); |
101 EXPECT_EQ("foo", it.name()); | 101 EXPECT_EQ("foo", it.name()); |
102 EXPECT_TRUE(it.AdvanceTo("bar")); | 102 EXPECT_TRUE(it.AdvanceTo("bar")); |
103 EXPECT_EQ("bar", it.name()); | 103 EXPECT_EQ("bar", it.name()); |
104 EXPECT_FALSE(it.AdvanceTo("blat")); | 104 EXPECT_FALSE(it.AdvanceTo("blat")); |
105 EXPECT_FALSE(it.GetNext()); // should be at end of headers | 105 EXPECT_FALSE(it.GetNext()); // should be at end of headers |
106 } | 106 } |
107 | 107 |
| 108 TEST(HttpUtilTest, HeadersIterator_Reset) { |
| 109 std::string headers = "foo: 1\r\n: 2\r\n3\r\nbar: 4"; |
| 110 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
| 111 // Search past "foo". |
| 112 EXPECT_TRUE(it.AdvanceTo("bar")); |
| 113 // Now try advancing to "foo". This time it should fail since the iterator |
| 114 // position is past it. |
| 115 EXPECT_FALSE(it.AdvanceTo("foo")); |
| 116 it.Reset(); |
| 117 // Now that we reset the iterator position, we should find 'foo' |
| 118 EXPECT_TRUE(it.AdvanceTo("foo")); |
| 119 } |
| 120 |
108 TEST(HttpUtilTest, ValuesIterator) { | 121 TEST(HttpUtilTest, ValuesIterator) { |
109 std::string values = " must-revalidate, no-cache=\"foo, bar\"\t, private "; | 122 std::string values = " must-revalidate, no-cache=\"foo, bar\"\t, private "; |
110 | 123 |
111 HttpUtil::ValuesIterator it(values.begin(), values.end(), ','); | 124 HttpUtil::ValuesIterator it(values.begin(), values.end(), ','); |
112 | 125 |
113 ASSERT_TRUE(it.GetNext()); | 126 ASSERT_TRUE(it.GetNext()); |
114 EXPECT_EQ(std::string("must-revalidate"), it.value()); | 127 EXPECT_EQ(std::string("must-revalidate"), it.value()); |
115 | 128 |
116 ASSERT_TRUE(it.GetNext()); | 129 ASSERT_TRUE(it.GetNext()); |
117 EXPECT_EQ(std::string("no-cache=\"foo, bar\""), it.value()); | 130 EXPECT_EQ(std::string("no-cache=\"foo, bar\""), it.value()); |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 EXPECT_EQ(tests[i].expected_ranges[j].expected_first_byte_position, | 664 EXPECT_EQ(tests[i].expected_ranges[j].expected_first_byte_position, |
652 ranges[j].first_byte_position()); | 665 ranges[j].first_byte_position()); |
653 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, | 666 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, |
654 ranges[j].last_byte_position()); | 667 ranges[j].last_byte_position()); |
655 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, | 668 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, |
656 ranges[j].suffix_length()); | 669 ranges[j].suffix_length()); |
657 } | 670 } |
658 } | 671 } |
659 } | 672 } |
660 } | 673 } |
OLD | NEW |