OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/elide_url.h" | 5 #include "chrome/browser/ui/elide_url.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/font_list.h" | 9 #include "ui/gfx/font_list.h" |
10 #include "ui/gfx/text_elider.h" | 10 #include "ui/gfx/text_elider.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 // Trying to elide to a really short length will still keep the full TLD+1 | 198 // Trying to elide to a really short length will still keep the full TLD+1 |
199 EXPECT_EQ(base::ASCIIToUTF16("google.com"), | 199 EXPECT_EQ(base::ASCIIToUTF16("google.com"), |
200 ElideHost(GURL("http://google.com"), gfx::FontList(), 2)); | 200 ElideHost(GURL("http://google.com"), gfx::FontList(), 2)); |
201 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), | 201 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), |
202 ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2)); | 202 ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2)); |
203 EXPECT_EQ(base::ASCIIToUTF16("foo.bar"), | 203 EXPECT_EQ(base::ASCIIToUTF16("foo.bar"), |
204 ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); | 204 ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); |
205 } | 205 } |
206 | 206 |
| 207 struct OriginTestData { |
| 208 const char* const description; |
| 209 const char* const input; |
| 210 const char* const languages; |
| 211 const wchar_t* const output; |
| 212 }; |
| 213 |
| 214 TEST(TextEliderTest, FormatUrlForSecurityDisplay) { |
| 215 const OriginTestData tests[] = { |
| 216 {"Empty URL", "", "", L""}, |
| 217 {"Empty URL, with languages", "", "en-US,zh-TW,zh", L""}, |
| 218 {"HTTP URL", "http://www.google.com/", "", L"http://www.google.com"}, |
| 219 {"HTTP URL, with languages", |
| 220 "http://www.google.com/", |
| 221 "en-US,en,am", |
| 222 L"http://www.google.com"}, |
| 223 {"HTTPS URL", "https://www.google.com/", "", L"https://www.google.com"}, |
| 224 {"HTTPS URL, with languages", |
| 225 "https://www.google.com/", |
| 226 "en-US,en,am,zh", |
| 227 L"https://www.google.com"}, |
| 228 {"Standard HTTP port", |
| 229 "http://www.google.com:80/", |
| 230 "", |
| 231 L"http://www.google.com"}, |
| 232 {"Standard HTTP port, with languages", |
| 233 "http://www.google.com:80/", |
| 234 "en-US,en,am,zh", |
| 235 L"http://www.google.com"}, |
| 236 {"Standard HTTPS port", |
| 237 "https://www.google.com:443/", |
| 238 "", |
| 239 L"https://www.google.com"}, |
| 240 {"Standard HTTPS port, with languages", |
| 241 "https://www.google.com:443/", |
| 242 "en-US,en,am,zh-TW", |
| 243 L"https://www.google.com"}, |
| 244 {"Standard HTTP port, IDN Chinese", |
| 245 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80", |
| 246 "", |
| 247 L"http://xn--fiqs8s.icom.museum"}, |
| 248 {"Standard HTTP port, IDN Chinese, with languages", |
| 249 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80", |
| 250 "en-US,en,am,zh-TW", |
| 251 L"http://xn--fiqs8s.icom.museum"}, |
| 252 {"HTTP URL, IDN Hebrew (RTL)", |
| 253 "http://" |
| 254 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d." |
| 255 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/", |
| 256 "", |
| 257 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"}, |
| 258 {"HTTP URL, IDN Hebrew (RTL), with languages", |
| 259 "http://" |
| 260 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d." |
| 261 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/", |
| 262 "en-US,en,am,zh-TW", |
| 263 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"}, |
| 264 {"HTTP URL with query string, IDN Arabic (RTL)", |
| 265 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no", |
| 266 "", |
| 267 L"http://xn--wgbh1c.icom.museum"}, |
| 268 {"HTTP URL with query string, IDN Arabic (RTL), with languages", |
| 269 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no", |
| 270 "ar-EG,en,am,zh-TW", |
| 271 L"http://xn--wgbh1c.icom.museum"}, |
| 272 {"Non-standard HTTP port", |
| 273 "http://www.google.com:9000/", |
| 274 "", |
| 275 L"http://www.google.com:9000"}, |
| 276 {"Non-standard HTTP port, with languages", |
| 277 "http://www.google.com:9000/", |
| 278 "en-US,en,am,zh", |
| 279 L"http://www.google.com:9000"}, |
| 280 {"Non-standard HTTPS port", |
| 281 "https://www.google.com:9000/", |
| 282 "", |
| 283 L"https://www.google.com:9000"}, |
| 284 {"Non-standard HTTPS port, with languages", |
| 285 "https://www.google.com:9000/", |
| 286 "en,am", |
| 287 L"https://www.google.com:9000"}, |
| 288 {"File URI", |
| 289 "file:///usr/example/file.html", |
| 290 "", |
| 291 L"file:///usr/example/file.html"}, |
| 292 {"File URI, with languages", |
| 293 "file:///usr/example/file.html", |
| 294 "en-US,en,zh", |
| 295 L"file:///usr/example/file.html"}, |
| 296 {"File URI with hostname", |
| 297 "file://localhost/usr/example/file.html", |
| 298 "", |
| 299 L"file:///usr/example/file.html"}, |
| 300 {"File URI with hostname, with languages", |
| 301 "file://localhost/usr/example/file.html", |
| 302 "en-US,zh", |
| 303 L"file:///usr/example/file.html"}, |
| 304 {"UNC File URI 1", |
| 305 "file:///CONTOSO/accounting/money.xls", |
| 306 "", |
| 307 L"file:///CONTOSO/accounting/money.xls"}, |
| 308 {"UNC File URI 1, with languages", |
| 309 "file:///CONTOSO/accounting/money.xls", |
| 310 "zh-TW,en", |
| 311 L"file:///CONTOSO/accounting/money.xls"}, |
| 312 {"UNC File URI 2", |
| 313 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", |
| 314 "", |
| 315 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, |
| 316 {"UNC File URI 2, with languages", |
| 317 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", |
| 318 "ar-EG", |
| 319 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, |
| 320 {"HTTP URL with path", |
| 321 "http://www.google.com/test.html", |
| 322 "", |
| 323 L"http://www.google.com"}, |
| 324 {"HTTP URL with path, with languages", |
| 325 "http://www.google.com/test.html", |
| 326 "en-US,en,am,zh", |
| 327 L"http://www.google.com"}, |
| 328 {"HTTPS URL with path", |
| 329 "https://www.google.com/test.html", |
| 330 "", |
| 331 L"https://www.google.com"}, |
| 332 {"HTTPS URL with path, with languages", |
| 333 "https://www.google.com/test.html", |
| 334 "en-US,en,am,zh", |
| 335 L"https://www.google.com"}, |
| 336 {"Unusual secure scheme (wss)", |
| 337 "wss://www.google.com/", |
| 338 "", |
| 339 L"wss://www.google.com"}, |
| 340 {"Unusual secure scheme (wss), with languages", |
| 341 "wss://www.google.com/", |
| 342 "en-US,en,am,zh", |
| 343 L"wss://www.google.com"}, |
| 344 {"Unusual non-secure scheme (gopher)", |
| 345 "gopher://www.google.com/", |
| 346 "", |
| 347 L"gopher://www.google.com"}, |
| 348 {"Unusual non-secure scheme (gopher), with languages", |
| 349 "gopher://www.google.com/", |
| 350 "en-US", |
| 351 L"gopher://www.google.com"}, |
| 352 {"Unlisted scheme (chrome)", "chrome://version", "", L"chrome://version"}, |
| 353 {"Unlisted scheme (chrome), with languages", |
| 354 "chrome://version", |
| 355 "en-US,en,am,zh", |
| 356 L"chrome://version"}, |
| 357 {"HTTP IP address", |
| 358 "http://173.194.65.103", |
| 359 "", |
| 360 L"http://173.194.65.103"}, |
| 361 {"HTTP IP address, with languages", |
| 362 "http://173.194.65.103", |
| 363 "en-US,en,am,zh", |
| 364 L"http://173.194.65.103"}, |
| 365 {"HTTPS IP address", |
| 366 "https://173.194.65.103", |
| 367 "", |
| 368 L"https://173.194.65.103"}, |
| 369 {"HTTPS IP address, with languages", |
| 370 "https://173.194.65.103", |
| 371 "en-US,en,am", |
| 372 L"https://173.194.65.103"}, |
| 373 {"HTTP IPv6 address", |
| 374 "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", |
| 375 "", |
| 376 L"http://[fe80::202:b3ff:fe1e:8329]"}, |
| 377 {"HTTP IPv6 address, with languages", |
| 378 "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", |
| 379 "zh", |
| 380 L"http://[fe80::202:b3ff:fe1e:8329]"}, |
| 381 {"HTTPS IPv6 address with port", |
| 382 "https://[2001:db8:0:1]:443/", |
| 383 "", |
| 384 L"https://[2001:db8:0:1]"}, |
| 385 {"HTTPS IPv6 address with port, with languages", |
| 386 "https://[2001:db8:0:1]:443/", |
| 387 "am,zh", |
| 388 L"https://[2001:db8:0:1]"}, |
| 389 {"HTTPS IP address, non-default port", |
| 390 "https://173.194.65.103:8443", |
| 391 "", |
| 392 L"https://173.194.65.103:8443"}, |
| 393 {"HTTPS IP address, non-default port, with languages", |
| 394 "https://173.194.65.103:8443", |
| 395 "en-US,en,am,zh", |
| 396 L"https://173.194.65.103:8443"}, |
| 397 {"HTTP filesystem: URL with path", |
| 398 "filesystem:http://www.google.com/temporary/test.html", |
| 399 "", |
| 400 L"filesystem:http://www.google.com"}, |
| 401 {"HTTP filesystem: URL with path, with languages", |
| 402 "filesystem:http://www.google.com/temporary/test.html", |
| 403 "en-US,en", |
| 404 L"filesystem:http://www.google.com"}, |
| 405 {"File filesystem: URL with path", |
| 406 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", |
| 407 "", |
| 408 L"filesystem:file:///temporary/stuff/test.html"}, |
| 409 {"File filesystem: URL with path, with languages", |
| 410 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", |
| 411 "en-US,en,am,zh", |
| 412 L"filesystem:file:///temporary/stuff/test.html"}, |
| 413 {"Invalid scheme 1", |
| 414 "twelve://www.cyber.org/wow.php", |
| 415 "", |
| 416 L"twelve://www.cyber.org/wow.php"}, |
| 417 {"Invalid scheme 1, with languages", |
| 418 "twelve://www.cyber.org/wow.php", |
| 419 "am,zh", |
| 420 L"twelve://www.cyber.org/wow.php"}, |
| 421 {"Invalid scheme 2", |
| 422 "://www.cyber.org/wow.php", |
| 423 "", |
| 424 L"://www.cyber.org/wow.php"}, |
| 425 {"Invalid scheme 2, with languages", |
| 426 "://www.cyber.org/wow.php", |
| 427 "en-US,zh", |
| 428 L"://www.cyber.org/wow.php"}, |
| 429 {"Invalid host 1", |
| 430 "https://www.cyber../wow.php", |
| 431 "", |
| 432 L"https://www.cyber.."}, |
| 433 {"Invalid host 1, with languages", |
| 434 "https://www.cyber../wow.php", |
| 435 "en-US,en,am", |
| 436 L"https://www.cyber.."}, |
| 437 {"Invalid host 2", |
| 438 "https://www...cyber/wow.php", |
| 439 "", |
| 440 L"https://www...cyber"}, |
| 441 {"Invalid host 2, with languages", |
| 442 "https://www...cyber/wow.php", |
| 443 "en-US,en,am,zh", |
| 444 L"https://www...cyber"}, |
| 445 {"Invalid port 1", |
| 446 "https://173.194.65.103:000", |
| 447 "", |
| 448 L"https://173.194.65.103:0"}, |
| 449 {"Invalid port 1, with languages", |
| 450 "https://173.194.65.103:000", |
| 451 "en-US,en", |
| 452 L"https://173.194.65.103:0"}, |
| 453 {"Invalid port 2", |
| 454 "https://173.194.65.103:gruffle", |
| 455 "", |
| 456 L"https://173.194.65.103:gruffle"}, |
| 457 {"Invalid port 2, with languages", |
| 458 "https://173.194.65.103:gruffle", |
| 459 "fr-FR", |
| 460 L"https://173.194.65.103:gruffle"}, |
| 461 {"Invalid port 3", |
| 462 "https://173.194.65.103:/hello.aspx", |
| 463 "", |
| 464 L"https://173.194.65.103"}, |
| 465 {"Invalid port 3, with languages", |
| 466 "https://173.194.65.103:/hello.aspx", |
| 467 "zh", |
| 468 L"https://173.194.65.103"}, |
| 469 {"Trailing dot in DNS name", |
| 470 "https://www.example.com./get/goat", |
| 471 "", |
| 472 L"https://www.example.com."}, |
| 473 {"Trailing dot in DNS name, with languages", |
| 474 "https://www.example.com./get/goat", |
| 475 "zh", |
| 476 L"https://www.example.com."}, |
| 477 {"Blob URL", |
| 478 "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
| 479 "", |
| 480 L"blob:http%3A//www.html5rocks.com/" |
| 481 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}, |
| 482 {"Blob URL, with languages", |
| 483 "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
| 484 "en-US,zh", |
| 485 L"blob:http%3A//www.html5rocks.com/" |
| 486 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}, |
| 487 }; |
| 488 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 489 base::string16 formatted = |
| 490 FormatUrlForSecurityDisplay(GURL(tests[i].input), tests[i].languages); |
| 491 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) |
| 492 << tests[i].description; |
| 493 } |
| 494 |
| 495 base::string16 formatted = FormatUrlForSecurityDisplay(GURL(), std::string()); |
| 496 EXPECT_EQ(base::string16(), formatted) |
| 497 << "Explicitly test the 0-argument GURL constructor"; |
| 498 } |
| 499 |
207 } // namespace | 500 } // namespace |
OLD | NEW |