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 "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 } | 1840 } |
1841 | 1841 |
1842 TEST(URLCanonTest, CanonicalizeMailtoURL) { | 1842 TEST(URLCanonTest, CanonicalizeMailtoURL) { |
1843 struct URLCase { | 1843 struct URLCase { |
1844 const char* input; | 1844 const char* input; |
1845 const char* expected; | 1845 const char* expected; |
1846 bool expected_success; | 1846 bool expected_success; |
1847 Component expected_path; | 1847 Component expected_path; |
1848 Component expected_query; | 1848 Component expected_query; |
1849 } cases[] = { | 1849 } cases[] = { |
1850 // Null character should be escaped to %00. | 1850 {"mailto:addr1", "mailto:addr1", true, Component(7, 5), Component()}, |
1851 // Keep this test first in the list as it is handled specially below. | 1851 {"mailto:addr1@foo.com", "mailto:addr1@foo.com", true, Component(7, 13), Com
ponent()}, |
1852 {"mailto:addr1\0addr2?foo", | |
1853 "mailto:addr1%00addr2?foo", | |
1854 true, Component(7, 13), Component(21, 3)}, | |
1855 {"mailto:addr1", | |
1856 "mailto:addr1", | |
1857 true, Component(7, 5), Component()}, | |
1858 {"mailto:addr1@foo.com", | |
1859 "mailto:addr1@foo.com", | |
1860 true, Component(7, 13), Component()}, | |
1861 // Trailing whitespace is stripped. | 1852 // Trailing whitespace is stripped. |
1862 {"MaIlTo:addr1 \t ", | 1853 {"MaIlTo:addr1 \t ", "mailto:addr1", true, Component(7, 5), Component()}, |
1863 "mailto:addr1", | 1854 {"MaIlTo:addr1?to=jon", "mailto:addr1?to=jon", true, Component(7, 5), Compon
ent(13,6)}, |
1864 true, Component(7, 5), Component()}, | 1855 {"mailto:addr1,addr2", "mailto:addr1,addr2", true, Component(7, 11), Compone
nt()}, |
1865 {"MaIlTo:addr1?to=jon", | 1856 {"mailto:addr1, addr2", "mailto:addr1, addr2", true, Component(7, 12), Compo
nent()}, |
1866 "mailto:addr1?to=jon", | 1857 {"mailto:addr1%2caddr2", "mailto:addr1%2caddr2", true, Component(7, 13), Com
ponent()}, |
1867 true, Component(7, 5), Component(13,6)}, | 1858 {"mailto:\xF0\x90\x8C\x80", "mailto:%F0%90%8C%80", true, Component(7, 12), C
omponent()}, |
1868 {"mailto:addr1,addr2", | 1859 // Null character should be escaped to %00 |
1869 "mailto:addr1,addr2", | 1860 {"mailto:addr1\0addr2?foo", "mailto:addr1%00addr2?foo", true, Component(7, 1
3), Component(21, 3)}, |
1870 true, Component(7, 11), Component()}, | |
1871 // Embedded spaces must be encoded. | |
1872 {"mailto:addr1, addr2", | |
1873 "mailto:addr1,%20addr2", | |
1874 true, Component(7, 14), Component()}, | |
1875 {"mailto:addr1, addr2?subject=one two ", | |
1876 "mailto:addr1,%20addr2?subject=one%20two", | |
1877 true, Component(7, 14), Component(22, 17)}, | |
1878 {"mailto:addr1%2caddr2", | |
1879 "mailto:addr1%2caddr2", | |
1880 true, Component(7, 13), Component()}, | |
1881 {"mailto:\xF0\x90\x8C\x80", | |
1882 "mailto:%F0%90%8C%80", | |
1883 true, Component(7, 12), Component()}, | |
1884 // Invalid -- UTF-8 encoded surrogate value. | 1861 // Invalid -- UTF-8 encoded surrogate value. |
1885 {"mailto:\xed\xa0\x80", | 1862 {"mailto:\xed\xa0\x80", "mailto:%EF%BF%BD", false, Component(7, 9), Componen
t()}, |
1886 "mailto:%EF%BF%BD", | 1863 {"mailto:addr1?", "mailto:addr1?", true, Component(7, 5), Component(13, 0)}, |
1887 false, Component(7, 9), Component()}, | |
1888 {"mailto:addr1?", | |
1889 "mailto:addr1?", | |
1890 true, Component(7, 5), Component(13, 0)}, | |
1891 // Certain characters have special meanings and must be encoded. | |
1892 {"mailto:! \x22$&()+,-./09:;<=>@AZ[\\]&_`az{|}~\x7f?Query! \x22$&()+,-./09:;
<=>@AZ[\\]&_`az{|}~", | |
1893 "mailto:!%20%22$&()+,-./09:;%3C=%3E@AZ[\\]&_%60az%7B%7C%7D~%7F?Query!%20%22
$&()+,-./09:;%3C=%3E@AZ[\\]&_`az{|}~", | |
1894 true, Component(7, 53), Component(61, 47)}, | |
1895 }; | 1864 }; |
1896 | 1865 |
1897 // Define outside of loop to catch bugs where components aren't reset | 1866 // Define outside of loop to catch bugs where components aren't reset |
1898 Parsed parsed; | 1867 Parsed parsed; |
1899 Parsed out_parsed; | 1868 Parsed out_parsed; |
1900 | 1869 |
1901 for (size_t i = 0; i < arraysize(cases); i++) { | 1870 for (size_t i = 0; i < arraysize(cases); i++) { |
1902 int url_len = static_cast<int>(strlen(cases[i].input)); | 1871 int url_len = static_cast<int>(strlen(cases[i].input)); |
1903 if (i == 0) { | 1872 if (i == 8) { |
1904 // The first test case purposely has a '\0' in it -- don't count it | 1873 // The 9th test case purposely has a '\0' in it -- don't count it |
1905 // as the string terminator. | 1874 // as the string terminator. |
1906 url_len = 22; | 1875 url_len = 22; |
1907 } | 1876 } |
1908 ParseMailtoURL(cases[i].input, url_len, &parsed); | 1877 ParseMailtoURL(cases[i].input, url_len, &parsed); |
1909 | 1878 |
1910 std::string out_str; | 1879 std::string out_str; |
1911 StdStringCanonOutput output(&out_str); | 1880 StdStringCanonOutput output(&out_str); |
1912 bool success = CanonicalizeMailtoURL(cases[i].input, url_len, parsed, | 1881 bool success = CanonicalizeMailtoURL(cases[i].input, url_len, parsed, |
1913 &output, &out_parsed); | 1882 &output, &out_parsed); |
1914 output.Complete(); | 1883 output.Complete(); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2281 }; | 2250 }; |
2282 | 2251 |
2283 for (auto& test_case : cases) { | 2252 for (auto& test_case : cases) { |
2284 SCOPED_TRACE(test_case.scheme); | 2253 SCOPED_TRACE(test_case.scheme); |
2285 EXPECT_EQ(test_case.expected_port, | 2254 EXPECT_EQ(test_case.expected_port, |
2286 DefaultPortForScheme(test_case.scheme, strlen(test_case.scheme))); | 2255 DefaultPortForScheme(test_case.scheme, strlen(test_case.scheme))); |
2287 } | 2256 } |
2288 } | 2257 } |
2289 | 2258 |
2290 } // namespace url | 2259 } // namespace url |
OLD | NEW |