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..08a0c8aaf0be93e438bee90166b43c4d3237c72f 100644 |
--- a/chrome/browser/ui/elide_url_unittest.cc |
+++ b/chrome/browser/ui/elide_url_unittest.cc |
@@ -204,4 +204,188 @@ TEST(TextEliderTest, TestHostEliding) { |
ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); |
} |
+struct OriginTestData { |
+ const char* description; |
+ const char* input; |
+ const char* languages; |
msw
2015/05/29 00:18:51
None of the test cases supply languages, can this
palmer
2015/05/29 17:52:13
Done.
|
+ const bool omit_scheme; |
+ const wchar_t* output; |
+}; |
+ |
+TEST(TextEliderTest, FormatOriginForDisplay) { |
+ const OriginTestData tests[] = { |
+ {"Empty URL", "", "", false, L""}, |
+ {"HTTP URL, no omit scheme", |
+ "http://www.google.com/", |
+ "", |
+ false, |
+ L"http://www.google.com"}, |
+ {"HTTP URL, omit scheme", |
+ "http://www.google.com/", |
+ "", |
+ true, |
+ L"www.google.com"}, |
+ {"HTTPS URL, no omit scheme", |
+ "https://www.google.com/", |
+ "", |
+ false, |
+ L"https://www.google.com"}, |
+ {"HTTPS URL, omit scheme", |
+ "https://www.google.com/", |
+ "", |
+ true, |
+ L"www.google.com"}, |
+ {"Standard HTTP port", |
+ "http://www.google.com:80/", |
+ "", |
+ false, |
+ L"http://www.google.com"}, |
+ {"Standard HTTPS port", |
+ "https://www.google.com:443/", |
+ "", |
+ false, |
+ L"https://www.google.com"}, |
+ {"Non-standard HTTP port", |
+ "http://www.google.com:9000/", |
+ "", |
+ false, |
+ L"http://www.google.com:9000"}, |
+ {"Non-standard HTTPS port", |
+ "https://www.google.com:9000/", |
+ "", |
+ false, |
+ L"https://www.google.com:9000"}, |
+ {"File URI, omit scheme", |
+ "file:///usr/example/file.html", |
+ "", |
+ 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 with hostname, omit scheme", |
+ "file://localhost/usr/example/file.html", |
+ "", |
+ 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"}, |
+ {"HTTP URL with path", |
+ "http://www.google.com/test.html", |
+ "", |
+ false, |
+ L"http://www.google.com"}, |
+ {"HTTPS URL with path", |
+ "https://www.google.com/test.html", |
+ "", |
+ false, |
+ L"https://www.google.com"}, |
+ {"Unusual secure scheme (wss)", |
+ "wss://www.google.com/", |
+ "", |
+ false, |
+ L"wss://www.google.com"}, |
+ {"Unusual non-secure scheme (gopher)", |
+ "gopher://www.google.com/", |
+ "", |
+ false, |
+ L"gopher://www.google.com"}, |
+ {"Unlisted scheme (chrome)", |
+ "chrome://version", |
+ "", |
+ false, |
+ L"chrome://version"}, |
+ {"HTTP IP address", |
+ "http://173.194.65.103", |
+ "", |
+ 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, non-default port", |
+ "https://173.194.65.103:8443", |
+ "", |
+ false, |
+ L"https://173.194.65.103:8443"}, |
+ {"HTTPS IP address, omit scheme", |
+ "https://173.194.65.103", |
+ "", |
+ 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, omit scheme", |
+ "filesystem:http://www.google.com/persistent/test.html", |
+ "", |
+ 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, omit scheme", |
+ "filesystem:file://cyber.com/persistent/stuff/test.html?y=z#abc", |
+ "", |
+ 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 2", |
+ "://www.cyber.org/wow.php", |
+ "", |
+ false, |
+ L"://www.cyber.org/wow.php"}, |
+ {"Invalid host 1", |
+ "https://www.cyber../wow.php", |
+ "", |
+ false, |
+ L"https://www.cyber.."}, |
+ {"Invalid host 2", |
+ "https://www...cyber/wow.php", |
+ "", |
+ false, |
+ L"https://www...cyber"}, |
+ {"Invalid port 1", |
+ "https://173.194.65.103:000", |
+ "", |
+ 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 3", |
+ "https://173.194.65.103:/hello.aspx", |
+ "", |
+ 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); |
+ EXPECT_EQ(base::string16(), formatted) |
+ << "Explicitly test the 0-argument GURL constructor"; |
+} |
+ |
} // namespace |