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 <errno.h> | 5 #include <errno.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "url/third_party/mozilla/url_parse.h" | 10 #include "url/third_party/mozilla/url_parse.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // however, that the output range includes everything but the colon. | 233 // however, that the output range includes everything but the colon. |
234 ComponentCase scheme_cases[] = { | 234 ComponentCase scheme_cases[] = { |
235 {"http", "http:", Component(0, 4), true}, | 235 {"http", "http:", Component(0, 4), true}, |
236 {"HTTP", "http:", Component(0, 4), true}, | 236 {"HTTP", "http:", Component(0, 4), true}, |
237 {" HTTP ", "%20http%20:", Component(0, 10), false}, | 237 {" HTTP ", "%20http%20:", Component(0, 10), false}, |
238 {"htt: ", "htt%3A%20:", Component(0, 9), false}, | 238 {"htt: ", "htt%3A%20:", Component(0, 9), false}, |
239 {"\xe4\xbd\xa0\xe5\xa5\xbdhttp", "%E4%BD%A0%E5%A5%BDhttp:", Component(0, 22)
, false}, | 239 {"\xe4\xbd\xa0\xe5\xa5\xbdhttp", "%E4%BD%A0%E5%A5%BDhttp:", Component(0, 22)
, false}, |
240 // Don't re-escape something already escaped. Note that it will | 240 // Don't re-escape something already escaped. Note that it will |
241 // "canonicalize" the 'A' to 'a', but that's OK. | 241 // "canonicalize" the 'A' to 'a', but that's OK. |
242 {"ht%3Atp", "ht%3atp:", Component(0, 7), false}, | 242 {"ht%3Atp", "ht%3atp:", Component(0, 7), false}, |
| 243 {"", ":", Component(0, 0), false}, |
243 }; | 244 }; |
244 | 245 |
245 std::string out_str; | 246 std::string out_str; |
246 | 247 |
247 for (size_t i = 0; i < arraysize(scheme_cases); i++) { | 248 for (size_t i = 0; i < arraysize(scheme_cases); i++) { |
248 int url_len = static_cast<int>(strlen(scheme_cases[i].input)); | 249 int url_len = static_cast<int>(strlen(scheme_cases[i].input)); |
249 Component in_comp(0, url_len); | 250 Component in_comp(0, url_len); |
250 Component out_comp; | 251 Component out_comp; |
251 | 252 |
252 out_str.clear(); | 253 out_str.clear(); |
(...skipping 22 matching lines...) Expand all Loading... |
275 EXPECT_EQ(scheme_cases[i].expected_component.begin, out_comp.begin); | 276 EXPECT_EQ(scheme_cases[i].expected_component.begin, out_comp.begin); |
276 EXPECT_EQ(scheme_cases[i].expected_component.len, out_comp.len); | 277 EXPECT_EQ(scheme_cases[i].expected_component.len, out_comp.len); |
277 } | 278 } |
278 | 279 |
279 // Test the case where the scheme is declared nonexistent, it should be | 280 // Test the case where the scheme is declared nonexistent, it should be |
280 // converted into an empty scheme. | 281 // converted into an empty scheme. |
281 Component out_comp; | 282 Component out_comp; |
282 out_str.clear(); | 283 out_str.clear(); |
283 StdStringCanonOutput output(&out_str); | 284 StdStringCanonOutput output(&out_str); |
284 | 285 |
285 EXPECT_TRUE(CanonicalizeScheme("", Component(0, -1), &output, &out_comp)); | 286 EXPECT_FALSE(CanonicalizeScheme("", Component(0, -1), &output, &out_comp)); |
286 output.Complete(); | 287 output.Complete(); |
287 | 288 |
288 EXPECT_EQ(std::string(":"), out_str); | 289 EXPECT_EQ(std::string(":"), out_str); |
289 EXPECT_EQ(0, out_comp.begin); | 290 EXPECT_EQ(0, out_comp.begin); |
290 EXPECT_EQ(0, out_comp.len); | 291 EXPECT_EQ(0, out_comp.len); |
291 } | 292 } |
292 | 293 |
293 TEST(URLCanonTest, Host) { | 294 TEST(URLCanonTest, Host) { |
294 IPAddressCase host_cases[] = { | 295 IPAddressCase host_cases[] = { |
295 // Basic canonicalization, uppercase should be converted to lowercase. | 296 // Basic canonicalization, uppercase should be converted to lowercase. |
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 // parts are included or excluded properly, and have the correct separators. | 1297 // parts are included or excluded properly, and have the correct separators. |
1297 struct URLCase { | 1298 struct URLCase { |
1298 const char* input; | 1299 const char* input; |
1299 const char* expected; | 1300 const char* expected; |
1300 bool expected_success; | 1301 bool expected_success; |
1301 } cases[] = { | 1302 } cases[] = { |
1302 {"http://www.google.com/foo?bar=baz#", "http://www.google.com/foo?bar=baz#",
true}, | 1303 {"http://www.google.com/foo?bar=baz#", "http://www.google.com/foo?bar=baz#",
true}, |
1303 {"http://[www.google.com]/", "http://[www.google.com]/", false}, | 1304 {"http://[www.google.com]/", "http://[www.google.com]/", false}, |
1304 {"ht\ttp:@www.google.com:80/;p?#", "ht%09tp://www.google.com:80/;p?#", false
}, | 1305 {"ht\ttp:@www.google.com:80/;p?#", "ht%09tp://www.google.com:80/;p?#", false
}, |
1305 {"http:////////user:@google.com:99?foo", "http://user@google.com:99/?foo", t
rue}, | 1306 {"http:////////user:@google.com:99?foo", "http://user@google.com:99/?foo", t
rue}, |
1306 {"www.google.com", ":www.google.com/", true}, | 1307 {"www.google.com", ":www.google.com/", false}, |
1307 {"http://192.0x00A80001", "http://192.168.0.1/", true}, | 1308 {"http://192.0x00A80001", "http://192.168.0.1/", true}, |
1308 {"http://www/foo%2Ehtml", "http://www/foo.html", true}, | 1309 {"http://www/foo%2Ehtml", "http://www/foo.html", true}, |
1309 {"http://user:pass@/", "http://user:pass@/", false}, | 1310 {"http://user:pass@/", "http://user:pass@/", false}, |
1310 {"http://%25DOMAIN:foobar@foodomain.com/", "http://%25DOMAIN:foobar@foodomai
n.com/", true}, | 1311 {"http://%25DOMAIN:foobar@foodomain.com/", "http://%25DOMAIN:foobar@foodomai
n.com/", true}, |
1311 | 1312 |
1312 // Backslashes should get converted to forward slashes. | 1313 // Backslashes should get converted to forward slashes. |
1313 {"http:\\\\www.google.com\\foo", "http://www.google.com/foo", true}, | 1314 {"http:\\\\www.google.com\\foo", "http://www.google.com/foo", true}, |
1314 | 1315 |
1315 // Busted refs shouldn't make the whole thing fail. | 1316 // Busted refs shouldn't make the whole thing fail. |
1316 {"http://www.google.com/asdf#\xc2", "http://www.google.com/asdf#\xef\xbf\xbd
", true}, | 1317 {"http://www.google.com/asdf#\xc2", "http://www.google.com/asdf#\xef\xbf\xbd
", true}, |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 } | 1752 } |
1752 | 1753 |
1753 TEST(URLCanonTest, CanonicalizePathURL) { | 1754 TEST(URLCanonTest, CanonicalizePathURL) { |
1754 // Path URLs should get canonicalized schemes but nothing else. | 1755 // Path URLs should get canonicalized schemes but nothing else. |
1755 struct PathCase { | 1756 struct PathCase { |
1756 const char* input; | 1757 const char* input; |
1757 const char* expected; | 1758 const char* expected; |
1758 } path_cases[] = { | 1759 } path_cases[] = { |
1759 {"javascript:", "javascript:"}, | 1760 {"javascript:", "javascript:"}, |
1760 {"JavaScript:Foo", "javascript:Foo"}, | 1761 {"JavaScript:Foo", "javascript:Foo"}, |
1761 {":\":This /is interesting;?#", ":\":This /is interesting;?#"}, | 1762 {"Foo:\":This /is interesting;?#", "foo:\":This /is interesting;?#"}, |
1762 }; | 1763 }; |
1763 | 1764 |
1764 for (size_t i = 0; i < arraysize(path_cases); i++) { | 1765 for (size_t i = 0; i < arraysize(path_cases); i++) { |
1765 int url_len = static_cast<int>(strlen(path_cases[i].input)); | 1766 int url_len = static_cast<int>(strlen(path_cases[i].input)); |
1766 Parsed parsed; | 1767 Parsed parsed; |
1767 ParsePathURL(path_cases[i].input, url_len, true, &parsed); | 1768 ParsePathURL(path_cases[i].input, url_len, true, &parsed); |
1768 | 1769 |
1769 Parsed out_parsed; | 1770 Parsed out_parsed; |
1770 std::string out_str; | 1771 std::string out_str; |
1771 StdStringCanonOutput output(&out_str); | 1772 StdStringCanonOutput output(&out_str); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2166 repl_output.Complete(); | 2167 repl_output.Complete(); |
2167 | 2168 |
2168 // Generate the expected string and check. | 2169 // Generate the expected string and check. |
2169 std::string expected("file:///foo?"); | 2170 std::string expected("file:///foo?"); |
2170 for (size_t i = 0; i < new_query.length(); i++) | 2171 for (size_t i = 0; i < new_query.length(); i++) |
2171 expected.push_back('a'); | 2172 expected.push_back('a'); |
2172 EXPECT_TRUE(expected == repl_str); | 2173 EXPECT_TRUE(expected == repl_str); |
2173 } | 2174 } |
2174 | 2175 |
2175 } // namespace url | 2176 } // namespace url |
OLD | NEW |