Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Unified Diff: net/base/net_util_unittest.cc

Issue 6898026: Eliminate wstring from base/utf_offset_string_conversions.h, net/base/escape.h, and net/base/net_... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/net_util_unittest.cc
===================================================================
--- net/base/net_util_unittest.cc (revision 82762)
+++ net/base/net_util_unittest.cc (working copy)
@@ -31,14 +31,14 @@
};
struct HeaderCase {
- const wchar_t* header_name;
- const wchar_t* expected;
+ const char* header_name;
+ const char* expected;
};
struct HeaderParamCase {
- const wchar_t* header_name;
- const wchar_t* param_name;
- const wchar_t* expected;
+ const char* header_name;
+ const char* param_name;
+ const char* expected;
};
struct FileNameCDCase {
@@ -47,12 +47,12 @@
const wchar_t* expected;
};
-const wchar_t* kLanguages[] = {
- L"", L"en", L"zh-CN", L"ja", L"ko",
- L"he", L"ar", L"ru", L"el", L"fr",
- L"de", L"pt", L"sv", L"th", L"hi",
- L"de,en", L"el,en", L"zh-TW,en", L"ko,ja", L"he,ru,en",
- L"zh,ru,en"
+const char* kLanguages[] = {
+ "", "en", "zh-CN", "ja", "ko",
+ "he", "ar", "ru", "el", "fr",
+ "de", "pt", "sv", "th", "hi",
+ "de,en", "el,en", "zh-TW,en", "ko,ja", "he,ru,en",
+ "zh,ru,en"
};
struct IDNTestCase {
@@ -451,13 +451,12 @@
// 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.
-void AppendLanguagesToOutputs(const wchar_t* languages,
- std::wstring* expected,
- std::wstring* actual) {
- expected->append(L"::");
- expected->append(languages);
- actual->append(L"::");
- actual->append(languages);
+void AppendLanguagesToOutputs(const char* languages,
+ string16* expected,
+ string16* actual) {
+ string16 to_append = ASCIIToUTF16("::") + ASCIIToUTF16(languages);
+ expected->append(to_append);
+ actual->append(to_append);
}
// Helper to strignize an IP number (used to define expectations).
@@ -650,83 +649,83 @@
}
// Just a bunch of fake headers.
-const wchar_t* google_headers =
- L"HTTP/1.1 200 OK\n"
- L"Content-TYPE: text/html; charset=utf-8\n"
- L"Content-disposition: attachment; filename=\"download.pdf\"\n"
- L"Content-Length: 378557\n"
- L"X-Google-Google1: 314159265\n"
- L"X-Google-Google2: aaaa2:7783,bbb21:9441\n"
- L"X-Google-Google4: home\n"
- L"Transfer-Encoding: chunked\n"
- L"Set-Cookie: HEHE_AT=6666x66beef666x6-66xx6666x66; Path=/mail\n"
- L"Set-Cookie: HEHE_HELP=owned:0;Path=/\n"
- L"Set-Cookie: S=gmail=Xxx-beefbeefbeef_beefb:gmail_yj=beefbeef000beefbee"
- L"fbee:gmproxy=bee-fbeefbe; Domain=.google.com; Path=/\n"
- L"X-Google-Google2: /one/two/three/four/five/six/seven-height/nine:9411\n"
- L"Server: GFE/1.3\n"
- L"Transfer-Encoding: chunked\n"
- L"Date: Mon, 13 Nov 2006 21:38:09 GMT\n"
- L"Expires: Tue, 14 Nov 2006 19:23:58 GMT\n"
- L"X-Malformed: bla; arg=test\"\n"
- L"X-Malformed2: bla; arg=\n"
- L"X-Test: bla; arg1=val1; arg2=val2";
+const char* google_headers =
+ "HTTP/1.1 200 OK\n"
+ "Content-TYPE: text/html; charset=utf-8\n"
+ "Content-disposition: attachment; filename=\"download.pdf\"\n"
+ "Content-Length: 378557\n"
+ "X-Google-Google1: 314159265\n"
+ "X-Google-Google2: aaaa2:7783,bbb21:9441\n"
+ "X-Google-Google4: home\n"
+ "Transfer-Encoding: chunked\n"
+ "Set-Cookie: HEHE_AT=6666x66beef666x6-66xx6666x66; Path=/mail\n"
+ "Set-Cookie: HEHE_HELP=owned:0;Path=/\n"
+ "Set-Cookie: S=gmail=Xxx-beefbeefbeef_beefb:gmail_yj=beefbeef000beefbee"
+ "fbee:gmproxy=bee-fbeefbe; Domain=.google.com; Path=/\n"
+ "X-Google-Google2: /one/two/three/four/five/six/seven-height/nine:9411\n"
+ "Server: GFE/1.3\n"
+ "Transfer-Encoding: chunked\n"
+ "Date: Mon, 13 Nov 2006 21:38:09 GMT\n"
+ "Expires: Tue, 14 Nov 2006 19:23:58 GMT\n"
+ "X-Malformed: bla; arg=test\"\n"
+ "X-Malformed2: bla; arg=\n"
+ "X-Test: bla; arg1=val1; arg2=val2";
TEST(NetUtilTest, GetSpecificHeader) {
const HeaderCase tests[] = {
- {L"content-type", L"text/html; charset=utf-8"},
- {L"CONTENT-LENGTH", L"378557"},
- {L"Date", L"Mon, 13 Nov 2006 21:38:09 GMT"},
- {L"Bad-Header", L""},
- {L"", L""},
+ {"content-type", "text/html; charset=utf-8"},
+ {"CONTENT-LENGTH", "378557"},
+ {"Date", "Mon, 13 Nov 2006 21:38:09 GMT"},
+ {"Bad-Header", ""},
+ {"", ""},
};
// Test first with google_headers.
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- std::wstring result = GetSpecificHeader(google_headers,
- tests[i].header_name);
+ std::string result =
+ GetSpecificHeader(google_headers, tests[i].header_name);
EXPECT_EQ(result, tests[i].expected);
}
// Test again with empty headers.
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- std::wstring result = GetSpecificHeader(L"", tests[i].header_name);
- EXPECT_EQ(result, std::wstring());
+ std::string result = GetSpecificHeader(std::string(), tests[i].header_name);
+ EXPECT_EQ(result, std::string());
}
}
TEST(NetUtilTest, GetHeaderParamValue) {
const HeaderParamCase tests[] = {
- {L"Content-type", L"charset", L"utf-8"},
- {L"content-disposition", L"filename", L"download.pdf"},
- {L"Content-Type", L"badparam", L""},
- {L"X-Malformed", L"arg", L"test\""},
- {L"X-Malformed2", L"arg", L""},
- {L"X-Test", L"arg1", L"val1"},
- {L"X-Test", L"arg2", L"val2"},
- {L"Bad-Header", L"badparam", L""},
- {L"Bad-Header", L"", L""},
- {L"", L"badparam", L""},
- {L"", L"", L""},
+ {"Content-type", "charset", "utf-8"},
+ {"content-disposition", "filename", "download.pdf"},
+ {"Content-Type", "badparam", ""},
+ {"X-Malformed", "arg", "test\""},
+ {"X-Malformed2", "arg", ""},
+ {"X-Test", "arg1", "val1"},
+ {"X-Test", "arg2", "val2"},
+ {"Bad-Header", "badparam", ""},
+ {"Bad-Header", "", ""},
+ {"", "badparam", ""},
+ {"", "", ""},
};
// TODO(mpcomplete): add tests for other formats of headers.
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- std::wstring header_value =
+ std::string header_value =
GetSpecificHeader(google_headers, tests[i].header_name);
- std::wstring result =
+ std::string result =
GetHeaderParamValue(header_value, tests[i].param_name,
QuoteRule::REMOVE_OUTER_QUOTES);
EXPECT_EQ(result, tests[i].expected);
}
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- std::wstring header_value =
- GetSpecificHeader(L"", tests[i].header_name);
- std::wstring result =
+ std::string header_value =
+ GetSpecificHeader(std::string(), tests[i].header_name);
+ std::string result =
GetHeaderParamValue(header_value, tests[i].param_name,
QuoteRule::REMOVE_OUTER_QUOTES);
- EXPECT_EQ(result, std::wstring());
+ EXPECT_EQ(result, std::string());
}
}
@@ -941,10 +940,11 @@
// ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow
if (j == 3 || j == 17 || j == 18)
continue;
- std::wstring output(IDNToUnicode(idn_cases[i].input,
- strlen(idn_cases[i].input), kLanguages[j], NULL));
- std::wstring expected(idn_cases[i].unicode_allowed[j] ?
- idn_cases[i].unicode_output : ASCIIToWide(idn_cases[i].input));
+ string16 output(IDNToUnicode(idn_cases[i].input,
+ strlen(idn_cases[i].input), kLanguages[j]));
+ string16 expected(idn_cases[i].unicode_allowed[j] ?
+ WideToUTF16(idn_cases[i].unicode_output) :
+ ASCIIToUTF16(idn_cases[i].input));
AppendLanguagesToOutputs(kLanguages[j], &expected, &output);
EXPECT_EQ(expected, output);
}
@@ -957,57 +957,17 @@
// !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast
if (!(j == 3 || j == 17 || j == 18))
continue;
- std::wstring output(IDNToUnicode(idn_cases[i].input,
- strlen(idn_cases[i].input), kLanguages[j], NULL));
- std::wstring expected(idn_cases[i].unicode_allowed[j] ?
- idn_cases[i].unicode_output : ASCIIToWide(idn_cases[i].input));
+ string16 output(IDNToUnicode(idn_cases[i].input,
+ strlen(idn_cases[i].input), kLanguages[j]));
+ string16 expected(idn_cases[i].unicode_allowed[j] ?
+ WideToUTF16(idn_cases[i].unicode_output) :
+ ASCIIToUTF16(idn_cases[i].input));
AppendLanguagesToOutputs(kLanguages[j], &expected, &output);
EXPECT_EQ(expected, output);
}
}
}
-TEST(NetUtilTest, IDNToUnicodeAdjustOffset) {
- const AdjustOffsetCase adjust_cases[] = {
- {0, 0},
- {2, 2},
- {4, 4},
- {5, 5},
- {6, string16::npos},
- {16, string16::npos},
- {17, 7},
- {18, 8},
- {19, string16::npos},
- {25, string16::npos},
- {34, 12},
- {35, 13},
- {38, 16},
- {39, string16::npos},
- {string16::npos, string16::npos},
- };
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(adjust_cases); ++i) {
- size_t offset = adjust_cases[i].input_offset;
- // "test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test"
- IDNToUnicode("test.xn--cy2a840a.xn--1lq90ic7f1rc.test", 39, L"zh-CN",
- &offset);
- EXPECT_EQ(adjust_cases[i].output_offset, offset);
- }
-
- std::vector<size_t> offsets;
- for (size_t i = 0; i < 40; ++i)
- offsets.push_back(i);
- IDNToUnicodeWithOffsets("test.xn--cy2a840a.xn--1lq90ic7f1rc.test", 39,
- L"zh-CN", &offsets);
- size_t expected[] = {0, 1, 2, 3, 4, 5, kNpos, kNpos, kNpos, kNpos, kNpos,
- kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7, 8, kNpos,
- kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
- kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, 13, 14, 15,
- 16, kNpos};
- ASSERT_EQ(40U, arraysize(expected));
- for (size_t i = 0; i < 40; ++i)
- EXPECT_EQ(expected[i], offsets[i]);
-}
-
TEST(NetUtilTest, CompliantHost) {
const CompliantHostCase compliant_host_cases[] = {
{"", "", false},
@@ -1249,6 +1209,51 @@
}
}
+TEST(NetUtilTest, AppendFormattedHostAdjustOffset) {
+ const AdjustOffsetCase adjust_cases[] = {
+ {7, 7},
+ {9, 9},
+ {11, 11},
+ {12, 12},
+ {13, string16::npos},
+ {23, string16::npos},
+ {24, 14},
+ {25, 15},
+ {26, string16::npos},
+ {32, string16::npos},
+ {41, 19},
+ {42, 20},
+ {45, 23},
+ {46, string16::npos},
+ {string16::npos, string16::npos},
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(adjust_cases); ++i) {
+ size_t offset = adjust_cases[i].input_offset;
+ // "test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test"
+ string16 output;
+ AppendFormattedHost(GURL("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/"),
+ "zh-CN", &output, NULL, &offset);
+ EXPECT_EQ(adjust_cases[i].output_offset, offset);
+ }
+
+ std::vector<size_t> offsets;
+ // 7 == "http://"
+ for (size_t i = 7; i < 47; ++i)
+ offsets.push_back(i);
+ string16 output;
+ AppendFormattedHostWithOffsets(
+ GURL("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/"), "zh-CN", &output,
+ NULL, &offsets);
+ size_t expected[] = {7, 8, 9, 10, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos,
+ kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 14, 15, kNpos,
+ kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
+ kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 19, 20, 21, 22,
+ 23, kNpos};
+ ASSERT_EQ(40U, arraysize(expected));
+ for (size_t i = 0; i < 40; ++i)
+ EXPECT_EQ(expected[i], offsets[i]);
+}
+
// This is currently a windows specific function.
#if defined(OS_WIN)
namespace {

Powered by Google App Engine
This is Rietveld 408576698