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 | |
justincohen | b96612bf | 2015-07-24 22:26:09 | [diff] [blame] | 7 | #include "base/ios/ios_util.h" |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 8 | #include "base/strings/utf_string_conversions.h" |
| 9 | #include "testing/gtest/include/gtest/gtest.h" |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 10 | #include "url/gurl.h" |
| 11 | |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 12 | #if !defined(OS_ANDROID) |
| 13 | #include "ui/gfx/font_list.h" // nogncheck |
| 14 | #include "ui/gfx/text_elider.h" // nogncheck |
| 15 | #include "ui/gfx/text_utils.h" // nogncheck |
| 16 | #endif |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 17 | |
| 18 | namespace { |
| 19 | |
| 20 | struct Testcase { |
| 21 | const std::string input; |
| 22 | const std::string output; |
eugenebut | bec2c5f | 2015-08-07 23:22:32 | [diff] [blame^] | 23 | enum SupportedPlatforms { |
| 24 | ALL = 0, |
| 25 | NO_IOS9_OR_LATER, |
| 26 | NO_IOS, |
| 27 | } platforms; |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | #if !defined(OS_ANDROID) |
| 31 | void RunUrlTest(Testcase* testcases, size_t num_testcases) { |
| 32 | static const gfx::FontList font_list; |
| 33 | for (size_t i = 0; i < num_testcases; ++i) { |
| 34 | const GURL url(testcases[i].input); |
| 35 | // Should we test with non-empty language list? |
| 36 | // That's kinda redundant with net_util_unittests. |
| 37 | const float available_width = |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 38 | gfx::GetStringWidthF(base::UTF8ToUTF16(testcases[i].output), font_list); |
| 39 | EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output), |
| 40 | url_formatter::ElideUrl(url, font_list, available_width, |
| 41 | std::string())); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | // Test eliding of commonplace URLs. |
| 46 | TEST(TextEliderTest, TestGeneralEliding) { |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 47 | const std::string kEllipsisStr(gfx::kEllipsis); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 48 | Testcase testcases[] = { |
| 49 | {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, |
| 50 | {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, |
| 51 | {"http://www.google.com/intl/en/ads/", |
| 52 | "google.com/intl/" + kEllipsisStr + "/ads/"}, |
| 53 | {"http://www.google.com/intl/en/ads/", |
| 54 | "google.com/" + kEllipsisStr + "/ads/"}, |
| 55 | {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr}, |
| 56 | {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr}, |
| 57 | {"https://subdomain.foo.com/bar/filename.html", |
| 58 | "subdomain.foo.com/bar/filename.html"}, |
| 59 | {"https://subdomain.foo.com/bar/filename.html", |
| 60 | "subdomain.foo.com/" + kEllipsisStr + "/filename.html"}, |
| 61 | {"http://subdomain.foo.com/bar/filename.html", |
| 62 | kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"}, |
| 63 | {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired", |
| 64 | "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr}, |
| 65 | }; |
| 66 | |
| 67 | RunUrlTest(testcases, arraysize(testcases)); |
| 68 | } |
| 69 | |
| 70 | // When there is very little space available, the elision code will shorten |
| 71 | // both path AND file name to an ellipsis - ".../...". To avoid this result, |
| 72 | // there is a hack in place that simply treats them as one string in this |
| 73 | // case. |
| 74 | TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) { |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 75 | const std::string kEllipsisStr(gfx::kEllipsis); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 76 | |
| 77 | // Very little space, would cause double ellipsis. |
| 78 | gfx::FontList font_list; |
| 79 | GURL url("http://battersbox.com/directory/foo/peter_paul_and_mary.html"); |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 80 | float available_width = gfx::GetStringWidthF( |
| 81 | base::UTF8ToUTF16("battersbox.com/" + kEllipsisStr + "/" + kEllipsisStr), |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 82 | font_list); |
| 83 | |
| 84 | // Create the expected string, after elision. Depending on font size, the |
| 85 | // directory might become /dir... or /di... or/d... - it never should be |
| 86 | // shorter than that. (If it is, the font considers d... to be longer |
| 87 | // than .../... - that should never happen). |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 88 | ASSERT_GT( |
| 89 | gfx::GetStringWidthF(base::UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr), |
| 90 | font_list), |
| 91 | gfx::GetStringWidthF(base::UTF8ToUTF16("d" + kEllipsisStr), font_list)); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 92 | GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc"); |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 93 | base::string16 expected = url_formatter::ElideUrl( |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 94 | long_url, font_list, available_width, std::string()); |
| 95 | // Ensure that the expected result still contains part of the directory name. |
| 96 | ASSERT_GT(expected.length(), std::string("battersbox.com/d").length()); |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 97 | EXPECT_EQ(expected, url_formatter::ElideUrl(url, font_list, available_width, |
| 98 | std::string())); |
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; |
| 235 | }; |
| 236 | |
| 237 | const OriginTestData tests[] = { |
| 238 | {"Empty URL", "", L""}, |
| 239 | {"HTTP URL", "http://www.google.com/", L"http://www.google.com"}, |
| 240 | {"HTTPS URL", "https://www.google.com/", L"https://www.google.com"}, |
| 241 | {"Standard HTTP port", "http://www.google.com:80/", |
| 242 | L"http://www.google.com"}, |
| 243 | {"Standard HTTPS port", "https://www.google.com:443/", |
| 244 | L"https://www.google.com"}, |
| 245 | {"Standard HTTP port, IDN Chinese", |
| 246 | "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80", |
| 247 | L"http://xn--fiqs8s.icom.museum"}, |
| 248 | {"HTTP URL, IDN Hebrew (RTL)", |
| 249 | "http://" |
| 250 | "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d." |
| 251 | "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/", |
| 252 | L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"}, |
| 253 | {"HTTP URL with query string, IDN Arabic (RTL)", |
| 254 | "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no", |
| 255 | L"http://xn--wgbh1c.icom.museum"}, |
| 256 | {"Non-standard HTTP port", "http://www.google.com:9000/", |
| 257 | L"http://www.google.com:9000"}, |
| 258 | {"Non-standard HTTPS port", "https://www.google.com:9000/", |
| 259 | L"https://www.google.com:9000"}, |
| 260 | {"File URI", "file:///usr/example/file.html", |
| 261 | L"file:///usr/example/file.html"}, |
| 262 | {"File URI with hostname", "file://localhost/usr/example/file.html", |
| 263 | L"file:///usr/example/file.html"}, |
| 264 | {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls", |
| 265 | L"file:///CONTOSO/accounting/money.xls"}, |
| 266 | {"UNC File URI 2", |
| 267 | "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", |
| 268 | L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, |
| 269 | {"HTTP URL with path", "http://www.google.com/test.html", |
| 270 | L"http://www.google.com"}, |
| 271 | {"HTTPS URL with path", "https://www.google.com/test.html", |
| 272 | L"https://www.google.com"}, |
| 273 | {"Unusual secure scheme (wss)", "wss://www.google.com/", |
| 274 | L"wss://www.google.com"}, |
| 275 | {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/", |
| 276 | L"gopher://www.google.com"}, |
| 277 | {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version"}, |
| 278 | {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103"}, |
| 279 | {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103"}, |
| 280 | {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", |
| 281 | L"http://[fe80::202:b3ff:fe1e:8329]"}, |
| 282 | {"HTTPS IPv6 address with port", "https://[2001:db8:0:1]:443/", |
| 283 | L"https://[2001:db8:0:1]"}, |
| 284 | {"HTTPS IP address, non-default port", "https://173.194.65.103:8443", |
| 285 | L"https://173.194.65.103:8443"}, |
| 286 | {"HTTP filesystem: URL with path", |
| 287 | "filesystem:http://www.google.com/temporary/test.html", |
| 288 | L"filesystem:http://www.google.com"}, |
| 289 | {"File filesystem: URL with path", |
| 290 | "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", |
| 291 | L"filesystem:file:///temporary/stuff/test.html"}, |
| 292 | {"Invalid scheme 1", "twelve://www.cyber.org/wow.php", |
| 293 | L"twelve://www.cyber.org/wow.php"}, |
| 294 | {"Invalid scheme 2", "://www.cyber.org/wow.php", |
| 295 | L"://www.cyber.org/wow.php"}, |
| 296 | {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber.."}, |
| 297 | {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber"}, |
| 298 | {"Invalid port 1", "https://173.194.65.103:000", |
| 299 | L"https://173.194.65.103:0"}, |
| 300 | {"Invalid port 2", "https://173.194.65.103:gruffle", |
| 301 | L"https://173.194.65.103:gruffle"}, |
| 302 | {"Invalid port 3", "https://173.194.65.103:/hello.aspx", |
| 303 | L"https://173.194.65.103"}, |
| 304 | {"Trailing dot in DNS name", "https://www.example.com./get/goat", |
| 305 | L"https://www.example.com."}, |
| 306 | {"Blob URL", |
| 307 | "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
| 308 | L"blob:http%3A//www.html5rocks.com/" |
| 309 | L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}, |
| 310 | }; |
| 311 | |
| 312 | const char languages[] = "zh-TW,en-US,en,am,ar-EG,ar"; |
| 313 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 314 | base::string16 formatted = url_formatter::FormatUrlForSecurityDisplay( |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 315 | GURL(tests[i].input), std::string()); |
| 316 | EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) |
| 317 | << tests[i].description; |
| 318 | base::string16 formatted_with_languages = |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 319 | url_formatter::FormatUrlForSecurityDisplay(GURL(tests[i].input), |
| 320 | languages); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 321 | EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted_with_languages) |
| 322 | << tests[i].description; |
| 323 | } |
| 324 | |
| 325 | base::string16 formatted = |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 326 | url_formatter::FormatUrlForSecurityDisplay(GURL(), std::string()); |
miguelg | dbcfb12 | 2015-07-23 10:45:11 | [diff] [blame] | 327 | EXPECT_EQ(base::string16(), formatted) |
| 328 | << "Explicitly test the 0-argument GURL constructor"; |
| 329 | } |
| 330 | |
| 331 | } // namespace |