| 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 "components/url_formatter/elide_url.h" | 5 #include "components/url_formatter/elide_url.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 url_formatter::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); | 228 url_formatter::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 #endif // !defined(OS_ANDROID) | 231 #endif // !defined(OS_ANDROID) |
| 232 | 232 |
| 233 TEST(TextEliderTest, FormatUrlForSecurityDisplay) { | 233 TEST(TextEliderTest, FormatUrlForSecurityDisplay) { |
| 234 struct OriginTestData { | 234 struct OriginTestData { |
| 235 const char* const description; | 235 const char* const description; |
| 236 const char* const input; | 236 const char* const input; |
| 237 const wchar_t* const output; | 237 const wchar_t* const output; |
| 238 const wchar_t* const output_omit_scheme; | 238 const wchar_t* const output_omit_web_scheme; |
| 239 const wchar_t* const output_omit_cryptographic_scheme; |
| 239 }; | 240 }; |
| 240 | 241 |
| 241 const OriginTestData tests[] = { | 242 const OriginTestData tests[] = { |
| 242 {"Empty URL", "", L"", L""}, | 243 {"Empty URL", "", L"", L"", L""}, |
| 243 {"HTTP URL", "http://www.google.com/", L"http://www.google.com", | 244 {"HTTP URL", "http://www.google.com/", L"http://www.google.com", |
| 244 L"www.google.com"}, | 245 L"www.google.com", L"http://www.google.com"}, |
| 245 {"HTTPS URL", "https://www.google.com/", L"https://www.google.com", | 246 {"HTTPS URL", "https://www.google.com/", L"https://www.google.com", |
| 246 L"www.google.com"}, | 247 L"www.google.com", L"www.google.com"}, |
| 247 {"Standard HTTP port", "http://www.google.com:80/", | 248 {"Standard HTTP port", "http://www.google.com:80/", |
| 248 L"http://www.google.com", L"www.google.com"}, | 249 L"http://www.google.com", L"www.google.com", L"http://www.google.com"}, |
| 249 {"Standard HTTPS port", "https://www.google.com:443/", | 250 {"Standard HTTPS port", "https://www.google.com:443/", |
| 250 L"https://www.google.com", L"www.google.com"}, | 251 L"https://www.google.com", L"www.google.com", L"www.google.com"}, |
| 251 {"Standard HTTP port, IDN Chinese", | 252 {"Standard HTTP port, IDN Chinese", |
| 252 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80", | 253 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80", |
| 253 L"http://xn--fiqs8s.icom.museum", L"xn--fiqs8s.icom.museum"}, | 254 L"http://xn--fiqs8s.icom.museum", L"xn--fiqs8s.icom.museum", |
| 255 L"http://xn--fiqs8s.icom.museum"}, |
| 254 {"HTTP URL, IDN Hebrew (RTL)", | 256 {"HTTP URL, IDN Hebrew (RTL)", |
| 255 "http://" | 257 "http://" |
| 256 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d." | 258 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d." |
| 257 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/", | 259 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/", |
| 258 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum", | 260 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum", |
| 259 L"xn--4dbklr2c8d.xn--4dbrk0ce.museum"}, | 261 L"xn--4dbklr2c8d.xn--4dbrk0ce.museum", |
| 262 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"}, |
| 260 {"HTTP URL with query string, IDN Arabic (RTL)", | 263 {"HTTP URL with query string, IDN Arabic (RTL)", |
| 261 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no", | 264 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no", |
| 262 L"http://xn--wgbh1c.icom.museum", L"xn--wgbh1c.icom.museum"}, | 265 L"http://xn--wgbh1c.icom.museum", L"xn--wgbh1c.icom.museum", |
| 266 L"http://xn--wgbh1c.icom.museum"}, |
| 263 {"Non-standard HTTP port", "http://www.google.com:9000/", | 267 {"Non-standard HTTP port", "http://www.google.com:9000/", |
| 264 L"http://www.google.com:9000", L"www.google.com:9000"}, | 268 L"http://www.google.com:9000", L"www.google.com:9000", |
| 269 L"http://www.google.com:9000"}, |
| 265 {"Non-standard HTTPS port", "https://www.google.com:9000/", | 270 {"Non-standard HTTPS port", "https://www.google.com:9000/", |
| 266 L"https://www.google.com:9000", L"www.google.com:9000"}, | 271 L"https://www.google.com:9000", L"www.google.com:9000", |
| 272 L"www.google.com:9000"}, |
| 267 {"File URI", "file:///usr/example/file.html", | 273 {"File URI", "file:///usr/example/file.html", |
| 268 L"file:///usr/example/file.html", L"file:///usr/example/file.html"}, | 274 L"file:///usr/example/file.html", L"file:///usr/example/file.html", |
| 275 L"file:///usr/example/file.html"}, |
| 269 {"File URI with hostname", "file://localhost/usr/example/file.html", | 276 {"File URI with hostname", "file://localhost/usr/example/file.html", |
| 270 L"file:///usr/example/file.html", L"file:///usr/example/file.html"}, | 277 L"file:///usr/example/file.html", L"file:///usr/example/file.html", |
| 278 L"file:///usr/example/file.html"}, |
| 271 {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls", | 279 {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls", |
| 272 L"file:///CONTOSO/accounting/money.xls", | 280 L"file:///CONTOSO/accounting/money.xls", |
| 281 L"file:///CONTOSO/accounting/money.xls", |
| 273 L"file:///CONTOSO/accounting/money.xls"}, | 282 L"file:///CONTOSO/accounting/money.xls"}, |
| 274 {"UNC File URI 2", | 283 {"UNC File URI 2", |
| 275 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", | 284 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", |
| 276 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html", | 285 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html", |
| 286 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html", |
| 277 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, | 287 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, |
| 278 {"HTTP URL with path", "http://www.google.com/test.html", | 288 {"HTTP URL with path", "http://www.google.com/test.html", |
| 279 L"http://www.google.com", L"www.google.com"}, | 289 L"http://www.google.com", L"www.google.com", L"http://www.google.com"}, |
| 280 {"HTTPS URL with path", "https://www.google.com/test.html", | 290 {"HTTPS URL with path", "https://www.google.com/test.html", |
| 281 L"https://www.google.com", L"www.google.com"}, | 291 L"https://www.google.com", L"www.google.com", L"www.google.com"}, |
| 282 {"Unusual secure scheme (wss)", "wss://www.google.com/", | 292 {"Unusual secure scheme (wss)", "wss://www.google.com/", |
| 283 L"wss://www.google.com", L"wss://www.google.com"}, | 293 L"wss://www.google.com", L"wss://www.google.com", L"www.google.com"}, |
| 284 {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/", | 294 {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/", |
| 285 L"gopher://www.google.com", L"gopher://www.google.com"}, | 295 L"gopher://www.google.com", L"gopher://www.google.com", |
| 296 L"gopher://www.google.com"}, |
| 286 {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version", | 297 {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version", |
| 287 L"chrome://version"}, | 298 L"chrome://version", L"chrome://version"}, |
| 288 {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103", | 299 {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103", |
| 289 L"173.194.65.103"}, | 300 L"173.194.65.103", L"http://173.194.65.103"}, |
| 290 {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103", | 301 {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103", |
| 291 L"173.194.65.103"}, | 302 L"173.194.65.103", L"173.194.65.103"}, |
| 292 {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", | 303 {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", |
| 293 L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]"}, | 304 L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]", |
| 294 {"HTTPS IPv6 address with port", "https://[2001:db8:0:1]:443/", | 305 L"http://[fe80::202:b3ff:fe1e:8329]"}, |
| 295 L"https://[2001:db8:0:1]", L"https://[2001:db8:0:1]"}, | 306 {"HTTPs IPv6 address", |
| 307 "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", |
| 308 L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]", |
| 309 L"[fe80::202:b3ff:fe1e:8329]"}, |
| 310 {"HTTP IPv6 address with port", |
| 311 "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:80/", |
| 312 L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]", |
| 313 L"http://[fe80::202:b3ff:fe1e:8329]"}, |
| 314 {"HTTPs IPv6 address with port", |
| 315 "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:443/", |
| 316 L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]", |
| 317 L"[fe80::202:b3ff:fe1e:8329]"}, |
| 318 {"Invalid IPv6 address", "https://[2001:db8:0:1]/", |
| 319 L"https://[2001:db8:0:1]", L"https://[2001:db8:0:1]", |
| 320 L"https://[2001:db8:0:1]"}, |
| 296 {"HTTPS IP address, non-default port", "https://173.194.65.103:8443", | 321 {"HTTPS IP address, non-default port", "https://173.194.65.103:8443", |
| 297 L"https://173.194.65.103:8443", L"173.194.65.103:8443"}, | 322 L"https://173.194.65.103:8443", L"173.194.65.103:8443", |
| 323 L"173.194.65.103:8443"}, |
| 298 {"HTTP filesystem: URL with path", | 324 {"HTTP filesystem: URL with path", |
| 299 "filesystem:http://www.google.com/temporary/test.html", | 325 "filesystem:http://www.google.com/temporary/test.html", |
| 300 L"filesystem:http://www.google.com", | 326 L"filesystem:http://www.google.com", L"filesystem:http://www.google.com", |
| 301 L"filesystem:http://www.google.com"}, | 327 L"filesystem:http://www.google.com"}, |
| 302 {"File filesystem: URL with path", | 328 {"File filesystem: URL with path", |
| 303 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", | 329 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", |
| 304 L"filesystem:file:///temporary/stuff/test.html", | 330 L"filesystem:file:///temporary/stuff/test.html", |
| 331 L"filesystem:file:///temporary/stuff/test.html", |
| 305 L"filesystem:file:///temporary/stuff/test.html"}, | 332 L"filesystem:file:///temporary/stuff/test.html"}, |
| 306 {"Invalid scheme 1", "twelve://www.cyber.org/wow.php", | 333 {"Invalid scheme 1", "twelve://www.cyber.org/wow.php", |
| 307 L"twelve://www.cyber.org/wow.php", L"twelve://www.cyber.org/wow.php"}, | 334 L"twelve://www.cyber.org/wow.php", L"twelve://www.cyber.org/wow.php", |
| 335 L"twelve://www.cyber.org/wow.php"}, |
| 308 {"Invalid scheme 2", "://www.cyber.org/wow.php", | 336 {"Invalid scheme 2", "://www.cyber.org/wow.php", |
| 309 L"://www.cyber.org/wow.php", L"://www.cyber.org/wow.php"}, | 337 L"://www.cyber.org/wow.php", L"://www.cyber.org/wow.php", |
| 338 L"://www.cyber.org/wow.php"}, |
| 310 {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber..", | 339 {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber..", |
| 311 L"www.cyber.."}, | 340 L"www.cyber..", L"www.cyber.."}, |
| 312 {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber", | 341 {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber", |
| 313 L"www...cyber"}, | 342 L"www...cyber", L"www...cyber"}, |
| 314 {"Invalid port 1", "https://173.194.65.103:000", | 343 {"Invalid port 1", "https://173.194.65.103:000", |
| 315 L"https://173.194.65.103:0", L"173.194.65.103:0"}, | 344 L"https://173.194.65.103:0", L"173.194.65.103:0", L"173.194.65.103:0"}, |
| 316 {"Invalid port 2", "https://173.194.65.103:gruffle", | 345 {"Invalid port 2", "https://173.194.65.103:gruffle", |
| 317 L"https://173.194.65.103:gruffle", L"https://173.194.65.103:gruffle"}, | 346 L"https://173.194.65.103:gruffle", L"https://173.194.65.103:gruffle", |
| 347 L"https://173.194.65.103:gruffle"}, |
| 318 {"Invalid port 3", "https://173.194.65.103:/hello.aspx", | 348 {"Invalid port 3", "https://173.194.65.103:/hello.aspx", |
| 319 L"https://173.194.65.103", L"173.194.65.103"}, | 349 L"https://173.194.65.103", L"173.194.65.103", L"173.194.65.103"}, |
| 320 {"Trailing dot in DNS name", "https://www.example.com./get/goat", | 350 {"Trailing dot in DNS name", "https://www.example.com./get/goat", |
| 321 L"https://www.example.com.", L"www.example.com."}, | 351 L"https://www.example.com.", L"www.example.com.", L"www.example.com."}, |
| 322 {"Blob URL", | 352 {"Blob URL", |
| 323 "blob:http://www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", | 353 "blob:http://www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
| 324 L"blob:http://www.html5rocks.com/" | 354 L"blob:http://www.html5rocks.com/" |
| 325 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9", | 355 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
| 326 L"blob:http://www.html5rocks.com/" | 356 L"blob:http://www.html5rocks.com/" |
| 357 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
| 358 L"blob:http://www.html5rocks.com/" |
| 327 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}}; | 359 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}}; |
| 328 | 360 |
| 329 for (size_t i = 0; i < arraysize(tests); ++i) { | 361 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 330 base::string16 formatted = | 362 base::string16 formatted = |
| 331 url_formatter::FormatUrlForSecurityDisplay(GURL(tests[i].input)); | 363 url_formatter::FormatUrlForSecurityDisplay(GURL(tests[i].input)); |
| 332 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) | 364 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) |
| 333 << tests[i].description; | 365 << tests[i].description; |
| 334 | 366 |
| 335 base::string16 formatted_omit_scheme = | 367 base::string16 formatted_omit_web_scheme = |
| 336 url_formatter::FormatUrlForSecurityDisplayOmitScheme( | 368 url_formatter::FormatUrlForSecurityDisplay( |
| 337 GURL(tests[i].input)); | 369 GURL(tests[i].input), |
| 338 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_scheme), | 370 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); |
| 339 formatted_omit_scheme) | 371 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_web_scheme), |
| 372 formatted_omit_web_scheme) |
| 373 << tests[i].description; |
| 374 |
| 375 base::string16 formatted_omit_cryptographic_scheme = |
| 376 url_formatter::FormatUrlForSecurityDisplay( |
| 377 GURL(tests[i].input), |
| 378 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); |
| 379 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_cryptographic_scheme), |
| 380 formatted_omit_cryptographic_scheme) |
| 340 << tests[i].description; | 381 << tests[i].description; |
| 341 } | 382 } |
| 342 | 383 |
| 343 base::string16 formatted = | 384 base::string16 formatted = |
| 344 url_formatter::FormatUrlForSecurityDisplay(GURL()); | 385 url_formatter::FormatUrlForSecurityDisplay(GURL()); |
| 345 EXPECT_EQ(base::string16(), formatted) | 386 EXPECT_EQ(base::string16(), formatted) |
| 346 << "Explicitly test the 0-argument GURL constructor"; | 387 << "Explicitly test the 0-argument GURL constructor"; |
| 347 | 388 |
| 348 base::string16 formatted_omit_scheme = | 389 base::string16 formatted_omit_scheme = |
| 349 url_formatter::FormatUrlForSecurityDisplayOmitScheme(GURL()); | 390 url_formatter::FormatUrlForSecurityDisplay( |
| 391 GURL(), url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); |
| 392 EXPECT_EQ(base::string16(), formatted_omit_scheme) |
| 393 << "Explicitly test the 0-argument GURL constructor"; |
| 394 |
| 395 formatted_omit_scheme = url_formatter::FormatUrlForSecurityDisplay( |
| 396 GURL(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); |
| 350 EXPECT_EQ(base::string16(), formatted_omit_scheme) | 397 EXPECT_EQ(base::string16(), formatted_omit_scheme) |
| 351 << "Explicitly test the 0-argument GURL constructor"; | 398 << "Explicitly test the 0-argument GURL constructor"; |
| 352 } | 399 } |
| 353 | 400 |
| 354 } // namespace | 401 } // namespace |
| OLD | NEW |