Chromium Code Reviews| Index: net/base/net_util_icu_unittest.cc |
| diff --git a/net/base/net_util_icu_unittest.cc b/net/base/net_util_icu_unittest.cc |
| index 1b315c297c45edcb773d884c058208d3c9991aed..61884e560dca401de783e558470590b0aa5d8e84 100644 |
| --- a/net/base/net_util_icu_unittest.cc |
| +++ b/net/base/net_util_icu_unittest.cc |
| @@ -364,6 +364,14 @@ struct UrlTestData { |
| size_t prefix_len; |
| }; |
| +struct OriginTestData { |
| + const char* description; |
| + const char* input; |
| + const char* languages; |
| + const bool omit_scheme; |
| + const wchar_t* output; |
| +}; |
| + |
| // A helper for IDN*{Fast,Slow}. |
| // Append "::<language list>" to |expected| and |actual| to make it |
| // easy to tell which sub-case fails without debugging. |
| @@ -1081,4 +1089,120 @@ TEST(NetUtilTest, FormatUrlWithOffsets) { |
| UnescapeRule::NORMAL, omit_all_offsets); |
| } |
| +TEST(NetUtilTest, 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"}, |
| + {"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/test.html", |
| + "", |
| + false, |
| + L"filesystem:http://www.google.com"}, |
|
asanka
2015/05/11 23:39:44
Nit: filesystem URIs are of the form filesystem:<o
palmer
2015/05/12 22:20:53
Done.
|
| + {"HTTP filesystem: URL with path, omit scheme", |
| + "filesystem:http://www.google.com/test.html", |
| + "", |
| + true, |
| + L"filesystem:www.google.com"}, |
| + }; |
|
asanka
2015/05/11 23:39:44
Do you want to test how the code behaves with inva
palmer
2015/05/12 22:20:53
I added some, but I am not sure if it really helps
|
| + 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(WideToUTF16(tests[i].output), formatted) << tests[i].description; |
| + } |
| +} |
| + |
| } // namespace net |