Index: chrome/browser/ui/elide_url_unittest.cc |
diff --git a/chrome/browser/ui/elide_url_unittest.cc b/chrome/browser/ui/elide_url_unittest.cc |
index a2cec9e82b490b05b77a266ea77b8a3d874592a7..8ee30a26ef796d45922d680bf5a4f2ad987ed805 100644 |
--- a/chrome/browser/ui/elide_url_unittest.cc |
+++ b/chrome/browser/ui/elide_url_unittest.cc |
@@ -204,4 +204,344 @@ TEST(TextEliderTest, TestHostEliding) { |
ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); |
} |
+struct OriginTestData { |
+ const char* description; |
+ const char* input; |
+ const char* languages; |
+ const bool omit_scheme; |
+ const wchar_t* output; |
+}; |
+ |
+TEST(TextEliderTest, FormatOriginForDisplay) { |
+ const OriginTestData tests[] = { |
Ryan Sleevi
2015/05/29 18:28:31
Suggestions:
1) Add IDN test cases
2) Add IPv6 te
palmer
2015/05/29 20:40:10
Done.
|
+ {"Empty URL", "", "", false, L""}, |
+ {"Empty URL with languages", "", "en-US,zh-TW,zh", false, L""}, |
+ {"HTTP URL, no omit scheme", |
+ "http://www.google.com/", |
+ "", |
+ false, |
+ L"http://www.google.com"}, |
+ {"HTTP URL, no omit scheme, with languages", |
+ "http://www.google.com/", |
+ "en-US,en,am", |
+ false, |
+ L"http://www.google.com"}, |
+ {"HTTP URL, omit scheme", |
+ "http://www.google.com/", |
+ "", |
+ true, |
+ L"www.google.com"}, |
+ {"HTTP URL, omit scheme, with languages", |
+ "http://www.google.com/", |
+ "en-US,en,am,es-MX", |
+ true, |
+ L"www.google.com"}, |
+ {"HTTPS URL, no omit scheme", |
+ "https://www.google.com/", |
+ "", |
+ false, |
+ L"https://www.google.com"}, |
+ {"HTTPS URL, no omit scheme, with languages", |
+ "https://www.google.com/", |
+ "en-US,en,am,zh", |
+ false, |
+ L"https://www.google.com"}, |
+ {"HTTPS URL, omit scheme", |
+ "https://www.google.com/", |
+ "", |
+ true, |
+ L"www.google.com"}, |
+ {"HTTPS URL, omit scheme, with languages", |
+ "https://www.google.com/", |
+ "en-US,en,am,zh-TW", |
+ true, |
+ L"www.google.com"}, |
+ {"Standard HTTP port", |
+ "http://www.google.com:80/", |
+ "", |
+ false, |
+ L"http://www.google.com"}, |
+ {"Standard HTTP port, with languages", |
+ "http://www.google.com:80/", |
+ "en-US,en,am,zh", |
+ false, |
+ L"http://www.google.com"}, |
+ {"Standard HTTPS port", |
+ "https://www.google.com:443/", |
+ "", |
+ false, |
+ L"https://www.google.com"}, |
+ {"Standard HTTPS port, with languages", |
+ "https://www.google.com:443/", |
+ "en-US,en,am,zh-TW", |
+ false, |
+ L"https://www.google.com"}, |
+ {"Non-standard HTTP port", |
+ "http://www.google.com:9000/", |
+ "", |
+ false, |
+ L"http://www.google.com:9000"}, |
+ {"Non-standard HTTP port, with languages", |
+ "http://www.google.com:9000/", |
+ "en-US,en,am,zh", |
+ false, |
+ L"http://www.google.com:9000"}, |
+ {"Non-standard HTTPS port", |
+ "https://www.google.com:9000/", |
+ "", |
+ false, |
+ L"https://www.google.com:9000"}, |
+ {"Non-standard HTTPS port, with languages", |
+ "https://www.google.com:9000/", |
+ "en,am", |
+ false, |
+ L"https://www.google.com:9000"}, |
+ {"File URI, omit scheme", |
+ "file:///usr/example/file.html", |
+ "", |
+ true, |
+ L"/usr/example/file.html"}, |
+ {"File URI, omit scheme, with languages", |
+ "file:///usr/example/file.html", |
+ "zh", |
+ true, |
+ L"/usr/example/file.html"}, |
+ {"File URI, no omit scheme", |
+ "file:///usr/example/file.html", |
+ "", |
+ false, |
+ L"file:///usr/example/file.html"}, |
+ {"File URI, no omit scheme, with languages", |
+ "file:///usr/example/file.html", |
+ "en-US,en,zh", |
+ false, |
+ L"file:///usr/example/file.html"}, |
+ {"File URI with hostname, omit scheme", |
+ "file://localhost/usr/example/file.html", |
+ "", |
+ true, |
+ L"/usr/example/file.html"}, |
+ {"File URI with hostname, omit scheme, with languages", |
+ "file://localhost/usr/example/file.html", |
+ "en-US,en,am,zh", |
+ true, |
+ L"/usr/example/file.html"}, |
+ {"File URI with hostname, no omit scheme", |
+ "file://localhost/usr/example/file.html", |
+ "", |
+ false, |
+ L"file:///usr/example/file.html"}, |
+ {"File URI with hostname, no omit scheme, with languages", |
+ "file://localhost/usr/example/file.html", |
brettw
2015/05/29 20:12:16
As Ryan mentioned, we should worry about UNC filen
palmer
2015/05/29 20:40:10
I agree, if hostnames count as part of the origin
|
+ "en-US,zh", |
+ false, |
+ L"file:///usr/example/file.html"}, |
+ {"HTTP URL with path", |
+ "http://www.google.com/test.html", |
+ "", |
+ false, |
+ L"http://www.google.com"}, |
+ {"HTTP URL with path, with languages", |
+ "http://www.google.com/test.html", |
+ "en-US,en,am,zh", |
+ false, |
+ L"http://www.google.com"}, |
+ {"HTTPS URL with path", |
+ "https://www.google.com/test.html", |
+ "", |
+ false, |
+ L"https://www.google.com"}, |
+ {"HTTPS URL with path, with languages", |
+ "https://www.google.com/test.html", |
+ "en-US,en,am,zh", |
+ false, |
+ L"https://www.google.com"}, |
+ {"Unusual secure scheme (wss)", |
+ "wss://www.google.com/", |
+ "", |
+ false, |
+ L"wss://www.google.com"}, |
+ {"Unusual secure scheme (wss), with languages", |
+ "wss://www.google.com/", |
+ "en-US,en,am,zh", |
+ false, |
+ L"wss://www.google.com"}, |
+ {"Unusual non-secure scheme (gopher)", |
+ "gopher://www.google.com/", |
+ "", |
+ false, |
+ L"gopher://www.google.com"}, |
+ {"Unusual non-secure scheme (gopher), with languages", |
+ "gopher://www.google.com/", |
+ "en-US", |
+ false, |
+ L"gopher://www.google.com"}, |
+ {"Unlisted scheme (chrome)", |
+ "chrome://version", |
+ "", |
+ false, |
+ L"chrome://version"}, |
+ {"Unlisted scheme (chrome), with languages", |
+ "chrome://version", |
+ "en-US,en,am,zh", |
+ false, |
+ L"chrome://version"}, |
+ {"HTTP IP address", |
+ "http://173.194.65.103", |
+ "", |
+ false, |
+ L"http://173.194.65.103"}, |
+ {"HTTP IP address, with languages", |
+ "http://173.194.65.103", |
+ "en-US,en,am,zh", |
+ false, |
+ L"http://173.194.65.103"}, |
+ {"HTTPS IP address", |
+ "https://173.194.65.103", |
+ "", |
+ false, |
+ L"https://173.194.65.103"}, |
+ {"HTTPS IP address, with languages", |
+ "https://173.194.65.103", |
+ "en-US,en,am", |
+ false, |
+ L"https://173.194.65.103"}, |
+ {"HTTPS IP address, non-default port, with languages", |
+ "https://173.194.65.103:8443", |
+ "en-US,en,am,zh", |
felt
2015/05/29 18:31:02
thought:
I think it's important to test this with
palmer
2015/05/29 20:40:10
Done.
|
+ false, |
+ L"https://173.194.65.103:8443"}, |
+ {"HTTPS IP address, omit scheme", |
+ "https://173.194.65.103", |
+ "", |
+ true, |
+ L"173.194.65.103"}, |
+ {"HTTPS IP address, omit scheme, with languages", |
+ "https://173.194.65.103", |
+ "en-US,en,zh", |
+ true, |
+ L"173.194.65.103"}, |
+ {"HTTP filesystem: URL with path", |
+ "filesystem:http://www.google.com/temporary/test.html", |
+ "", |
+ false, |
+ L"filesystem:http://www.google.com"}, |
+ {"HTTP filesystem: URL with path, with languages", |
+ "filesystem:http://www.google.com/temporary/test.html", |
+ "en-US,en", |
+ false, |
+ L"filesystem:http://www.google.com"}, |
+ {"HTTP filesystem: URL with path, omit scheme", |
+ "filesystem:http://www.google.com/persistent/test.html", |
+ "", |
+ true, |
+ L"filesystem:www.google.com"}, |
+ {"HTTP filesystem: URL with path, omit scheme, with languages", |
+ "filesystem:http://www.google.com/persistent/test.html", |
+ "en-US,en,am,zh", |
+ true, |
+ L"filesystem:www.google.com"}, |
+ {"File filesystem: URL with path", |
+ "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", |
+ "", |
+ false, |
+ L"filesystem:file:///temporary/stuff/test.html"}, |
+ {"File filesystem: URL with path, with languages", |
+ "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", |
+ "en-US,en,am,zh", |
+ false, |
+ L"filesystem:file:///temporary/stuff/test.html"}, |
+ {"File filesystem: URL with path, omit scheme", |
+ "filesystem:file://cyber.com/persistent/stuff/test.html?y=z#abc", |
+ "", |
+ true, |
+ L"filesystem:/persistent/stuff/test.html"}, |
+ {"File filesystem: URL with path, omit scheme, with languages", |
+ "filesystem:file://cyber.com/persistent/stuff/test.html?y=z#abc", |
+ "en-US,en,am", |
+ true, |
+ L"filesystem:/persistent/stuff/test.html"}, |
+ {"Invalid scheme 1", |
+ "twelve://www.cyber.org/wow.php", |
+ "", |
+ false, |
+ L"twelve://www.cyber.org/wow.php"}, |
+ {"Invalid scheme 1, with languages", |
+ "twelve://www.cyber.org/wow.php", |
+ "am,zh", |
+ false, |
+ L"twelve://www.cyber.org/wow.php"}, |
+ {"Invalid scheme 2", |
+ "://www.cyber.org/wow.php", |
+ "", |
+ false, |
+ L"://www.cyber.org/wow.php"}, |
+ {"Invalid scheme 2, with languages", |
+ "://www.cyber.org/wow.php", |
+ "en-US,zh", |
+ false, |
+ L"://www.cyber.org/wow.php"}, |
+ {"Invalid host 1", |
+ "https://www.cyber../wow.php", |
+ "", |
+ false, |
+ L"https://www.cyber.."}, |
+ {"Invalid host 1, with languages", |
+ "https://www.cyber../wow.php", |
+ "en-US,en,am", |
+ false, |
+ L"https://www.cyber.."}, |
+ {"Invalid host 2", |
+ "https://www...cyber/wow.php", |
+ "", |
+ false, |
+ L"https://www...cyber"}, |
+ {"Invalid host 2, with languages", |
+ "https://www...cyber/wow.php", |
+ "en-US,en,am,zh", |
+ false, |
+ L"https://www...cyber"}, |
+ {"Invalid port 1", |
+ "https://173.194.65.103:000", |
+ "", |
+ false, |
+ L"https://173.194.65.103"}, |
+ {"Invalid port 1, with languages", |
+ "https://173.194.65.103:000", |
+ "en-US,en", |
+ false, |
+ L"https://173.194.65.103"}, |
+ {"Invalid port 2", |
+ "https://173.194.65.103:gruffle", |
+ "", |
+ false, |
+ L"https://173.194.65.103:gruffle"}, |
+ {"Invalid port 2, with languages", |
+ "https://173.194.65.103:gruffle", |
+ "fr-FR", |
+ false, |
+ L"https://173.194.65.103:gruffle"}, |
+ {"Invalid port 3", |
+ "https://173.194.65.103:/hello.aspx", |
+ "", |
+ false, |
+ L"https://173.194.65.103"}, |
+ {"Invalid port 3, with languages", |
+ "https://173.194.65.103:/hello.aspx", |
+ "zh", |
+ false, |
+ L"https://173.194.65.103"}, |
+ }; |
+ for (size_t i = 0; i < arraysize(tests); ++i) { |
+ base::string16 formatted = FormatOriginForDisplay( |
+ GURL(tests[i].input), tests[i].languages, tests[i].omit_scheme); |
+ EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) |
+ << tests[i].description; |
+ } |
+ |
+ base::string16 formatted = FormatOriginForDisplay(GURL(), "", false); |
Ryan Sleevi
2015/05/29 18:28:31
nit: std::string() is preferred over "" (it's slig
palmer
2015/05/29 20:40:10
Done.
|
+ EXPECT_EQ(base::string16(), formatted) |
+ << "Explicitly test the 0-argument GURL constructor"; |
+} |
+ |
} // namespace |