OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/base/url_util.h" | 5 #include "net/base/url_util.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 TEST(UrlUtilTest, GetValueForKeyInQueryInvalidURL) { | 103 TEST(UrlUtilTest, GetValueForKeyInQueryInvalidURL) { |
104 GURL url("http://%01/?test"); | 104 GURL url("http://%01/?test"); |
105 std::string value; | 105 std::string value; |
106 | 106 |
107 // Always false when parsing an invalid URL. | 107 // Always false when parsing an invalid URL. |
108 EXPECT_FALSE(GetValueForKeyInQuery(url, "test", &value)); | 108 EXPECT_FALSE(GetValueForKeyInQuery(url, "test", &value)); |
109 } | 109 } |
110 | 110 |
| 111 TEST(UrlUtilTest, ParseQuery) { |
| 112 const GURL url("http://example.com/path?name=value&boolParam&" |
| 113 "url=http://test.com/q?n1%3Dv1%26n2&" |
| 114 "multikey=value1&multikey=value2&multikey"); |
| 115 QueryIterator it(url); |
| 116 |
| 117 ASSERT_FALSE(it.IsAtEnd()); |
| 118 EXPECT_EQ("name", it.GetKey()); |
| 119 EXPECT_EQ("value", it.GetValue()); |
| 120 EXPECT_EQ("value", it.GetUnescapedValue()); |
| 121 it.Advance(); |
| 122 |
| 123 ASSERT_FALSE(it.IsAtEnd()); |
| 124 EXPECT_EQ("boolParam", it.GetKey()); |
| 125 EXPECT_EQ("", it.GetValue()); |
| 126 EXPECT_EQ("", it.GetUnescapedValue()); |
| 127 it.Advance(); |
| 128 |
| 129 ASSERT_FALSE(it.IsAtEnd()); |
| 130 EXPECT_EQ("url", it.GetKey()); |
| 131 EXPECT_EQ("http://test.com/q?n1%3Dv1%26n2", it.GetValue()); |
| 132 EXPECT_EQ("http://test.com/q?n1=v1&n2", it.GetUnescapedValue()); |
| 133 it.Advance(); |
| 134 |
| 135 ASSERT_FALSE(it.IsAtEnd()); |
| 136 EXPECT_EQ("multikey", it.GetKey()); |
| 137 EXPECT_EQ("value1", it.GetValue()); |
| 138 EXPECT_EQ("value1", it.GetUnescapedValue()); |
| 139 it.Advance(); |
| 140 |
| 141 ASSERT_FALSE(it.IsAtEnd()); |
| 142 EXPECT_EQ("multikey", it.GetKey()); |
| 143 EXPECT_EQ("value2", it.GetValue()); |
| 144 EXPECT_EQ("value2", it.GetUnescapedValue()); |
| 145 it.Advance(); |
| 146 |
| 147 ASSERT_FALSE(it.IsAtEnd()); |
| 148 EXPECT_EQ("multikey", it.GetKey()); |
| 149 EXPECT_EQ("", it.GetValue()); |
| 150 EXPECT_EQ("", it.GetUnescapedValue()); |
| 151 it.Advance(); |
| 152 |
| 153 EXPECT_TRUE(it.IsAtEnd()); |
| 154 } |
| 155 |
| 156 TEST(UrlUtilTest, ParseQueryInvalidURL) { |
| 157 const GURL url("http://%01/?test"); |
| 158 QueryIterator it(url); |
| 159 EXPECT_TRUE(it.IsAtEnd()); |
| 160 } |
| 161 |
111 } // namespace | 162 } // namespace |
112 } // namespace net | 163 } // namespace net |
OLD | NEW |