| Index: components/url_formatter/url_formatter_unittest.cc
|
| diff --git a/net/base/net_util_icu_unittest.cc b/components/url_formatter/url_formatter_unittest.cc
|
| similarity index 67%
|
| copy from net/base/net_util_icu_unittest.cc
|
| copy to components/url_formatter/url_formatter_unittest.cc
|
| index f643426aa678ed48f36e96877adde254a26624b5..0dd635a9488c9dc89b43e574e11ccd548d1b30e6 100644
|
| --- a/net/base/net_util_icu_unittest.cc
|
| +++ b/components/url_formatter/url_formatter_unittest.cc
|
| @@ -1,28 +1,28 @@
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "net/base/net_util.h"
|
| +#include "components/url_formatter/url_formatter.h"
|
|
|
| #include <string.h>
|
|
|
| #include <vector>
|
|
|
| -#include "base/format_macros.h"
|
| +#include "base/macros.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| -#include "base/time/time.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| -using base::ASCIIToUTF16;
|
| -using base::WideToUTF16;
|
|
|
| -namespace net {
|
| +namespace url_formatter {
|
|
|
| namespace {
|
|
|
| +using base::WideToUTF16;
|
| +using base::ASCIIToUTF16;
|
| +
|
| const size_t kNpos = base::string16::npos;
|
|
|
| const char* const kLanguages[] = {
|
| @@ -374,7 +374,7 @@ struct UrlTestData {
|
| const char* const input;
|
| const char* const languages;
|
| FormatUrlTypes format_types;
|
| - UnescapeRule::Type escape_rules;
|
| + net::UnescapeRule::Type escape_rules;
|
| const wchar_t* output; // Use |wchar_t| to handle Unicode constants easily.
|
| size_t prefix_len;
|
| };
|
| @@ -403,7 +403,7 @@ void VerboseExpect(size_t expected,
|
| void CheckAdjustedOffsets(const std::string& url_string,
|
| const std::string& languages,
|
| FormatUrlTypes format_types,
|
| - UnescapeRule::Type unescape_rules,
|
| + net::UnescapeRule::Type unescape_rules,
|
| const size_t* output_offsets) {
|
| GURL url(url_string);
|
| size_t url_length = url_string.length();
|
| @@ -424,9 +424,7 @@ void CheckAdjustedOffsets(const std::string& url_string,
|
| std::string::npos, formatted_url);
|
| }
|
|
|
| -} // anonymous namespace
|
| -
|
| -TEST(NetUtilTest, IDNToUnicodeFast) {
|
| +TEST(UrlFormatterTest, IDNToUnicodeFast) {
|
| for (size_t i = 0; i < arraysize(idn_cases); i++) {
|
| for (size_t j = 0; j < arraysize(kLanguages); j++) {
|
| // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow
|
| @@ -444,7 +442,7 @@ TEST(NetUtilTest, IDNToUnicodeFast) {
|
| }
|
| }
|
|
|
| -TEST(NetUtilTest, IDNToUnicodeSlow) {
|
| +TEST(UrlFormatterTest, IDNToUnicodeSlow) {
|
| for (size_t i = 0; i < arraysize(idn_cases); i++) {
|
| for (size_t j = 0; j < arraysize(kLanguages); j++) {
|
| // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast
|
| @@ -465,7 +463,7 @@ TEST(NetUtilTest, IDNToUnicodeSlow) {
|
| // ulocdata_getExemplarSet may fail with some locales (currently bn, gu, and
|
| // te), which was causing a crash (See http://crbug.com/510551). This may be an
|
| // icu bug, but regardless, that should not cause a crash.
|
| -TEST(NetUtilTest, IDNToUnicodeNeverCrashes) {
|
| +TEST(UrlFormatterTest, IDNToUnicodeNeverCrashes) {
|
| for (char c1 = 'a'; c1 <= 'z'; c1++) {
|
| for (char c2 = 'a'; c2 <= 'z'; c2++) {
|
| std::string lang = base::StringPrintf("%c%c", c1, c2);
|
| @@ -474,254 +472,161 @@ TEST(NetUtilTest, IDNToUnicodeNeverCrashes) {
|
| }
|
| }
|
|
|
| -TEST(NetUtilTest, StripWWW) {
|
| - EXPECT_EQ(base::string16(), StripWWW(base::string16()));
|
| - EXPECT_EQ(base::string16(), StripWWW(ASCIIToUTF16("www.")));
|
| - EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("www.blah")));
|
| - EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("blah")));
|
| -}
|
| -
|
| -// This is currently a windows specific function.
|
| -#if defined(OS_WIN)
|
| -namespace {
|
| -
|
| -struct GetDirectoryListingEntryCase {
|
| - const wchar_t* name;
|
| - const char* const raw_bytes;
|
| - bool is_dir;
|
| - int64_t filesize;
|
| - base::Time time;
|
| - const char* const expected;
|
| -};
|
| -
|
| -} // namespace
|
| -
|
| -TEST(NetUtilTest, GetDirectoryListingEntry) {
|
| - const GetDirectoryListingEntryCase test_cases[] = {
|
| - {L"Foo",
|
| - "",
|
| - false,
|
| - 10000,
|
| - base::Time(),
|
| - "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"},
|
| - {L"quo\"tes",
|
| - "",
|
| - false,
|
| - 10000,
|
| - base::Time(),
|
| - "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>"
|
| - "\n"},
|
| - {L"quo\"tes",
|
| - "quo\"tes",
|
| - false,
|
| - 10000,
|
| - base::Time(),
|
| - "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>"
|
| - "\n"},
|
| - // U+D55C0 U+AE00. raw_bytes is empty (either a local file with
|
| - // UTF-8/UTF-16 encoding or a remote file on an ftp server using UTF-8
|
| - {L"\xD55C\xAE00.txt",
|
| - "",
|
| - false,
|
| - 10000,
|
| - base::Time(),
|
| - "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\","
|
| - "\"%ED%95%9C%EA%B8%80.txt\",0,\"9.8 kB\",\"\");</script>\n"},
|
| - // U+D55C0 U+AE00. raw_bytes is the corresponding EUC-KR sequence:
|
| - // a local or remote file in EUC-KR.
|
| - {L"\xD55C\xAE00.txt",
|
| - "\xC7\xD1\xB1\xDB.txt",
|
| - false,
|
| - 10000,
|
| - base::Time(),
|
| - "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\",\"%C7%D1%B1%DB.txt\""
|
| - ",0,\"9.8 kB\",\"\");</script>\n"},
|
| - };
|
| -
|
| - for (size_t i = 0; i < arraysize(test_cases); ++i) {
|
| - const std::string results = GetDirectoryListingEntry(
|
| - WideToUTF16(test_cases[i].name),
|
| - test_cases[i].raw_bytes,
|
| - test_cases[i].is_dir,
|
| - test_cases[i].filesize,
|
| - test_cases[i].time);
|
| - EXPECT_EQ(test_cases[i].expected, results);
|
| - }
|
| -}
|
| -
|
| -#endif
|
| -
|
| -TEST(NetUtilTest, FormatUrl) {
|
| +TEST(UrlFormatterTest, FormatUrl) {
|
| FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword;
|
| const UrlTestData tests[] = {
|
| - {"Empty URL", "", "", default_format_type, UnescapeRule::NORMAL, L"", 0},
|
| -
|
| - {"Simple URL",
|
| - "http://www.google.com/", "", default_format_type, UnescapeRule::NORMAL,
|
| - L"http://www.google.com/", 7},
|
| -
|
| - {"With a port number and a reference",
|
| - "http://www.google.com:8080/#\xE3\x82\xB0", "", default_format_type,
|
| - UnescapeRule::NORMAL,
|
| - L"http://www.google.com:8080/#\x30B0", 7},
|
| -
|
| - // -------- IDN tests --------
|
| - {"Japanese IDN with ja",
|
| - "http://xn--l8jvb1ey91xtjb.jp", "ja", default_format_type,
|
| - UnescapeRule::NORMAL, L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
|
| -
|
| - {"Japanese IDN with en",
|
| - "http://xn--l8jvb1ey91xtjb.jp", "en", default_format_type,
|
| - UnescapeRule::NORMAL, L"http://xn--l8jvb1ey91xtjb.jp/", 7},
|
| -
|
| - {"Japanese IDN without any languages",
|
| - "http://xn--l8jvb1ey91xtjb.jp", "", default_format_type,
|
| - UnescapeRule::NORMAL,
|
| - // Single script is safe for empty languages.
|
| - L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
|
| -
|
| - {"mailto: with Japanese IDN",
|
| - "mailto:foo@xn--l8jvb1ey91xtjb.jp", "ja", default_format_type,
|
| - UnescapeRule::NORMAL,
|
| - // GURL doesn't assume an email address's domain part as a host name.
|
| - L"mailto:foo@xn--l8jvb1ey91xtjb.jp", 7},
|
| -
|
| - {"file: with Japanese IDN",
|
| - "file://xn--l8jvb1ey91xtjb.jp/config.sys", "ja", default_format_type,
|
| - UnescapeRule::NORMAL,
|
| - L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 7},
|
| -
|
| - {"ftp: with Japanese IDN",
|
| - "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", "ja", default_format_type,
|
| - UnescapeRule::NORMAL,
|
| - L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 6},
|
| -
|
| - // -------- omit_username_password flag tests --------
|
| - {"With username and password, omit_username_password=false",
|
| - "http://user:passwd@example.com/foo", "",
|
| - kFormatUrlOmitNothing, UnescapeRule::NORMAL,
|
| - L"http://user:passwd@example.com/foo", 19},
|
| -
|
| - {"With username and password, omit_username_password=true",
|
| - "http://user:passwd@example.com/foo", "", default_format_type,
|
| - UnescapeRule::NORMAL, L"http://example.com/foo", 7},
|
| -
|
| - {"With username and no password",
|
| - "http://user@example.com/foo", "", default_format_type,
|
| - UnescapeRule::NORMAL, L"http://example.com/foo", 7},
|
| -
|
| - {"Just '@' without username and password",
|
| - "http://@example.com/foo", "", default_format_type, UnescapeRule::NORMAL,
|
| - L"http://example.com/foo", 7},
|
| -
|
| - // GURL doesn't think local-part of an email address is username for URL.
|
| - {"mailto:, omit_username_password=true",
|
| - "mailto:foo@example.com", "", default_format_type, UnescapeRule::NORMAL,
|
| - L"mailto:foo@example.com", 7},
|
| -
|
| - // -------- unescape flag tests --------
|
| - {"Do not unescape",
|
| - "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
|
| - "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
|
| - "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", "en", default_format_type,
|
| - UnescapeRule::NONE,
|
| - // GURL parses %-encoded hostnames into Punycode.
|
| - L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
|
| - L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 7},
|
| -
|
| - {"Unescape normally",
|
| - "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
|
| - "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
|
| - "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", "en", default_format_type,
|
| - UnescapeRule::NORMAL,
|
| - L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB"
|
| - L"?q=\x30B0\x30FC\x30B0\x30EB", 7},
|
| -
|
| - {"Unescape normally with BiDi control character",
|
| - "http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", "en", default_format_type,
|
| - UnescapeRule::NORMAL, L"http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", 7},
|
| -
|
| - {"Unescape normally including unescape spaces",
|
| - "http://www.google.com/search?q=Hello%20World", "en", default_format_type,
|
| - UnescapeRule::SPACES, L"http://www.google.com/search?q=Hello World", 7},
|
| -
|
| - /*
|
| - {"unescape=true with some special characters",
|
| - "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", "",
|
| - kFormatUrlOmitNothing, UnescapeRule::NORMAL,
|
| - L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25},
|
| - */
|
| - // Disabled: the resultant URL becomes "...user%253A:%2540passwd...".
|
| -
|
| - // -------- omit http: --------
|
| - {"omit http with user name",
|
| - "http://user@example.com/foo", "", kFormatUrlOmitAll,
|
| - UnescapeRule::NORMAL, L"example.com/foo", 0},
|
| -
|
| - {"omit http",
|
| - "http://www.google.com/", "en", kFormatUrlOmitHTTP,
|
| - UnescapeRule::NORMAL, L"www.google.com/",
|
| - 0},
|
| -
|
| - {"omit http with https",
|
| - "https://www.google.com/", "en", kFormatUrlOmitHTTP,
|
| - UnescapeRule::NORMAL, L"https://www.google.com/",
|
| - 8},
|
| -
|
| - {"omit http starts with ftp.",
|
| - "http://ftp.google.com/", "en", kFormatUrlOmitHTTP,
|
| - UnescapeRule::NORMAL, L"http://ftp.google.com/",
|
| - 7},
|
| -
|
| - // -------- omit trailing slash on bare hostname --------
|
| - {"omit slash when it's the entire path",
|
| - "http://www.google.com/", "en",
|
| - kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL,
|
| - L"http://www.google.com", 7},
|
| - {"omit slash when there's a ref",
|
| - "http://www.google.com/#ref", "en",
|
| - kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL,
|
| - L"http://www.google.com/#ref", 7},
|
| - {"omit slash when there's a query",
|
| - "http://www.google.com/?", "en",
|
| - kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL,
|
| - L"http://www.google.com/?", 7},
|
| - {"omit slash when it's not the entire path",
|
| - "http://www.google.com/foo", "en",
|
| - kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL,
|
| - L"http://www.google.com/foo", 7},
|
| - {"omit slash for nonstandard URLs",
|
| - "data:/", "en", kFormatUrlOmitTrailingSlashOnBareHostname,
|
| - UnescapeRule::NORMAL, L"data:/", 5},
|
| - {"omit slash for file URLs",
|
| - "file:///", "en", kFormatUrlOmitTrailingSlashOnBareHostname,
|
| - UnescapeRule::NORMAL, L"file:///", 7},
|
| -
|
| - // -------- view-source: --------
|
| - {"view-source",
|
| - "view-source:http://xn--qcka1pmc.jp/", "ja", default_format_type,
|
| - UnescapeRule::NORMAL, L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/",
|
| - 19},
|
| -
|
| - {"view-source of view-source",
|
| - "view-source:view-source:http://xn--qcka1pmc.jp/", "ja",
|
| - default_format_type, UnescapeRule::NORMAL,
|
| - L"view-source:view-source:http://xn--qcka1pmc.jp/", 12},
|
| -
|
| - // view-source should omit http and trailing slash where non-view-source
|
| - // would.
|
| - {"view-source omit http",
|
| - "view-source:http://a.b/c", "en", kFormatUrlOmitAll,
|
| - UnescapeRule::NORMAL, L"view-source:a.b/c",
|
| - 12},
|
| - {"view-source omit http starts with ftp.",
|
| - "view-source:http://ftp.b/c", "en", kFormatUrlOmitAll,
|
| - UnescapeRule::NORMAL, L"view-source:http://ftp.b/c",
|
| - 19},
|
| - {"view-source omit slash when it's the entire path",
|
| - "view-source:http://a.b/", "en", kFormatUrlOmitAll,
|
| - UnescapeRule::NORMAL, L"view-source:a.b",
|
| - 12},
|
| + {"Empty URL", "", "", default_format_type, net::UnescapeRule::NORMAL, L"",
|
| + 0},
|
| +
|
| + {"Simple URL", "http://www.google.com/", "", default_format_type,
|
| + net::UnescapeRule::NORMAL, L"http://www.google.com/", 7},
|
| +
|
| + {"With a port number and a reference",
|
| + "http://www.google.com:8080/#\xE3\x82\xB0", "", default_format_type,
|
| + net::UnescapeRule::NORMAL, L"http://www.google.com:8080/#\x30B0", 7},
|
| +
|
| + // -------- IDN tests --------
|
| + {"Japanese IDN with ja", "http://xn--l8jvb1ey91xtjb.jp", "ja",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
|
| +
|
| + {"Japanese IDN with en", "http://xn--l8jvb1ey91xtjb.jp", "en",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"http://xn--l8jvb1ey91xtjb.jp/", 7},
|
| +
|
| + {"Japanese IDN without any languages", "http://xn--l8jvb1ey91xtjb.jp", "",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + // Single script is safe for empty languages.
|
| + L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
|
| +
|
| + {"mailto: with Japanese IDN", "mailto:foo@xn--l8jvb1ey91xtjb.jp", "ja",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + // GURL doesn't assume an email address's domain part as a host name.
|
| + L"mailto:foo@xn--l8jvb1ey91xtjb.jp", 7},
|
| +
|
| + {"file: with Japanese IDN", "file://xn--l8jvb1ey91xtjb.jp/config.sys",
|
| + "ja", default_format_type, net::UnescapeRule::NORMAL,
|
| + L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 7},
|
| +
|
| + {"ftp: with Japanese IDN", "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", "ja",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 6},
|
| +
|
| + // -------- omit_username_password flag tests --------
|
| + {"With username and password, omit_username_password=false",
|
| + "http://user:passwd@example.com/foo", "", kFormatUrlOmitNothing,
|
| + net::UnescapeRule::NORMAL, L"http://user:passwd@example.com/foo", 19},
|
| +
|
| + {"With username and password, omit_username_password=true",
|
| + "http://user:passwd@example.com/foo", "", default_format_type,
|
| + net::UnescapeRule::NORMAL, L"http://example.com/foo", 7},
|
| +
|
| + {"With username and no password", "http://user@example.com/foo", "",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"http://example.com/foo", 7},
|
| +
|
| + {"Just '@' without username and password", "http://@example.com/foo", "",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"http://example.com/foo", 7},
|
| +
|
| + // GURL doesn't think local-part of an email address is username for URL.
|
| + {"mailto:, omit_username_password=true", "mailto:foo@example.com", "",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"mailto:foo@example.com", 7},
|
| +
|
| + // -------- unescape flag tests --------
|
| + {"Do not unescape",
|
| + "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
|
| + "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
|
| + "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
|
| + "en", default_format_type, net::UnescapeRule::NONE,
|
| + // GURL parses %-encoded hostnames into Punycode.
|
| + L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
|
| + L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
|
| + 7},
|
| +
|
| + {"Unescape normally",
|
| + "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
|
| + "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
|
| + "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
|
| + "en", default_format_type, net::UnescapeRule::NORMAL,
|
| + L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB"
|
| + L"?q=\x30B0\x30FC\x30B0\x30EB",
|
| + 7},
|
| +
|
| + {"Unescape normally with BiDi control character",
|
| + "http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", "en",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", 7},
|
| +
|
| + {"Unescape normally including unescape spaces",
|
| + "http://www.google.com/search?q=Hello%20World", "en",
|
| + default_format_type, net::UnescapeRule::SPACES,
|
| + L"http://www.google.com/search?q=Hello World", 7},
|
| +
|
| + /*
|
| + {"unescape=true with some special characters",
|
| + "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", "",
|
| + kFormatUrlOmitNothing, net::UnescapeRule::NORMAL,
|
| + L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25},
|
| + */
|
| + // Disabled: the resultant URL becomes "...user%253A:%2540passwd...".
|
| +
|
| + // -------- omit http: --------
|
| + {"omit http with user name", "http://user@example.com/foo", "",
|
| + kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"example.com/foo", 0},
|
| +
|
| + {"omit http", "http://www.google.com/", "en", kFormatUrlOmitHTTP,
|
| + net::UnescapeRule::NORMAL, L"www.google.com/", 0},
|
| +
|
| + {"omit http with https", "https://www.google.com/", "en",
|
| + kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL,
|
| + L"https://www.google.com/", 8},
|
| +
|
| + {"omit http starts with ftp.", "http://ftp.google.com/", "en",
|
| + kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, L"http://ftp.google.com/",
|
| + 7},
|
| +
|
| + // -------- omit trailing slash on bare hostname --------
|
| + {"omit slash when it's the entire path", "http://www.google.com/", "en",
|
| + kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
|
| + L"http://www.google.com", 7},
|
| + {"omit slash when there's a ref", "http://www.google.com/#ref", "en",
|
| + kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
|
| + L"http://www.google.com/#ref", 7},
|
| + {"omit slash when there's a query", "http://www.google.com/?", "en",
|
| + kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
|
| + L"http://www.google.com/?", 7},
|
| + {"omit slash when it's not the entire path", "http://www.google.com/foo",
|
| + "en", kFormatUrlOmitTrailingSlashOnBareHostname,
|
| + net::UnescapeRule::NORMAL, L"http://www.google.com/foo", 7},
|
| + {"omit slash for nonstandard URLs", "data:/", "en",
|
| + kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
|
| + L"data:/", 5},
|
| + {"omit slash for file URLs", "file:///", "en",
|
| + kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
|
| + L"file:///", 7},
|
| +
|
| + // -------- view-source: --------
|
| + {"view-source", "view-source:http://xn--qcka1pmc.jp/", "ja",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/", 19},
|
| +
|
| + {"view-source of view-source",
|
| + "view-source:view-source:http://xn--qcka1pmc.jp/", "ja",
|
| + default_format_type, net::UnescapeRule::NORMAL,
|
| + L"view-source:view-source:http://xn--qcka1pmc.jp/", 12},
|
| +
|
| + // view-source should omit http and trailing slash where non-view-source
|
| + // would.
|
| + {"view-source omit http", "view-source:http://a.b/c", "en",
|
| + kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"view-source:a.b/c", 12},
|
| + {"view-source omit http starts with ftp.", "view-source:http://ftp.b/c",
|
| + "en", kFormatUrlOmitAll, net::UnescapeRule::NORMAL,
|
| + L"view-source:http://ftp.b/c", 19},
|
| + {"view-source omit slash when it's the entire path",
|
| + "view-source:http://a.b/", "en", kFormatUrlOmitAll,
|
| + net::UnescapeRule::NORMAL, L"view-source:a.b", 12},
|
| };
|
|
|
| for (size_t i = 0; i < arraysize(tests); ++i) {
|
| @@ -734,14 +639,14 @@ TEST(NetUtilTest, FormatUrl) {
|
| }
|
| }
|
|
|
| -TEST(NetUtilTest, FormatUrlParsed) {
|
| +TEST(UrlFormatterTest, FormatUrlParsed) {
|
| // No unescape case.
|
| url::Parsed parsed;
|
| - base::string16 formatted = FormatUrl(
|
| - GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
|
| - "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
|
| - "ja", kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL,
|
| - NULL);
|
| + base::string16 formatted =
|
| + FormatUrl(GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
|
| + "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
|
| + "ja", kFormatUrlOmitNothing, net::UnescapeRule::NONE, &parsed,
|
| + NULL, NULL);
|
| EXPECT_EQ(WideToUTF16(
|
| L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
|
| L"/%E3%82%B0/?q=%E3%82%B0#\x30B0"), formatted);
|
| @@ -761,11 +666,11 @@ TEST(NetUtilTest, FormatUrlParsed) {
|
| formatted.substr(parsed.ref.begin, parsed.ref.len));
|
|
|
| // Unescape case.
|
| - formatted = FormatUrl(
|
| - GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
|
| - "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
|
| - "ja", kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL,
|
| - NULL);
|
| + formatted =
|
| + FormatUrl(GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
|
| + "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
|
| + "ja", kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, &parsed,
|
| + NULL, NULL);
|
| EXPECT_EQ(WideToUTF16(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
|
| L"/\x30B0/?q=\x30B0#\x30B0"), formatted);
|
| EXPECT_EQ(WideToUTF16(L"\x30B0"),
|
| @@ -784,11 +689,11 @@ TEST(NetUtilTest, FormatUrlParsed) {
|
| formatted.substr(parsed.ref.begin, parsed.ref.len));
|
|
|
| // Omit_username_password + unescape case.
|
| - formatted = FormatUrl(
|
| - GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
|
| - "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
|
| - "ja", kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed,
|
| - NULL, NULL);
|
| + formatted =
|
| + FormatUrl(GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
|
| + "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
|
| + "ja", kFormatUrlOmitUsernamePassword, net::UnescapeRule::NORMAL,
|
| + &parsed, NULL, NULL);
|
| EXPECT_EQ(WideToUTF16(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
|
| L"/\x30B0/?q=\x30B0#\x30B0"), formatted);
|
| EXPECT_FALSE(parsed.username.is_valid());
|
| @@ -807,12 +712,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
|
| // View-source case.
|
| formatted =
|
| FormatUrl(GURL("view-source:http://user:passwd@host:81/path?query#ref"),
|
| - std::string(),
|
| - kFormatUrlOmitUsernamePassword,
|
| - UnescapeRule::NORMAL,
|
| - &parsed,
|
| - NULL,
|
| - NULL);
|
| + std::string(), kFormatUrlOmitUsernamePassword,
|
| + net::UnescapeRule::NORMAL, &parsed, NULL, NULL);
|
| EXPECT_EQ(WideToUTF16(L"view-source:http://host:81/path?query#ref"),
|
| formatted);
|
| EXPECT_EQ(WideToUTF16(L"view-source:http"),
|
| @@ -831,13 +732,9 @@ TEST(NetUtilTest, FormatUrlParsed) {
|
| formatted.substr(parsed.ref.begin, parsed.ref.len));
|
|
|
| // omit http case.
|
| - formatted = FormatUrl(GURL("http://host:8000/a?b=c#d"),
|
| - std::string(),
|
| - kFormatUrlOmitHTTP,
|
| - UnescapeRule::NORMAL,
|
| - &parsed,
|
| - NULL,
|
| - NULL);
|
| + formatted = FormatUrl(GURL("http://host:8000/a?b=c#d"), std::string(),
|
| + kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, &parsed,
|
| + NULL, NULL);
|
| EXPECT_EQ(WideToUTF16(L"host:8000/a?b=c#d"), formatted);
|
| EXPECT_FALSE(parsed.scheme.is_valid());
|
| EXPECT_FALSE(parsed.username.is_valid());
|
| @@ -854,13 +751,9 @@ TEST(NetUtilTest, FormatUrlParsed) {
|
| formatted.substr(parsed.ref.begin, parsed.ref.len));
|
|
|
| // omit http starts with ftp case.
|
| - formatted = FormatUrl(GURL("http://ftp.host:8000/a?b=c#d"),
|
| - std::string(),
|
| - kFormatUrlOmitHTTP,
|
| - UnescapeRule::NORMAL,
|
| - &parsed,
|
| - NULL,
|
| - NULL);
|
| + formatted = FormatUrl(GURL("http://ftp.host:8000/a?b=c#d"), std::string(),
|
| + kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, &parsed,
|
| + NULL, NULL);
|
| EXPECT_EQ(WideToUTF16(L"http://ftp.host:8000/a?b=c#d"), formatted);
|
| EXPECT_TRUE(parsed.scheme.is_valid());
|
| EXPECT_FALSE(parsed.username.is_valid());
|
| @@ -879,13 +772,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
|
| formatted.substr(parsed.ref.begin, parsed.ref.len));
|
|
|
| // omit http starts with 'f' case.
|
| - formatted = FormatUrl(GURL("http://f/"),
|
| - std::string(),
|
| - kFormatUrlOmitHTTP,
|
| - UnescapeRule::NORMAL,
|
| - &parsed,
|
| - NULL,
|
| - NULL);
|
| + formatted = FormatUrl(GURL("http://f/"), std::string(), kFormatUrlOmitHTTP,
|
| + net::UnescapeRule::NORMAL, &parsed, NULL, NULL);
|
| EXPECT_EQ(WideToUTF16(L"f/"), formatted);
|
| EXPECT_FALSE(parsed.scheme.is_valid());
|
| EXPECT_FALSE(parsed.username.is_valid());
|
| @@ -902,25 +790,21 @@ TEST(NetUtilTest, FormatUrlParsed) {
|
|
|
| // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
|
| // results in the original GURL, for each ASCII character in the path.
|
| -TEST(NetUtilTest, FormatUrlRoundTripPathASCII) {
|
| +TEST(UrlFormatterTest, FormatUrlRoundTripPathASCII) {
|
| for (unsigned char test_char = 32; test_char < 128; ++test_char) {
|
| GURL url(std::string("http://www.google.com/") +
|
| static_cast<char>(test_char));
|
| size_t prefix_len;
|
| - base::string16 formatted = FormatUrl(url,
|
| - std::string(),
|
| - kFormatUrlOmitUsernamePassword,
|
| - UnescapeRule::NORMAL,
|
| - NULL,
|
| - &prefix_len,
|
| - NULL);
|
| + base::string16 formatted =
|
| + FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword,
|
| + net::UnescapeRule::NORMAL, NULL, &prefix_len, NULL);
|
| EXPECT_EQ(url.spec(), GURL(formatted).spec());
|
| }
|
| }
|
|
|
| // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
|
| // results in the original GURL, for each escaped ASCII character in the path.
|
| -TEST(NetUtilTest, FormatUrlRoundTripPathEscaped) {
|
| +TEST(UrlFormatterTest, FormatUrlRoundTripPathEscaped) {
|
| for (unsigned char test_char = 32; test_char < 128; ++test_char) {
|
| std::string original_url("http://www.google.com/");
|
| original_url.push_back('%');
|
| @@ -928,38 +812,30 @@ TEST(NetUtilTest, FormatUrlRoundTripPathEscaped) {
|
|
|
| GURL url(original_url);
|
| size_t prefix_len;
|
| - base::string16 formatted = FormatUrl(url,
|
| - std::string(),
|
| - kFormatUrlOmitUsernamePassword,
|
| - UnescapeRule::NORMAL,
|
| - NULL,
|
| - &prefix_len,
|
| - NULL);
|
| + base::string16 formatted =
|
| + FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword,
|
| + net::UnescapeRule::NORMAL, NULL, &prefix_len, NULL);
|
| EXPECT_EQ(url.spec(), GURL(formatted).spec());
|
| }
|
| }
|
|
|
| // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
|
| // results in the original GURL, for each ASCII character in the query.
|
| -TEST(NetUtilTest, FormatUrlRoundTripQueryASCII) {
|
| +TEST(UrlFormatterTest, FormatUrlRoundTripQueryASCII) {
|
| for (unsigned char test_char = 32; test_char < 128; ++test_char) {
|
| GURL url(std::string("http://www.google.com/?") +
|
| static_cast<char>(test_char));
|
| size_t prefix_len;
|
| - base::string16 formatted = FormatUrl(url,
|
| - std::string(),
|
| - kFormatUrlOmitUsernamePassword,
|
| - UnescapeRule::NORMAL,
|
| - NULL,
|
| - &prefix_len,
|
| - NULL);
|
| + base::string16 formatted =
|
| + FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword,
|
| + net::UnescapeRule::NORMAL, NULL, &prefix_len, NULL);
|
| EXPECT_EQ(url.spec(), GURL(formatted).spec());
|
| }
|
| }
|
|
|
| // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
|
| // only results in a different GURL for certain characters.
|
| -TEST(NetUtilTest, FormatUrlRoundTripQueryEscaped) {
|
| +TEST(UrlFormatterTest, FormatUrlRoundTripQueryEscaped) {
|
| // A full list of characters which FormatURL should unescape and GURL should
|
| // not escape again, when they appear in a query string.
|
| const char kUnescapedCharacters[] =
|
| @@ -971,13 +847,9 @@ TEST(NetUtilTest, FormatUrlRoundTripQueryEscaped) {
|
|
|
| GURL url(original_url);
|
| size_t prefix_len;
|
| - base::string16 formatted = FormatUrl(url,
|
| - std::string(),
|
| - kFormatUrlOmitUsernamePassword,
|
| - UnescapeRule::NORMAL,
|
| - NULL,
|
| - &prefix_len,
|
| - NULL);
|
| + base::string16 formatted =
|
| + FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword,
|
| + net::UnescapeRule::NORMAL, NULL, &prefix_len, NULL);
|
|
|
| if (test_char &&
|
| strchr(kUnescapedCharacters, static_cast<char>(test_char))) {
|
| @@ -988,16 +860,16 @@ TEST(NetUtilTest, FormatUrlRoundTripQueryEscaped) {
|
| }
|
| }
|
|
|
| -TEST(NetUtilTest, FormatUrlWithOffsets) {
|
| +TEST(UrlFormatterTest, FormatUrlWithOffsets) {
|
| CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing,
|
| - UnescapeRule::NORMAL, NULL);
|
| + net::UnescapeRule::NORMAL, NULL);
|
|
|
| const size_t basic_offsets[] = {
|
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
| 21, 22, 23, 24, 25
|
| };
|
| CheckAdjustedOffsets("http://www.google.com/foo/", "en",
|
| - kFormatUrlOmitNothing, UnescapeRule::NORMAL,
|
| + kFormatUrlOmitNothing, net::UnescapeRule::NORMAL,
|
| basic_offsets);
|
|
|
| const size_t omit_auth_offsets_1[] = {
|
| @@ -1005,16 +877,16 @@ TEST(NetUtilTest, FormatUrlWithOffsets) {
|
| 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
|
| };
|
| CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en",
|
| - kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
|
| - omit_auth_offsets_1);
|
| + kFormatUrlOmitUsernamePassword,
|
| + net::UnescapeRule::NORMAL, omit_auth_offsets_1);
|
|
|
| const size_t omit_auth_offsets_2[] = {
|
| 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14,
|
| 15, 16, 17, 18, 19, 20, 21
|
| };
|
| CheckAdjustedOffsets("http://foo@www.google.com/", "en",
|
| - kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
|
| - omit_auth_offsets_2);
|
| + kFormatUrlOmitUsernamePassword,
|
| + net::UnescapeRule::NORMAL, omit_auth_offsets_2);
|
|
|
| const size_t dont_omit_auth_offsets[] = {
|
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
|
| @@ -1024,7 +896,7 @@ TEST(NetUtilTest, FormatUrlWithOffsets) {
|
| };
|
| // Unescape to "http://foo\x30B0:\x30B0bar@www.google.com".
|
| CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en",
|
| - kFormatUrlOmitNothing, UnescapeRule::NORMAL,
|
| + kFormatUrlOmitNothing, net::UnescapeRule::NORMAL,
|
| dont_omit_auth_offsets);
|
|
|
| const size_t view_source_offsets[] = {
|
| @@ -1032,8 +904,8 @@ TEST(NetUtilTest, FormatUrlWithOffsets) {
|
| kNpos, kNpos, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33
|
| };
|
| CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en",
|
| - kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
|
| - view_source_offsets);
|
| + kFormatUrlOmitUsernamePassword,
|
| + net::UnescapeRule::NORMAL, view_source_offsets);
|
|
|
| const size_t idn_hostname_offsets_1[] = {
|
| 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
|
| @@ -1042,7 +914,7 @@ TEST(NetUtilTest, FormatUrlWithOffsets) {
|
| };
|
| // Convert punycode to "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/".
|
| CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja",
|
| - kFormatUrlOmitNothing, UnescapeRule::NORMAL,
|
| + kFormatUrlOmitNothing, net::UnescapeRule::NORMAL,
|
| idn_hostname_offsets_1);
|
|
|
| const size_t idn_hostname_offsets_2[] = {
|
| @@ -1054,8 +926,8 @@ TEST(NetUtilTest, FormatUrlWithOffsets) {
|
| // Convert punycode to
|
| // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/".
|
| CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/",
|
| - "zh-CN", kFormatUrlOmitNothing, UnescapeRule::NORMAL,
|
| - idn_hostname_offsets_2);
|
| + "zh-CN", kFormatUrlOmitNothing,
|
| + net::UnescapeRule::NORMAL, idn_hostname_offsets_2);
|
|
|
| const size_t unescape_offsets[] = {
|
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
| @@ -1067,7 +939,7 @@ TEST(NetUtilTest, FormatUrlWithOffsets) {
|
| // Unescape to "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB".
|
| CheckAdjustedOffsets(
|
| "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
|
| - "en", kFormatUrlOmitNothing, UnescapeRule::SPACES, unescape_offsets);
|
| + "en", kFormatUrlOmitNothing, net::UnescapeRule::SPACES, unescape_offsets);
|
|
|
| const size_t ref_offsets[] = {
|
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
| @@ -1077,27 +949,30 @@ TEST(NetUtilTest, FormatUrlWithOffsets) {
|
| // Unescape to "http://www.google.com/foo.html#\x30B0\x30B0z".
|
| CheckAdjustedOffsets(
|
| "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en",
|
| - kFormatUrlOmitNothing, UnescapeRule::NORMAL, ref_offsets);
|
| + kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, ref_offsets);
|
|
|
| const size_t omit_http_offsets[] = {
|
| 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
| 10, 11, 12, 13, 14
|
| };
|
| CheckAdjustedOffsets("http://www.google.com/", "en", kFormatUrlOmitHTTP,
|
| - UnescapeRule::NORMAL, omit_http_offsets);
|
| + net::UnescapeRule::NORMAL, omit_http_offsets);
|
|
|
| const size_t omit_http_start_with_ftp_offsets[] = {
|
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
|
| };
|
| CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP,
|
| - UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets);
|
| + net::UnescapeRule::NORMAL,
|
| + omit_http_start_with_ftp_offsets);
|
|
|
| const size_t omit_all_offsets[] = {
|
| 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
|
| 0, 1, 2, 3, 4, 5, 6, 7
|
| };
|
| CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll,
|
| - UnescapeRule::NORMAL, omit_all_offsets);
|
| + net::UnescapeRule::NORMAL, omit_all_offsets);
|
| }
|
|
|
| -} // namespace net
|
| +} // namespace
|
| +
|
| +} // namespace url_formatter
|
|
|