| Index: components/url_formatter/elide_url_unittest.cc
|
| diff --git a/components/url_formatter/elide_url_unittest.cc b/components/url_formatter/elide_url_unittest.cc
|
| index db7f5e634086a806831d86e6e62dbc2001ae1b23..e251e003ceac8a7dab107aa63701d3659ed5bdd9 100644
|
| --- a/components/url_formatter/elide_url_unittest.cc
|
| +++ b/components/url_formatter/elide_url_unittest.cc
|
| @@ -12,6 +12,7 @@
|
| #include "build/build_config.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
| +#include "url/origin.h"
|
|
|
| #if !defined(OS_ANDROID)
|
| #include "ui/gfx/font_list.h" // nogncheck
|
| @@ -230,46 +231,114 @@ TEST(TextEliderTest, TestHostEliding) {
|
|
|
| #endif // !defined(OS_ANDROID)
|
|
|
| +struct OriginTestData {
|
| + const char* const description;
|
| + const char* const input;
|
| + const wchar_t* const output;
|
| + const wchar_t* const output_omit_web_scheme;
|
| + const wchar_t* const output_omit_cryptographic_scheme;
|
| +};
|
| +
|
| +// Common test data for both FormatUrlForSecurityDisplay() and
|
| +// FormatOriginForSecurityDisplay()
|
| +const OriginTestData common_tests[] = {
|
| + {"Empty URL", "", L"", L"", L""},
|
| + {"HTTP URL", "http://www.google.com/", L"http://www.google.com",
|
| + L"www.google.com", L"http://www.google.com"},
|
| + {"HTTPS URL", "https://www.google.com/", L"https://www.google.com",
|
| + L"www.google.com", L"www.google.com"},
|
| + {"Standard HTTP port", "http://www.google.com:80/",
|
| + L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
|
| + {"Standard HTTPS port", "https://www.google.com:443/",
|
| + L"https://www.google.com", L"www.google.com", L"www.google.com"},
|
| + {"Standard HTTP port, IDN Chinese",
|
| + "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80",
|
| + L"http://xn--fiqs8s.icom.museum", L"xn--fiqs8s.icom.museum",
|
| + L"http://xn--fiqs8s.icom.museum"},
|
| + {"HTTP URL, IDN Hebrew (RTL)",
|
| + "http://"
|
| + "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d."
|
| + "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/",
|
| + L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum",
|
| + L"xn--4dbklr2c8d.xn--4dbrk0ce.museum",
|
| + L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"},
|
| + {"HTTP URL with query string, IDN Arabic (RTL)",
|
| + "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no",
|
| + L"http://xn--wgbh1c.icom.museum", L"xn--wgbh1c.icom.museum",
|
| + L"http://xn--wgbh1c.icom.museum"},
|
| + {"Non-standard HTTP port", "http://www.google.com:9000/",
|
| + L"http://www.google.com:9000", L"www.google.com:9000",
|
| + L"http://www.google.com:9000"},
|
| + {"Non-standard HTTPS port", "https://www.google.com:9000/",
|
| + L"https://www.google.com:9000", L"www.google.com:9000",
|
| + L"www.google.com:9000"},
|
| + {"HTTP URL with path", "http://www.google.com/test.html",
|
| + L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
|
| + {"HTTPS URL with path", "https://www.google.com/test.html",
|
| + L"https://www.google.com", L"www.google.com", L"www.google.com"},
|
| + {"Unusual secure scheme (wss)", "wss://www.google.com/",
|
| + L"wss://www.google.com", L"wss://www.google.com", L"www.google.com"},
|
| + {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/",
|
| + L"gopher://www.google.com", L"gopher://www.google.com",
|
| + L"gopher://www.google.com"},
|
| + {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version",
|
| + L"chrome://version", L"chrome://version"},
|
| + {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103",
|
| + L"173.194.65.103", L"http://173.194.65.103"},
|
| + {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103",
|
| + L"173.194.65.103", L"173.194.65.103"},
|
| + {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
|
| + L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
|
| + L"http://[fe80::202:b3ff:fe1e:8329]"},
|
| + {"HTTPs IPv6 address", "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
|
| + L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
|
| + L"[fe80::202:b3ff:fe1e:8329]"},
|
| + {"HTTP IPv6 address with port",
|
| + "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:80/",
|
| + L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
|
| + L"http://[fe80::202:b3ff:fe1e:8329]"},
|
| + {"HTTPs IPv6 address with port",
|
| + "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:443/",
|
| + L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
|
| + L"[fe80::202:b3ff:fe1e:8329]"},
|
| + {"HTTPS IP address, non-default port", "https://173.194.65.103:8443",
|
| + L"https://173.194.65.103:8443", L"173.194.65.103:8443",
|
| + L"173.194.65.103:8443"},
|
| + {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber..",
|
| + L"www.cyber..", L"www.cyber.."},
|
| + {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber",
|
| + L"www...cyber", L"www...cyber"},
|
| + {"Invalid port 3", "https://173.194.65.103:/hello.aspx",
|
| + L"https://173.194.65.103", L"173.194.65.103", L"173.194.65.103"},
|
| + {"Trailing dot in DNS name", "https://www.example.com./get/goat",
|
| + L"https://www.example.com.", L"www.example.com.", L"www.example.com."}};
|
| +
|
| TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
|
| - struct OriginTestData {
|
| - const char* const description;
|
| - const char* const input;
|
| - const wchar_t* const output;
|
| - const wchar_t* const output_omit_web_scheme;
|
| - const wchar_t* const output_omit_cryptographic_scheme;
|
| - };
|
| + for (size_t i = 0; i < arraysize(common_tests); ++i) {
|
| + base::string16 formatted =
|
| + url_formatter::FormatUrlForSecurityDisplay(GURL(common_tests[i].input));
|
| + EXPECT_EQ(base::WideToUTF16(common_tests[i].output), formatted)
|
| + << common_tests[i].description;
|
| +
|
| + base::string16 formatted_omit_web_scheme =
|
| + url_formatter::FormatUrlForSecurityDisplay(
|
| + GURL(common_tests[i].input),
|
| + url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
|
| + EXPECT_EQ(base::WideToUTF16(common_tests[i].output_omit_web_scheme),
|
| + formatted_omit_web_scheme)
|
| + << common_tests[i].description;
|
| +
|
| + base::string16 formatted_omit_cryptographic_scheme =
|
| + url_formatter::FormatUrlForSecurityDisplay(
|
| + GURL(common_tests[i].input),
|
| + url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
|
| + EXPECT_EQ(
|
| + base::WideToUTF16(common_tests[i].output_omit_cryptographic_scheme),
|
| + formatted_omit_cryptographic_scheme)
|
| + << common_tests[i].description;
|
| + }
|
|
|
| const OriginTestData tests[] = {
|
| - {"Empty URL", "", L"", L"", L""},
|
| - {"HTTP URL", "http://www.google.com/", L"http://www.google.com",
|
| - L"www.google.com", L"http://www.google.com"},
|
| - {"HTTPS URL", "https://www.google.com/", L"https://www.google.com",
|
| - L"www.google.com", L"www.google.com"},
|
| - {"Standard HTTP port", "http://www.google.com:80/",
|
| - L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
|
| - {"Standard HTTPS port", "https://www.google.com:443/",
|
| - L"https://www.google.com", L"www.google.com", L"www.google.com"},
|
| - {"Standard HTTP port, IDN Chinese",
|
| - "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80",
|
| - L"http://xn--fiqs8s.icom.museum", L"xn--fiqs8s.icom.museum",
|
| - L"http://xn--fiqs8s.icom.museum"},
|
| - {"HTTP URL, IDN Hebrew (RTL)",
|
| - "http://"
|
| - "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d."
|
| - "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/",
|
| - L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum",
|
| - L"xn--4dbklr2c8d.xn--4dbrk0ce.museum",
|
| - L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"},
|
| - {"HTTP URL with query string, IDN Arabic (RTL)",
|
| - "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no",
|
| - L"http://xn--wgbh1c.icom.museum", L"xn--wgbh1c.icom.museum",
|
| - L"http://xn--wgbh1c.icom.museum"},
|
| - {"Non-standard HTTP port", "http://www.google.com:9000/",
|
| - L"http://www.google.com:9000", L"www.google.com:9000",
|
| - L"http://www.google.com:9000"},
|
| - {"Non-standard HTTPS port", "https://www.google.com:9000/",
|
| - L"https://www.google.com:9000", L"www.google.com:9000",
|
| - L"www.google.com:9000"},
|
| {"File URI", "file:///usr/example/file.html",
|
| L"file:///usr/example/file.html", L"file:///usr/example/file.html",
|
| L"file:///usr/example/file.html"},
|
| @@ -285,48 +354,16 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
|
| L"file:///C:/Program%20Files/Music/Web%20Sys/main.html",
|
| L"file:///C:/Program%20Files/Music/Web%20Sys/main.html",
|
| L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"},
|
| - {"HTTP URL with path", "http://www.google.com/test.html",
|
| - L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
|
| - {"HTTPS URL with path", "https://www.google.com/test.html",
|
| - L"https://www.google.com", L"www.google.com", L"www.google.com"},
|
| - {"Unusual secure scheme (wss)", "wss://www.google.com/",
|
| - L"wss://www.google.com", L"wss://www.google.com", L"www.google.com"},
|
| - {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/",
|
| - L"gopher://www.google.com", L"gopher://www.google.com",
|
| - L"gopher://www.google.com"},
|
| - {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version",
|
| - L"chrome://version", L"chrome://version"},
|
| - {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103",
|
| - L"173.194.65.103", L"http://173.194.65.103"},
|
| - {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103",
|
| - L"173.194.65.103", L"173.194.65.103"},
|
| - {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
|
| - L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
|
| - L"http://[fe80::202:b3ff:fe1e:8329]"},
|
| - {"HTTPs IPv6 address",
|
| - "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
|
| - L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
|
| - L"[fe80::202:b3ff:fe1e:8329]"},
|
| - {"HTTP IPv6 address with port",
|
| - "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:80/",
|
| - L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
|
| - L"http://[fe80::202:b3ff:fe1e:8329]"},
|
| - {"HTTPs IPv6 address with port",
|
| - "https://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]:443/",
|
| - L"https://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]",
|
| - L"[fe80::202:b3ff:fe1e:8329]"},
|
| {"Invalid IPv6 address", "https://[2001:db8:0:1]/",
|
| L"https://[2001:db8:0:1]", L"https://[2001:db8:0:1]",
|
| L"https://[2001:db8:0:1]"},
|
| - {"HTTPS IP address, non-default port", "https://173.194.65.103:8443",
|
| - L"https://173.194.65.103:8443", L"173.194.65.103:8443",
|
| - L"173.194.65.103:8443"},
|
| {"HTTP filesystem: URL with path",
|
| "filesystem:http://www.google.com/temporary/test.html",
|
| L"filesystem:http://www.google.com", L"filesystem:http://www.google.com",
|
| L"filesystem:http://www.google.com"},
|
| {"File filesystem: URL with path",
|
| - "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy",
|
| + "filesystem:file://localhost/temporary/stuff/"
|
| + "test.html?z=fun&goat=billy",
|
| L"filesystem:file:///temporary/stuff/test.html",
|
| L"filesystem:file:///temporary/stuff/test.html",
|
| L"filesystem:file:///temporary/stuff/test.html"},
|
| @@ -336,19 +373,11 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
|
| {"Invalid scheme 2", "://www.cyber.org/wow.php",
|
| L"://www.cyber.org/wow.php", L"://www.cyber.org/wow.php",
|
| L"://www.cyber.org/wow.php"},
|
| - {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber..",
|
| - L"www.cyber..", L"www.cyber.."},
|
| - {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber",
|
| - L"www...cyber", L"www...cyber"},
|
| {"Invalid port 1", "https://173.194.65.103:000",
|
| L"https://173.194.65.103:0", L"173.194.65.103:0", L"173.194.65.103:0"},
|
| {"Invalid port 2", "https://173.194.65.103:gruffle",
|
| L"https://173.194.65.103:gruffle", L"https://173.194.65.103:gruffle",
|
| L"https://173.194.65.103:gruffle"},
|
| - {"Invalid port 3", "https://173.194.65.103:/hello.aspx",
|
| - L"https://173.194.65.103", L"173.194.65.103", L"173.194.65.103"},
|
| - {"Trailing dot in DNS name", "https://www.example.com./get/goat",
|
| - L"https://www.example.com.", L"www.example.com.", L"www.example.com."},
|
| {"Blob URL",
|
| "blob:http://www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
|
| L"blob:http://www.html5rocks.com/"
|
| @@ -381,8 +410,7 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
|
| << tests[i].description;
|
| }
|
|
|
| - base::string16 formatted =
|
| - url_formatter::FormatUrlForSecurityDisplay(GURL());
|
| + base::string16 formatted = url_formatter::FormatUrlForSecurityDisplay(GURL());
|
| EXPECT_EQ(base::string16(), formatted)
|
| << "Explicitly test the 0-argument GURL constructor";
|
|
|
| @@ -398,4 +426,96 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
|
| << "Explicitly test the 0-argument GURL constructor";
|
| }
|
|
|
| +TEST(TextEliderTest, FormatOriginForSecurityDisplay) {
|
| + for (size_t i = 0; i < arraysize(common_tests); ++i) {
|
| + base::string16 formatted = url_formatter::FormatOriginForSecurityDisplay(
|
| + url::Origin(GURL(common_tests[i].input)));
|
| + EXPECT_EQ(base::WideToUTF16(common_tests[i].output), formatted)
|
| + << common_tests[i].description;
|
| +
|
| + base::string16 formatted_omit_web_scheme =
|
| + url_formatter::FormatOriginForSecurityDisplay(
|
| + url::Origin(GURL(common_tests[i].input)),
|
| + url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
|
| + EXPECT_EQ(base::WideToUTF16(common_tests[i].output_omit_web_scheme),
|
| + formatted_omit_web_scheme)
|
| + << common_tests[i].description;
|
| +
|
| + base::string16 formatted_omit_cryptographic_scheme =
|
| + url_formatter::FormatOriginForSecurityDisplay(
|
| + url::Origin(GURL(common_tests[i].input)),
|
| + url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
|
| + EXPECT_EQ(
|
| + base::WideToUTF16(common_tests[i].output_omit_cryptographic_scheme),
|
| + formatted_omit_cryptographic_scheme)
|
| + << common_tests[i].description;
|
| + }
|
| +
|
| + const OriginTestData tests[] = {
|
| + {"File URI", "file:///usr/example/file.html", L"file://", L"file://",
|
| + L"file://"},
|
| + {"File URI with hostname", "file://localhost/usr/example/file.html",
|
| + L"file://localhost", L"file://localhost", L"file://localhost"},
|
| + {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls", L"file://",
|
| + L"file://", L"file://"},
|
| + {"UNC File URI 2",
|
| + "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO",
|
| + L"file://", L"file://", L"file://"},
|
| + {"Invalid IPv6 address", "https://[2001:db8:0:1]/", L"", L"", L""},
|
| + {"HTTP filesystem: URL with path",
|
| + "filesystem:http://www.google.com/temporary/test.html",
|
| + L"http://www.google.com", L"www.google.com", L"http://www.google.com"},
|
| + {"File filesystem: URL with path",
|
| + "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy",
|
| + L"file://", L"file://", L"file://"},
|
| + {"Invalid scheme 1", "twelve://www.cyber.org/wow.php", L"", L"", L""},
|
| + {"Invalid scheme 2", "://www.cyber.org/wow.php", L"", L"", L""},
|
| + {"Invalid port 1", "https://173.194.65.103:000", L"", L"", L""},
|
| + {"Invalid port 2", "https://173.194.65.103:gruffle", L"", L"", L""},
|
| + {"Blob URL",
|
| + "blob:http://www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
|
| + L"http://www.html5rocks.com", L"www.html5rocks.com",
|
| + L"http://www.html5rocks.com"}};
|
| +
|
| + for (size_t i = 0; i < arraysize(tests); ++i) {
|
| + base::string16 formatted = url_formatter::FormatOriginForSecurityDisplay(
|
| + url::Origin(GURL(tests[i].input)));
|
| + EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted)
|
| + << tests[i].description;
|
| +
|
| + base::string16 formatted_omit_web_scheme =
|
| + url_formatter::FormatOriginForSecurityDisplay(
|
| + url::Origin(GURL(tests[i].input)),
|
| + url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
|
| + EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_web_scheme),
|
| + formatted_omit_web_scheme)
|
| + << tests[i].description;
|
| +
|
| + base::string16 formatted_omit_cryptographic_scheme =
|
| + url_formatter::FormatOriginForSecurityDisplay(
|
| + url::Origin(GURL(tests[i].input)),
|
| + url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
|
| + EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_cryptographic_scheme),
|
| + formatted_omit_cryptographic_scheme)
|
| + << tests[i].description;
|
| + }
|
| +
|
| + base::string16 formatted =
|
| + url_formatter::FormatOriginForSecurityDisplay(url::Origin(GURL()));
|
| + EXPECT_EQ(base::string16(), formatted)
|
| + << "Explicitly test the url::Origin which takes an empty, invalid URL";
|
| +
|
| + base::string16 formatted_omit_scheme =
|
| + url_formatter::FormatOriginForSecurityDisplay(
|
| + url::Origin(GURL()),
|
| + url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
|
| + EXPECT_EQ(base::string16(), formatted_omit_scheme)
|
| + << "Explicitly test the url::Origin which takes an empty, invalid URL";
|
| +
|
| + formatted_omit_scheme = url_formatter::FormatOriginForSecurityDisplay(
|
| + url::Origin(GURL()), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
|
| + EXPECT_EQ(base::string16(), formatted_omit_scheme)
|
| + << "Explicitly test the url::Origin which takes an empty, invalid URL";
|
| +}
|
| +
|
| } // namespace
|
|
|