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 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 } | 1817 } |
1818 | 1818 |
1819 TEST(URLCanonTest, CanonicalizePathURL) { | 1819 TEST(URLCanonTest, CanonicalizePathURL) { |
1820 // Path URLs should get canonicalized schemes but nothing else. | 1820 // Path URLs should get canonicalized schemes but nothing else. |
1821 struct PathCase { | 1821 struct PathCase { |
1822 const char* input; | 1822 const char* input; |
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%20/is%20interesting;?#"}, |
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, &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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 url_canon::StdStringCanonOutput repl_output(&repl_str); | 2229 url_canon::StdStringCanonOutput repl_output(&repl_str); |
2230 url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed)
; | 2230 url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed)
; |
2231 repl_output.Complete(); | 2231 repl_output.Complete(); |
2232 | 2232 |
2233 // Generate the expected string and check. | 2233 // Generate the expected string and check. |
2234 std::string expected("file:///foo?"); | 2234 std::string expected("file:///foo?"); |
2235 for (size_t i = 0; i < new_query.length(); i++) | 2235 for (size_t i = 0; i < new_query.length(); i++) |
2236 expected.push_back('a'); | 2236 expected.push_back('a'); |
2237 EXPECT_TRUE(expected == repl_str); | 2237 EXPECT_TRUE(expected == repl_str); |
2238 } | 2238 } |
OLD | NEW |