miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 5 | #include "components/url_formatter/elide_url.h" |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 6 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
justincohen | b96612bf | 2015-07-24 22:26:09 | [diff] [blame] | 9 | #include "base/ios/ios_util.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 10 | #include "base/macros.h" |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 12 | #include "build/build_config.h" |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 13 | #include "testing/gtest/include/gtest/gtest.h" |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 14 | #include "url/gurl.h" |
| 15 | |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 16 | #if !defined(OS_ANDROID) |
| 17 | #include "ui/gfx/font_list.h" // nogncheck |
| 18 | #include "ui/gfx/text_elider.h" // nogncheck |
| 19 | #include "ui/gfx/text_utils.h" // nogncheck |
| 20 | #endif |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 21 | |
| 22 | namespace { |
| 23 | |
| 24 | struct Testcase { |
| 25 | const std::string input; |
| 26 | const std::string output; |
eugenebut | bec2c5f | 2015-08-07 23:22:32 | [diff] [blame] | 27 | enum SupportedPlatforms { |
| 28 | ALL = 0, |
| 29 | NO_IOS9_OR_LATER, |
| 30 | NO_IOS, |
| 31 | } platforms; |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | #if !defined(OS_ANDROID) |
| 35 | void RunUrlTest(Testcase* testcases, size_t num_testcases) { |
| 36 | static const gfx::FontList font_list; |
| 37 | for (size_t i = 0; i < num_testcases; ++i) { |
| 38 | const GURL url(testcases[i].input); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 39 | const float available_width = |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 40 | gfx::GetStringWidthF(base::UTF8ToUTF16(testcases[i].output), font_list); |
| 41 | EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output), |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame^] | 42 | url_formatter::ElideUrl(url, font_list, available_width)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | // Test eliding of commonplace URLs. |
| 47 | TEST(TextEliderTest, TestGeneralEliding) { |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 48 | const std::string kEllipsisStr(gfx::kEllipsis); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 49 | Testcase testcases[] = { |
| 50 | {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, |
| 51 | {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, |
| 52 | {"http://www.google.com/intl/en/ads/", |
| 53 | "google.com/intl/" + kEllipsisStr + "/ads/"}, |
| 54 | {"http://www.google.com/intl/en/ads/", |
| 55 | "google.com/" + kEllipsisStr + "/ads/"}, |
| 56 | {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr}, |
| 57 | {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr}, |
| 58 | {"https://subdomain.foo.com/bar/filename.html", |
| 59 | "subdomain.foo.com/bar/filename.html"}, |
| 60 | {"https://subdomain.foo.com/bar/filename.html", |
| 61 | "subdomain.foo.com/" + kEllipsisStr + "/filename.html"}, |
| 62 | {"http://subdomain.foo.com/bar/filename.html", |
| 63 | kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"}, |
| 64 | {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired", |
| 65 | "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr}, |
| 66 | }; |
| 67 | |
| 68 | RunUrlTest(testcases, arraysize(testcases)); |
| 69 | } |
| 70 | |
| 71 | // When there is very little space available, the elision code will shorten |
| 72 | // both path AND file name to an ellipsis - ".../...". To avoid this result, |
| 73 | // there is a hack in place that simply treats them as one string in this |
| 74 | // case. |
| 75 | TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) { |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 76 | const std::string kEllipsisStr(gfx::kEllipsis); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 77 | |
| 78 | // Very little space, would cause double ellipsis. |
| 79 | gfx::FontList font_list; |
| 80 | GURL url("http://battersbox.com/directory/foo/peter_paul_and_mary.html"); |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 81 | float available_width = gfx::GetStringWidthF( |
| 82 | base::UTF8ToUTF16("battersbox.com/" + kEllipsisStr + "/" + kEllipsisStr), |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 83 | font_list); |
| 84 | |
| 85 | // Create the expected string, after elision. Depending on font size, the |
| 86 | // directory might become /dir... or /di... or/d... - it never should be |
| 87 | // shorter than that. (If it is, the font considers d... to be longer |
| 88 | // than .../... - that should never happen). |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 89 | ASSERT_GT( |
| 90 | gfx::GetStringWidthF(base::UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr), |
| 91 | font_list), |
| 92 | gfx::GetStringWidthF(base::UTF8ToUTF16("d" + kEllipsisStr), font_list)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 93 | GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc"); |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 94 | base::string16 expected = url_formatter::ElideUrl( |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame^] | 95 | long_url, font_list, available_width); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 96 | // Ensure that the expected result still contains part of the directory name. |
| 97 | ASSERT_GT(expected.length(), std::string("battersbox.com/d").length()); |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame^] | 98 | EXPECT_EQ(expected, url_formatter::ElideUrl(url, font_list, available_width)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 99 | |
| 100 | // More space available - elide directories, partially elide filename. |
| 101 | Testcase testcases[] = { |
| 102 | {"http://battersbox.com/directory/foo/peter_paul_and_mary.html", |
| 103 | "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr}, |
| 104 | }; |
| 105 | RunUrlTest(testcases, arraysize(testcases)); |
| 106 | } |
| 107 | |
| 108 | // Test eliding of empty strings, URLs with ports, passwords, queries, etc. |
| 109 | TEST(TextEliderTest, TestMoreEliding) { |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 110 | const std::string kEllipsisStr(gfx::kEllipsis); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 111 | Testcase testcases[] = { |
| 112 | {"http://www.google.com/foo?bar", "www.google.com/foo?bar"}, |
| 113 | {"http://xyz.google.com/foo?bar", "xyz.google.com/foo?" + kEllipsisStr}, |
| 114 | {"http://xyz.google.com/foo?bar", "xyz.google.com/foo" + kEllipsisStr}, |
| 115 | {"http://xyz.google.com/foo?bar", "xyz.google.com/fo" + kEllipsisStr}, |
| 116 | {"http://a.b.com/pathname/c?d", "a.b.com/" + kEllipsisStr + "/c?d"}, |
| 117 | {"", ""}, |
| 118 | {"http://foo.bar..example.com...hello/test/filename.html", |
| 119 | "foo.bar..example.com...hello/" + kEllipsisStr + "/filename.html"}, |
| 120 | {"http://foo.bar../", "foo.bar.."}, |
| 121 | {"http://xn--1lq90i.cn/foo", "\xe5\x8c\x97\xe4\xba\xac.cn/foo"}, |
| 122 | {"http://me:[email protected]:99/foo?bar#baz", |
| 123 | "secrethost.com:99/foo?bar#baz"}, |
| 124 | {"http://me:mypass@ss%xxfdsf.com/foo", "ss%25xxfdsf.com/foo"}, |
| 125 | {"mailto:[email protected]", "mailto:[email protected]"}, |
| 126 | {"javascript:click(0)", "javascript:click(0)"}, |
| 127 | {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", |
| 128 | "chess.eecs.berkeley.edu:4430/login/arbitfilename"}, |
| 129 | {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", |
| 130 | kEllipsisStr + "berkeley.edu:4430/" + kEllipsisStr + "/arbitfilename"}, |
| 131 | |
| 132 | // Unescaping. |
| 133 | {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", |
| 134 | "www/\xe4\xbd\xa0\xe5\xa5\xbd?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"}, |
| 135 | |
| 136 | // Invalid unescaping for path. The ref will always be valid UTF-8. We |
| 137 | // don't |
| 138 | // bother to do too many edge cases, since these are handled by the |
| 139 | // escaper |
| 140 | // unittest. |
| 141 | {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", |
| 142 | "www/%E4%A0%E5%A5%BD?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"}, |
| 143 | }; |
| 144 | |
| 145 | RunUrlTest(testcases, arraysize(testcases)); |
| 146 | } |
| 147 | |
| 148 | // Test eliding of file: URLs. |
| 149 | TEST(TextEliderTest, TestFileURLEliding) { |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 150 | const std::string kEllipsisStr(gfx::kEllipsis); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 151 | Testcase testcases[] = { |
| 152 | {"file:///C:/path1/path2/path3/filename", |
| 153 | "file:///C:/path1/path2/path3/filename"}, |
| 154 | {"file:///C:/path1/path2/path3/filename", "C:/path1/path2/path3/filename"}, |
| 155 | // GURL parses "file:///C:path" differently on windows than it does on posix. |
| 156 | #if defined(OS_WIN) |
| 157 | {"file:///C:path1/path2/path3/filename", |
| 158 | "C:/path1/path2/" + kEllipsisStr + "/filename"}, |
| 159 | {"file:///C:path1/path2/path3/filename", |
| 160 | "C:/path1/" + kEllipsisStr + "/filename"}, |
| 161 | {"file:///C:path1/path2/path3/filename", |
| 162 | "C:/" + kEllipsisStr + "/filename"}, |
| 163 | #endif // defined(OS_WIN) |
| 164 | {"file://filer/foo/bar/file", "filer/foo/bar/file"}, |
| 165 | {"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"}, |
| 166 | {"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"}, |
| 167 | {"file://filer/foo/", "file://filer/foo/"}, |
| 168 | {"file://filer/foo/", "filer/foo/"}, |
| 169 | {"file://filer/foo/", "filer" + kEllipsisStr}, |
| 170 | // Eliding file URLs with nothing after the ':' shouldn't crash. |
| 171 | {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:", "aaa" + kEllipsisStr}, |
| 172 | {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:/", "aaa" + kEllipsisStr}, |
| 173 | }; |
| 174 | |
| 175 | RunUrlTest(testcases, arraysize(testcases)); |
| 176 | } |
| 177 | |
| 178 | TEST(TextEliderTest, TestHostEliding) { |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 179 | const std::string kEllipsisStr(gfx::kEllipsis); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 180 | Testcase testcases[] = { |
eugenebut | bec2c5f | 2015-08-07 23:22:32 | [diff] [blame] | 181 | {"http://google.com", "google.com"}, |
| 182 | // iOS width calculations are off by a letter from other platforms for |
| 183 | // strings with too many kerned letters on the default font set. |
| 184 | // TODO(rohitrao): Fix secure_display::ElideHost for iOS |
| 185 | // (crbug.com/517604). |
| 186 | {"http://subdomain.google.com", kEllipsisStr + ".google.com", |
| 187 | Testcase::NO_IOS9_OR_LATER}, |
| 188 | {"http://reallyreallyreallylongdomainname.com", |
| 189 | "reallyreallyreallylongdomainname.com"}, |
| 190 | {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com", |
| 191 | Testcase::NO_IOS9_OR_LATER}, |
| 192 | {"http://foo", "foo"}, |
| 193 | {"http://foo.bar", "foo.bar"}, |
| 194 | {"http://subdomain.foo.bar", kEllipsisStr + "in.foo.bar", |
| 195 | Testcase::NO_IOS9_OR_LATER}, |
| 196 | {"http://subdomain.reallylongdomainname.com", |
| 197 | kEllipsisStr + "ain.reallylongdomainname.com", Testcase::NO_IOS}, |
| 198 | {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com", Testcase::NO_IOS}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | for (size_t i = 0; i < arraysize(testcases); ++i) { |
eugenebut | bec2c5f | 2015-08-07 23:22:32 | [diff] [blame] | 202 | #if defined(OS_IOS) |
| 203 | if (testcases[i].platforms == Testcase::NO_IOS || |
| 204 | (testcases[i].platforms == Testcase::NO_IOS9_OR_LATER && |
| 205 | base::ios::IsRunningOnIOS9OrLater())) { |
| 206 | continue; |
| 207 | } |
| 208 | #endif |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 209 | const float available_width = gfx::GetStringWidthF( |
| 210 | base::UTF8ToUTF16(testcases[i].output), gfx::FontList()); |
| 211 | EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output), |
| 212 | url_formatter::ElideHost(GURL(testcases[i].input), |
| 213 | gfx::FontList(), available_width)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | // Trying to elide to a really short length will still keep the full TLD+1 |
| 217 | EXPECT_EQ( |
| 218 | base::ASCIIToUTF16("google.com"), |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 219 | url_formatter::ElideHost(GURL("http://google.com"), gfx::FontList(), 2)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 220 | EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 221 | url_formatter::ElideHost(GURL("http://subdomain.google.com"), |
| 222 | gfx::FontList(), 2)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 223 | EXPECT_EQ( |
| 224 | base::ASCIIToUTF16("foo.bar"), |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 225 | url_formatter::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | #endif // !defined(OS_ANDROID) |
| 229 | |
| 230 | TEST(TextEliderTest, FormatUrlForSecurityDisplay) { |
| 231 | struct OriginTestData { |
| 232 | const char* const description; |
| 233 | const char* const input; |
| 234 | const wchar_t* const output; |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 235 | const wchar_t* const output_omit_scheme; |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | const OriginTestData tests[] = { |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 239 | {"Empty URL", "", L"", L""}, |
| 240 | {"HTTP URL", "http://www.google.com/", L"http://www.google.com", |
| 241 | L"www.google.com"}, |
| 242 | {"HTTPS URL", "https://www.google.com/", L"https://www.google.com", |
| 243 | L"www.google.com"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 244 | {"Standard HTTP port", "http://www.google.com:80/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 245 | L"http://www.google.com", L"www.google.com"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 246 | {"Standard HTTPS port", "https://www.google.com:443/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 247 | L"https://www.google.com", L"www.google.com"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 248 | {"Standard HTTP port, IDN Chinese", |
| 249 | "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 250 | L"http://xn--fiqs8s.icom.museum", L"xn--fiqs8s.icom.museum"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 251 | {"HTTP URL, IDN Hebrew (RTL)", |
| 252 | "http://" |
| 253 | "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d." |
| 254 | "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 255 | L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum", |
| 256 | L"xn--4dbklr2c8d.xn--4dbrk0ce.museum"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 257 | {"HTTP URL with query string, IDN Arabic (RTL)", |
| 258 | "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 259 | L"http://xn--wgbh1c.icom.museum", L"xn--wgbh1c.icom.museum"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 260 | {"Non-standard HTTP port", "http://www.google.com:9000/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 261 | L"http://www.google.com:9000", L"www.google.com:9000"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 262 | {"Non-standard HTTPS port", "https://www.google.com:9000/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 263 | L"https://www.google.com:9000", L"www.google.com:9000"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 264 | {"File URI", "file:///usr/example/file.html", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 265 | L"file:///usr/example/file.html", L"file:///usr/example/file.html"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 266 | {"File URI with hostname", "file://localhost/usr/example/file.html", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 267 | L"file:///usr/example/file.html", L"file:///usr/example/file.html"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 268 | {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 269 | L"file:///CONTOSO/accounting/money.xls", |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 270 | L"file:///CONTOSO/accounting/money.xls"}, |
| 271 | {"UNC File URI 2", |
| 272 | "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 273 | L"file:///C:/Program%20Files/Music/Web%20Sys/main.html", |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 274 | L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, |
| 275 | {"HTTP URL with path", "http://www.google.com/test.html", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 276 | L"http://www.google.com", L"www.google.com"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 277 | {"HTTPS URL with path", "https://www.google.com/test.html", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 278 | L"https://www.google.com", L"www.google.com"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 279 | {"Unusual secure scheme (wss)", "wss://www.google.com/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 280 | L"wss://www.google.com", L"wss://www.google.com"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 281 | {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 282 | L"gopher://www.google.com", L"gopher://www.google.com"}, |
| 283 | {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version", |
| 284 | L"chrome://version"}, |
| 285 | {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103", |
| 286 | L"173.194.65.103"}, |
| 287 | {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103", |
| 288 | L"173.194.65.103"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 289 | {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 290 | L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 291 | {"HTTPS IPv6 address with port", "https://[2001:db8:0:1]:443/", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 292 | L"https://[2001:db8:0:1]", L"https://[2001:db8:0:1]"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 293 | {"HTTPS IP address, non-default port", "https://173.194.65.103:8443", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 294 | L"https://173.194.65.103:8443", L"173.194.65.103:8443"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 295 | {"HTTP filesystem: URL with path", |
| 296 | "filesystem:http://www.google.com/temporary/test.html", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 297 | L"filesystem:http://www.google.com", |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 298 | L"filesystem:http://www.google.com"}, |
| 299 | {"File filesystem: URL with path", |
| 300 | "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 301 | L"filesystem:file:///temporary/stuff/test.html", |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 302 | L"filesystem:file:///temporary/stuff/test.html"}, |
| 303 | {"Invalid scheme 1", "twelve://www.cyber.org/wow.php", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 304 | L"twelve://www.cyber.org/wow.php", L"twelve://www.cyber.org/wow.php"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 305 | {"Invalid scheme 2", "://www.cyber.org/wow.php", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 306 | L"://www.cyber.org/wow.php", L"://www.cyber.org/wow.php"}, |
| 307 | {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber..", |
| 308 | L"www.cyber.."}, |
| 309 | {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber", |
| 310 | L"www...cyber"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 311 | {"Invalid port 1", "https://173.194.65.103:000", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 312 | L"https://173.194.65.103:0", L"173.194.65.103:0"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 313 | {"Invalid port 2", "https://173.194.65.103:gruffle", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 314 | L"https://173.194.65.103:gruffle", L"https://173.194.65.103:gruffle"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 315 | {"Invalid port 3", "https://173.194.65.103:/hello.aspx", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 316 | L"https://173.194.65.103", L"173.194.65.103"}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 317 | {"Trailing dot in DNS name", "https://www.example.com./get/goat", |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 318 | L"https://www.example.com.", L"www.example.com."}, |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 319 | {"Blob URL", |
| 320 | "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
| 321 | L"blob:http%3A//www.html5rocks.com/" |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 322 | L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
| 323 | L"blob:http%3A//www.html5rocks.com/" |
| 324 | L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}}; |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 325 | |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 326 | for (size_t i = 0; i < arraysize(tests); ++i) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame^] | 327 | base::string16 formatted = |
| 328 | url_formatter::FormatUrlForSecurityDisplay(GURL(tests[i].input)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 329 | EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) |
| 330 | << tests[i].description; |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 331 | |
| 332 | base::string16 formatted_omit_scheme = |
| 333 | url_formatter::FormatUrlForSecurityDisplayOmitScheme( |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame^] | 334 | GURL(tests[i].input)); |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 335 | EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_scheme), |
| 336 | formatted_omit_scheme) |
| 337 | << tests[i].description; |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | base::string16 formatted = |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame^] | 341 | url_formatter::FormatUrlForSecurityDisplay(GURL()); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 342 | EXPECT_EQ(base::string16(), formatted) |
| 343 | << "Explicitly test the 0-argument GURL constructor"; |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 344 | |
| 345 | base::string16 formatted_omit_scheme = |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame^] | 346 | url_formatter::FormatUrlForSecurityDisplayOmitScheme(GURL()); |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 347 | EXPECT_EQ(base::string16(), formatted_omit_scheme) |
| 348 | << "Explicitly test the 0-argument GURL constructor"; |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | } // namespace |