| 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 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/icu/source/common/unicode/ucnv.h" | 8 #include "third_party/icu/source/common/unicode/ucnv.h" |
| 9 #include "url/url_canon.h" | 9 #include "url/url_canon.h" |
| 10 #include "url/url_canon_icu.h" | 10 #include "url/url_canon_icu.h" |
| (...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 // Replace one or the other | 1602 // Replace one or the other |
| 1603 {"data:foo", "javascript", NULL, NULL, NULL, NULL, NULL, NULL, NULL, "javasc
ript:foo"}, | 1603 {"data:foo", "javascript", NULL, NULL, NULL, NULL, NULL, NULL, NULL, "javasc
ript:foo"}, |
| 1604 {"data:foo", NULL, NULL, NULL, NULL, NULL, "bar", NULL, NULL, "data:bar"}, | 1604 {"data:foo", NULL, NULL, NULL, NULL, NULL, "bar", NULL, NULL, "data:bar"}, |
| 1605 {"data:foo", NULL, NULL, NULL, NULL, NULL, kDeleteComp, NULL, NULL, "data:"}
, | 1605 {"data:foo", NULL, NULL, NULL, NULL, NULL, kDeleteComp, NULL, NULL, "data:"}
, |
| 1606 }; | 1606 }; |
| 1607 | 1607 |
| 1608 for (size_t i = 0; i < arraysize(replace_cases); i++) { | 1608 for (size_t i = 0; i < arraysize(replace_cases); i++) { |
| 1609 const ReplaceCase& cur = replace_cases[i]; | 1609 const ReplaceCase& cur = replace_cases[i]; |
| 1610 int base_len = static_cast<int>(strlen(cur.base)); | 1610 int base_len = static_cast<int>(strlen(cur.base)); |
| 1611 url_parse::Parsed parsed; | 1611 url_parse::Parsed parsed; |
| 1612 url_parse::ParsePathURL(cur.base, base_len, &parsed); | 1612 url_parse::ParsePathURL(cur.base, base_len, false, &parsed); |
| 1613 | 1613 |
| 1614 url_canon::Replacements<char> r; | 1614 url_canon::Replacements<char> r; |
| 1615 typedef url_canon::Replacements<char> R; // Clean up syntax. | 1615 typedef url_canon::Replacements<char> R; // Clean up syntax. |
| 1616 SetupReplComp(&R::SetScheme, &R::ClearRef, &r, cur.scheme); | 1616 SetupReplComp(&R::SetScheme, &R::ClearRef, &r, cur.scheme); |
| 1617 SetupReplComp(&R::SetUsername, &R::ClearUsername, &r, cur.username); | 1617 SetupReplComp(&R::SetUsername, &R::ClearUsername, &r, cur.username); |
| 1618 SetupReplComp(&R::SetPassword, &R::ClearPassword, &r, cur.password); | 1618 SetupReplComp(&R::SetPassword, &R::ClearPassword, &r, cur.password); |
| 1619 SetupReplComp(&R::SetHost, &R::ClearHost, &r, cur.host); | 1619 SetupReplComp(&R::SetHost, &R::ClearHost, &r, cur.host); |
| 1620 SetupReplComp(&R::SetPort, &R::ClearPort, &r, cur.port); | 1620 SetupReplComp(&R::SetPort, &R::ClearPort, &r, cur.port); |
| 1621 SetupReplComp(&R::SetPath, &R::ClearPath, &r, cur.path); | 1621 SetupReplComp(&R::SetPath, &R::ClearPath, &r, cur.path); |
| 1622 SetupReplComp(&R::SetQuery, &R::ClearQuery, &r, cur.query); | 1622 SetupReplComp(&R::SetQuery, &R::ClearQuery, &r, cur.query); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 const char* expected; | 1823 const char* expected; |
| 1824 } path_cases[] = { | 1824 } path_cases[] = { |
| 1825 {"javascript:", "javascript:"}, | 1825 {"javascript:", "javascript:"}, |
| 1826 {"JavaScript:Foo", "javascript:Foo"}, | 1826 {"JavaScript:Foo", "javascript:Foo"}, |
| 1827 {":\":This /is interesting;?#", ":\":This /is interesting;?#"}, | 1827 {":\":This /is interesting;?#", ":\":This /is interesting;?#"}, |
| 1828 }; | 1828 }; |
| 1829 | 1829 |
| 1830 for (size_t i = 0; i < ARRAYSIZE(path_cases); i++) { | 1830 for (size_t i = 0; i < ARRAYSIZE(path_cases); i++) { |
| 1831 int url_len = static_cast<int>(strlen(path_cases[i].input)); | 1831 int url_len = static_cast<int>(strlen(path_cases[i].input)); |
| 1832 url_parse::Parsed parsed; | 1832 url_parse::Parsed parsed; |
| 1833 url_parse::ParsePathURL(path_cases[i].input, url_len, &parsed); | 1833 url_parse::ParsePathURL(path_cases[i].input, url_len, true, &parsed); |
| 1834 | 1834 |
| 1835 url_parse::Parsed out_parsed; | 1835 url_parse::Parsed out_parsed; |
| 1836 std::string out_str; | 1836 std::string out_str; |
| 1837 url_canon::StdStringCanonOutput output(&out_str); | 1837 url_canon::StdStringCanonOutput output(&out_str); |
| 1838 bool success = url_canon::CanonicalizePathURL(path_cases[i].input, url_len, | 1838 bool success = url_canon::CanonicalizePathURL(path_cases[i].input, url_len, |
| 1839 parsed, &output, | 1839 parsed, &output, |
| 1840 &out_parsed); | 1840 &out_parsed); |
| 1841 output.Complete(); | 1841 output.Complete(); |
| 1842 | 1842 |
| 1843 EXPECT_TRUE(success); | 1843 EXPECT_TRUE(success); |
| 1844 EXPECT_EQ(path_cases[i].expected, out_str); | 1844 EXPECT_EQ(path_cases[i].expected, out_str); |
| 1845 | 1845 |
| 1846 EXPECT_EQ(0, out_parsed.host.begin); | 1846 EXPECT_EQ(0, out_parsed.host.begin); |
| 1847 EXPECT_EQ(-1, out_parsed.host.len); | 1847 EXPECT_EQ(-1, out_parsed.host.len); |
| 1848 | 1848 |
| 1849 // When we end with a colon at the end, there should be no path. | 1849 // When we end with a colon at the end, there should be no path. |
| 1850 if (path_cases[i].input[url_len - 1] == ':') { | 1850 if (path_cases[i].input[url_len - 1] == ':') { |
| 1851 EXPECT_EQ(0, out_parsed.path.begin); | 1851 EXPECT_EQ(0, out_parsed.GetContent().begin); |
| 1852 EXPECT_EQ(-1, out_parsed.path.len); | 1852 EXPECT_EQ(-1, out_parsed.GetContent().len); |
| 1853 } | 1853 } |
| 1854 } | 1854 } |
| 1855 } | 1855 } |
| 1856 | 1856 |
| 1857 TEST(URLCanonTest, CanonicalizeMailtoURL) { | 1857 TEST(URLCanonTest, CanonicalizeMailtoURL) { |
| 1858 struct URLCase { | 1858 struct URLCase { |
| 1859 const char* input; | 1859 const char* input; |
| 1860 const char* expected; | 1860 const char* expected; |
| 1861 bool expected_success; | 1861 bool expected_success; |
| 1862 url_parse::Component expected_path; | 1862 url_parse::Component expected_path; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2149 for (size_t i = 0; i < ARRAYSIZE(rel_cases); i++) { | 2149 for (size_t i = 0; i < ARRAYSIZE(rel_cases); i++) { |
| 2150 const RelativeCase& cur_case = rel_cases[i]; | 2150 const RelativeCase& cur_case = rel_cases[i]; |
| 2151 | 2151 |
| 2152 url_parse::Parsed parsed; | 2152 url_parse::Parsed parsed; |
| 2153 int base_len = static_cast<int>(strlen(cur_case.base)); | 2153 int base_len = static_cast<int>(strlen(cur_case.base)); |
| 2154 if (cur_case.is_base_file) | 2154 if (cur_case.is_base_file) |
| 2155 url_parse::ParseFileURL(cur_case.base, base_len, &parsed); | 2155 url_parse::ParseFileURL(cur_case.base, base_len, &parsed); |
| 2156 else if (cur_case.is_base_hier) | 2156 else if (cur_case.is_base_hier) |
| 2157 url_parse::ParseStandardURL(cur_case.base, base_len, &parsed); | 2157 url_parse::ParseStandardURL(cur_case.base, base_len, &parsed); |
| 2158 else | 2158 else |
| 2159 url_parse::ParsePathURL(cur_case.base, base_len, &parsed); | 2159 url_parse::ParsePathURL(cur_case.base, base_len, false, &parsed); |
| 2160 | 2160 |
| 2161 // First see if it is relative. | 2161 // First see if it is relative. |
| 2162 int test_len = static_cast<int>(strlen(cur_case.test)); | 2162 int test_len = static_cast<int>(strlen(cur_case.test)); |
| 2163 bool is_relative; | 2163 bool is_relative; |
| 2164 url_parse::Component relative_component; | 2164 url_parse::Component relative_component; |
| 2165 bool succeed_is_rel = url_canon::IsRelativeURL( | 2165 bool succeed_is_rel = url_canon::IsRelativeURL( |
| 2166 cur_case.base, parsed, cur_case.test, test_len, cur_case.is_base_hier, | 2166 cur_case.base, parsed, cur_case.test, test_len, cur_case.is_base_hier, |
| 2167 &is_relative, &relative_component); | 2167 &is_relative, &relative_component); |
| 2168 | 2168 |
| 2169 EXPECT_EQ(cur_case.succeed_relative, succeed_is_rel) << | 2169 EXPECT_EQ(cur_case.succeed_relative, succeed_is_rel) << |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2181 cur_case.test, relative_component, NULL, &output, &resolved_parsed); | 2181 cur_case.test, relative_component, NULL, &output, &resolved_parsed); |
| 2182 output.Complete(); | 2182 output.Complete(); |
| 2183 | 2183 |
| 2184 EXPECT_EQ(cur_case.succeed_resolve, succeed_resolve); | 2184 EXPECT_EQ(cur_case.succeed_resolve, succeed_resolve); |
| 2185 EXPECT_EQ(cur_case.resolved, resolved) << " on " << cur_case.test; | 2185 EXPECT_EQ(cur_case.resolved, resolved) << " on " << cur_case.test; |
| 2186 | 2186 |
| 2187 // Verify that the output parsed structure is the same as parsing a | 2187 // Verify that the output parsed structure is the same as parsing a |
| 2188 // the URL freshly. | 2188 // the URL freshly. |
| 2189 url_parse::Parsed ref_parsed; | 2189 url_parse::Parsed ref_parsed; |
| 2190 int resolved_len = static_cast<int>(resolved.size()); | 2190 int resolved_len = static_cast<int>(resolved.size()); |
| 2191 if (cur_case.is_base_file) | 2191 if (cur_case.is_base_file) { |
| 2192 url_parse::ParseFileURL(resolved.c_str(), resolved_len, &ref_parsed); | 2192 url_parse::ParseFileURL(resolved.c_str(), resolved_len, &ref_parsed); |
| 2193 else if (cur_case.is_base_hier) | 2193 } else if (cur_case.is_base_hier) { |
| 2194 url_parse::ParseStandardURL(resolved.c_str(), resolved_len, &ref_parsed)
; | 2194 url_parse::ParseStandardURL(resolved.c_str(), resolved_len, |
| 2195 else | 2195 &ref_parsed); |
| 2196 url_parse::ParsePathURL(resolved.c_str(), resolved_len, &ref_parsed); | 2196 } else { |
| 2197 url_parse::ParsePathURL(resolved.c_str(), resolved_len, false, |
| 2198 &ref_parsed); |
| 2199 } |
| 2197 EXPECT_TRUE(ParsedIsEqual(ref_parsed, resolved_parsed)); | 2200 EXPECT_TRUE(ParsedIsEqual(ref_parsed, resolved_parsed)); |
| 2198 } | 2201 } |
| 2199 } | 2202 } |
| 2200 } | 2203 } |
| 2201 | 2204 |
| 2202 // It used to be when we did a replacement with a long buffer of UTF-16 | 2205 // It used to be when we did a replacement with a long buffer of UTF-16 |
| 2203 // characters, we would get invalid data in the URL. This is because the buffer | 2206 // characters, we would get invalid data in the URL. This is because the buffer |
| 2204 // it used to hold the UTF-8 data was resized, while some pointers were still | 2207 // it used to hold the UTF-8 data was resized, while some pointers were still |
| 2205 // kept to the old buffer that was removed. | 2208 // kept to the old buffer that was removed. |
| 2206 TEST(URLCanonTest, ReplacementOverflow) { | 2209 TEST(URLCanonTest, ReplacementOverflow) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2229 url_canon::StdStringCanonOutput repl_output(&repl_str); | 2232 url_canon::StdStringCanonOutput repl_output(&repl_str); |
| 2230 url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed)
; | 2233 url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed)
; |
| 2231 repl_output.Complete(); | 2234 repl_output.Complete(); |
| 2232 | 2235 |
| 2233 // Generate the expected string and check. | 2236 // Generate the expected string and check. |
| 2234 std::string expected("file:///foo?"); | 2237 std::string expected("file:///foo?"); |
| 2235 for (size_t i = 0; i < new_query.length(); i++) | 2238 for (size_t i = 0; i < new_query.length(); i++) |
| 2236 expected.push_back('a'); | 2239 expected.push_back('a'); |
| 2237 EXPECT_TRUE(expected == repl_str); | 2240 EXPECT_TRUE(expected == repl_str); |
| 2238 } | 2241 } |
| OLD | NEW |