| 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..811a46d2dea9f9aee757733da04cda845d997ffe 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,175 @@ 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"},
|
| + {"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(WideToUTF16(tests[i].output), formatted) << tests[i].description;
|
| + }
|
| +}
|
| +
|
| } // namespace net
|
|
|