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

Unified Diff: net/base/net_util_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index ebc330754fd929a395d4ae2b6bc22ed40a02d2b3..7cc6ae06529beb562067f0d9d390672b26e9136c 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -50,12 +50,9 @@ struct HeaderParamCase {
};
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"
-};
+ "", "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 {
const char* input;
@@ -67,294 +64,244 @@ struct IDNTestCase {
// from exhaustive. We may have to generate all the combinations
// of languages (powerset of a set of all the languages).
const IDNTestCase idn_cases[] = {
- // No IDN
- {"www.google.com", L"www.google.com",
- {true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true}},
- {"www.google.com.", L"www.google.com.",
- {true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true}},
- {".", L".",
- {true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true}},
- {"", L"",
- {true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true}},
- // IDN
- // Hanzi (Traditional Chinese)
- {"xn--1lq90ic7f1rc.cn", L"\x5317\x4eac\x5927\x5b78.cn",
- {true, false, true, true, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, true, true, false,
- true}},
- // Hanzi ('video' in Simplified Chinese : will pass only in zh-CN,zh)
- {"xn--cy2a840a.com", L"\x89c6\x9891.com",
- {true, false, true, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- true}},
- // Hanzi + '123'
- {"www.xn--123-p18d.com", L"www.\x4e00" L"123.com",
- {true, false, true, true, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, true, true, false,
- true}},
- // Hanzi + Latin : U+56FD is simplified and is regarded
- // as not supported in zh-TW.
- {"www.xn--hello-9n1hm04c.com", L"www.hello\x4e2d\x56fd.com",
- {false, false, true, true, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, true, false,
- true}},
- // Kanji + Kana (Japanese)
- {"xn--l8jvb1ey91xtjb.jp", L"\x671d\x65e5\x3042\x3055\x3072.jp",
- {true, false, false, true, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, true, false,
- false}},
- // Katakana including U+30FC
- {"xn--tckm4i2e.jp", L"\x30b3\x30de\x30fc\x30b9.jp",
- {true, false, false, true, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, true, false,
- }},
- {"xn--3ck7a7g.jp", L"\u30ce\u30f3\u30bd.jp",
- {true, false, false, true, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, true, false,
- }},
- // Katakana + Latin (Japanese)
- // TODO(jungshik): Change 'false' in the first element to 'true'
- // after upgrading to ICU 4.2.1 to use new uspoof_* APIs instead
- // of our IsIDNComponentInSingleScript().
- {"xn--e-efusa1mzf.jp", L"e\x30b3\x30de\x30fc\x30b9.jp",
- {false, false, false, true, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, true, false,
- }},
- {"xn--3bkxe.jp", L"\x30c8\x309a.jp",
- {false, false, false, true, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, true, false,
- }},
- // Hangul (Korean)
- {"www.xn--or3b17p6jjc.kr", L"www.\xc804\xc790\xc815\xbd80.kr",
- {true, false, false, false, true,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, true, false,
- false}},
- // b<u-umlaut>cher (German)
- {"xn--bcher-kva.de", L"b\x00fc" L"cher.de",
- {true, false, false, false, false,
- false, false, false, false, true,
- true, false, false, false, false,
- true, false, false, false, false,
- false}},
- // a with diaeresis
- {"www.xn--frgbolaget-q5a.se", L"www.f\x00e4rgbolaget.se",
- {true, false, false, false, false,
- false, false, false, false, false,
- true, false, true, false, false,
- true, false, false, false, false,
- false}},
- // c-cedilla (French)
- {"www.xn--alliancefranaise-npb.fr", L"www.alliancefran\x00e7" L"aise.fr",
- {true, false, false, false, false,
- false, false, false, false, true,
- false, true, false, false, false,
- false, false, false, false, false,
- false}},
- // caf'e with acute accent' (French)
- {"xn--caf-dma.fr", L"caf\x00e9.fr",
- {true, false, false, false, false,
- false, false, false, false, true,
- false, true, true, false, false,
- false, false, false, false, false,
- false}},
- // c-cedillla and a with tilde (Portuguese)
- {"xn--poema-9qae5a.com.br", L"p\x00e3oema\x00e7\x00e3.com.br",
- {true, false, false, false, false,
- false, false, false, false, false,
- false, true, false, false, false,
- false, false, false, false, false,
- false}},
- // s with caron
- {"xn--achy-f6a.com", L"\x0161" L"achy.com",
- {true, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- // TODO(jungshik) : Add examples with Cyrillic letters
- // only used in some languages written in Cyrillic.
- // Eutopia (Greek)
- {"xn--kxae4bafwg.gr", L"\x03bf\x03c5\x03c4\x03bf\x03c0\x03af\x03b1.gr",
- {true, false, false, false, false,
- false, false, false, true, false,
- false, false, false, false, false,
- false, true, false, false, false,
- false}},
- // Eutopia + 123 (Greek)
- {"xn---123-pldm0haj2bk.gr",
- L"\x03bf\x03c5\x03c4\x03bf\x03c0\x03af\x03b1-123.gr",
- {true, false, false, false, false,
- false, false, false, true, false,
- false, false, false, false, false,
- false, true, false, false, false,
- false}},
- // Cyrillic (Russian)
- {"xn--n1aeec9b.ru", L"\x0442\x043e\x0440\x0442\x044b.ru",
- {true, false, false, false, false,
- false, false, true, false, false,
- false, false, false, false, false,
- false, false, false, false, true,
- true}},
- // Cyrillic + 123 (Russian)
- {"xn---123-45dmmc5f.ru", L"\x0442\x043e\x0440\x0442\x044b-123.ru",
- {true, false, false, false, false,
- false, false, true, false, false,
- false, false, false, false, false,
- false, false, false, false, true,
- true}},
- // Arabic
- {"xn--mgba1fmg.ar", L"\x0627\x0641\x0644\x0627\x0645.ar",
- {true, false, false, false, false,
- false, true, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- // Hebrew
- {"xn--4dbib.he", L"\x05d5\x05d0\x05d4.he",
- {true, false, false, false, false,
- true, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, true,
- false}},
- // Thai
- {"xn--12c2cc4ag3b4ccu.th",
- L"\x0e2a\x0e32\x0e22\x0e01\x0e32\x0e23\x0e1a\x0e34\x0e19.th",
- {true, false, false, false, false,
- false, false, false, false, false,
- false, false, false, true, false,
- false, false, false, false, false,
- false}},
- // Devangari (Hindi)
- {"www.xn--l1b6a9e1b7c.in", L"www.\x0905\x0915\x094b\x0932\x093e.in",
- {true, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, true,
- false, false, false, false, false,
- false}},
- // Invalid IDN
- {"xn--hello?world.com", NULL,
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- // Unsafe IDNs
- // "payp<alpha>l.com"
- {"www.xn--paypl-g9d.com", L"payp\x03b1l.com",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- // google.gr with Greek omicron and epsilon
- {"xn--ggl-6xc1ca.gr", L"g\x03bf\x03bfgl\x03b5.gr",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- // google.ru with Cyrillic o
- {"xn--ggl-tdd6ba.ru", L"g\x043e\x043egl\x0435.ru",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- // h<e with acute>llo<China in Han>.cn
- {"xn--hllo-bpa7979ih5m.cn", L"h\x00e9llo\x4e2d\x56fd.cn",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- // <Greek rho><Cyrillic a><Cyrillic u>.ru
- {"xn--2xa6t2b.ru", L"\x03c1\x0430\x0443.ru",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- // One that's really long that will force a buffer realloc
- {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
- "aaaaaaa",
- L"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
- L"aaaaaaaa",
- {true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true, true, true, true, true,
- true}},
- // Test cases for characters we blacklisted although allowed in IDN.
- // Embedded spaces will be turned to %20 in the display.
- // TODO(jungshik): We need to have more cases. This is a typical
- // data-driven trap. The following test cases need to be separated
- // and tested only for a couple of languages.
- {"xn--osd3820f24c.kr", L"\xac00\xb098\x115f.kr",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false}},
- {"www.xn--google-ho0coa.com", L"www.\x2039google\x203a.com",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- }},
- {"google.xn--comabc-k8d", L"google.com\x0338" L"abc",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- }},
- {"google.xn--com-oh4ba.evil.jp", L"google.com\x309a\x309a.evil.jp",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- }},
- {"google.xn--comevil-v04f.jp", L"google.com\x30ce" L"evil.jp",
- {false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- false, false, false, false, false,
- }},
+ // No IDN
+ {"www.google.com",
+ L"www.google.com",
+ {true, true, true, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true}},
+ {"www.google.com.",
+ L"www.google.com.",
+ {true, true, true, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true}},
+ {".",
+ L".",
+ {true, true, true, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true}},
+ {"",
+ L"",
+ {true, true, true, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true}},
+ // IDN
+ // Hanzi (Traditional Chinese)
+ {"xn--1lq90ic7f1rc.cn",
+ L"\x5317\x4eac\x5927\x5b78.cn",
+ {true, false, true, true, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, true, true, false, true}},
+ // Hanzi ('video' in Simplified Chinese : will pass only in zh-CN,zh)
+ {"xn--cy2a840a.com",
+ L"\x89c6\x9891.com",
+ {true, false, true, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, true}},
+ // Hanzi + '123'
+ {"www.xn--123-p18d.com",
+ L"www.\x4e00"
+ L"123.com",
+ {true, false, true, true, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, true, true, false, true}},
+ // Hanzi + Latin : U+56FD is simplified and is regarded
+ // as not supported in zh-TW.
+ {"www.xn--hello-9n1hm04c.com",
+ L"www.hello\x4e2d\x56fd.com",
+ {false, false, true, true, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, true, false, true}},
+ // Kanji + Kana (Japanese)
+ {"xn--l8jvb1ey91xtjb.jp",
+ L"\x671d\x65e5\x3042\x3055\x3072.jp",
+ {true, false, false, true, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, true, false, false}},
+ // Katakana including U+30FC
+ {"xn--tckm4i2e.jp",
+ L"\x30b3\x30de\x30fc\x30b9.jp",
+ {
+ true, false, false, true, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, true, false,
+ }},
+ {"xn--3ck7a7g.jp",
+ L"\u30ce\u30f3\u30bd.jp",
+ {
+ true, false, false, true, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, true, false,
+ }},
+ // Katakana + Latin (Japanese)
+ // TODO(jungshik): Change 'false' in the first element to 'true'
+ // after upgrading to ICU 4.2.1 to use new uspoof_* APIs instead
+ // of our IsIDNComponentInSingleScript().
+ {"xn--e-efusa1mzf.jp",
+ L"e\x30b3\x30de\x30fc\x30b9.jp",
+ {
+ false, false, false, true, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, true, false,
+ }},
+ {"xn--3bkxe.jp",
+ L"\x30c8\x309a.jp",
+ {
+ false, false, false, true, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, true, false,
+ }},
+ // Hangul (Korean)
+ {"www.xn--or3b17p6jjc.kr",
+ L"www.\xc804\xc790\xc815\xbd80.kr",
+ {true, false, false, false, true, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, true, false, false}},
+ // b<u-umlaut>cher (German)
+ {"xn--bcher-kva.de",
+ L"b\x00fc"
+ L"cher.de",
+ {true, false, false, false, false, false, false, false, false, true, true,
+ false, false, false, false, true, false, false, false, false, false}},
+ // a with diaeresis
+ {"www.xn--frgbolaget-q5a.se",
+ L"www.f\x00e4rgbolaget.se",
+ {true, false, false, false, false, false, false, false, false, false, true,
+ false, true, false, false, true, false, false, false, false, false}},
+ // c-cedilla (French)
+ {"www.xn--alliancefranaise-npb.fr",
+ L"www.alliancefran\x00e7"
+ L"aise.fr",
+ {true, false, false, false, false, false, false, false, false, true, false,
+ true, false, false, false, false, false, false, false, false, false}},
+ // caf'e with acute accent' (French)
+ {"xn--caf-dma.fr",
+ L"caf\x00e9.fr",
+ {true, false, false, false, false, false, false, false, false, true, false,
+ true, true, false, false, false, false, false, false, false, false}},
+ // c-cedillla and a with tilde (Portuguese)
+ {"xn--poema-9qae5a.com.br",
+ L"p\x00e3oema\x00e7\x00e3.com.br",
+ {true, false, false, false, false, false, false, false, false, false,
+ false, true, false, false, false, false, false, false, false, false,
+ false}},
+ // s with caron
+ {"xn--achy-f6a.com",
+ L"\x0161"
+ L"achy.com",
+ {true, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ false}},
+ // TODO(jungshik) : Add examples with Cyrillic letters
+ // only used in some languages written in Cyrillic.
+ // Eutopia (Greek)
+ {"xn--kxae4bafwg.gr",
+ L"\x03bf\x03c5\x03c4\x03bf\x03c0\x03af\x03b1.gr",
+ {true, false, false, false, false, false, false, false, true, false, false,
+ false, false, false, false, false, true, false, false, false, false}},
+ // Eutopia + 123 (Greek)
+ {"xn---123-pldm0haj2bk.gr",
+ L"\x03bf\x03c5\x03c4\x03bf\x03c0\x03af\x03b1-123.gr",
+ {true, false, false, false, false, false, false, false, true, false, false,
+ false, false, false, false, false, true, false, false, false, false}},
+ // Cyrillic (Russian)
+ {"xn--n1aeec9b.ru",
+ L"\x0442\x043e\x0440\x0442\x044b.ru",
+ {true, false, false, false, false, false, false, true, false, false, false,
+ false, false, false, false, false, false, false, false, true, true}},
+ // Cyrillic + 123 (Russian)
+ {"xn---123-45dmmc5f.ru",
+ L"\x0442\x043e\x0440\x0442\x044b-123.ru",
+ {true, false, false, false, false, false, false, true, false, false, false,
+ false, false, false, false, false, false, false, false, true, true}},
+ // Arabic
+ {"xn--mgba1fmg.ar",
+ L"\x0627\x0641\x0644\x0627\x0645.ar",
+ {true, false, false, false, false, false, true, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false}},
+ // Hebrew
+ {"xn--4dbib.he",
+ L"\x05d5\x05d0\x05d4.he",
+ {true, false, false, false, false, true, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, true, false}},
+ // Thai
+ {"xn--12c2cc4ag3b4ccu.th",
+ L"\x0e2a\x0e32\x0e22\x0e01\x0e32\x0e23\x0e1a\x0e34\x0e19.th",
+ {true, false, false, false, false, false, false, false, false, false,
+ false, false, false, true, false, false, false, false, false, false,
+ false}},
+ // Devangari (Hindi)
+ {"www.xn--l1b6a9e1b7c.in",
+ L"www.\x0905\x0915\x094b\x0932\x093e.in",
+ {true, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, true, false, false, false, false, false,
+ false}},
+ // Invalid IDN
+ {"xn--hello?world.com",
+ NULL,
+ {false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ false}},
+ // Unsafe IDNs
+ // "payp<alpha>l.com"
+ {"www.xn--paypl-g9d.com",
+ L"payp\x03b1l.com",
+ {false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ false}},
+ // google.gr with Greek omicron and epsilon
+ {"xn--ggl-6xc1ca.gr",
+ L"g\x03bf\x03bfgl\x03b5.gr",
+ {false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ false}},
+ // google.ru with Cyrillic o
+ {"xn--ggl-tdd6ba.ru",
+ L"g\x043e\x043egl\x0435.ru",
+ {false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ false}},
+ // h<e with acute>llo<China in Han>.cn
+ {"xn--hllo-bpa7979ih5m.cn",
+ L"h\x00e9llo\x4e2d\x56fd.cn",
+ {false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ false}},
+ // <Greek rho><Cyrillic a><Cyrillic u>.ru
+ {"xn--2xa6t2b.ru",
+ L"\x03c1\x0430\x0443.ru",
+ {false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ false}},
+ // One that's really long that will force a buffer realloc
+ {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaa",
+ L"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ L"aaaaaaaa",
+ {true, true, true, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true}},
+ // Test cases for characters we blacklisted although allowed in IDN.
+ // Embedded spaces will be turned to %20 in the display.
+ // TODO(jungshik): We need to have more cases. This is a typical
+ // data-driven trap. The following test cases need to be separated
+ // and tested only for a couple of languages.
+ {"xn--osd3820f24c.kr",
+ L"\xac00\xb098\x115f.kr",
+ {false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ false}},
+ {"www.xn--google-ho0coa.com",
+ L"www.\x2039google\x203a.com",
+ {
+ false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ }},
+ {"google.xn--comabc-k8d",
+ L"google.com\x0338"
+ L"abc",
+ {
+ false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ }},
+ {"google.xn--com-oh4ba.evil.jp",
+ L"google.com\x309a\x309a.evil.jp",
+ {
+ false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ }},
+ {"google.xn--comevil-v04f.jp",
+ L"google.com\x30ce"
+ L"evil.jp",
+ {
+ false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false,
+ }},
#if 0
// These two cases are special. We need a separate test.
// U+3000 and U+3002 are normalized to ASCII space and dot.
@@ -434,7 +381,8 @@ void VerboseExpect(size_t expected,
size_t position,
const base::string16& formatted_url) {
EXPECT_EQ(expected, actual) << "Original URL: " << original_url
- << " (at char " << position << ")\nFormatted URL: " << formatted_url;
+ << " (at char " << position
+ << ")\nFormatted URL: " << formatted_url;
}
void CheckAdjustedOffsets(const std::string& url_string,
@@ -449,16 +397,25 @@ void CheckAdjustedOffsets(const std::string& url_string,
offsets.push_back(i);
offsets.push_back(500000); // Something larger than any input length.
offsets.push_back(std::string::npos);
- base::string16 formatted_url = FormatUrlWithOffsets(url, languages,
- format_types, unescape_rules, NULL, NULL, &offsets);
+ base::string16 formatted_url = FormatUrlWithOffsets(
+ url, languages, format_types, unescape_rules, NULL, NULL, &offsets);
for (size_t i = 0; i < url_length; ++i)
VerboseExpect(output_offsets[i], offsets[i], url_string, i, formatted_url);
- VerboseExpect(formatted_url.length(), offsets[url_length], url_string,
- url_length, formatted_url);
- VerboseExpect(base::string16::npos, offsets[url_length + 1], url_string,
- 500000, formatted_url);
- VerboseExpect(base::string16::npos, offsets[url_length + 2], url_string,
- std::string::npos, formatted_url);
+ VerboseExpect(formatted_url.length(),
+ offsets[url_length],
+ url_string,
+ url_length,
+ formatted_url);
+ VerboseExpect(base::string16::npos,
+ offsets[url_length + 1],
+ url_string,
+ 500000,
+ formatted_url);
+ VerboseExpect(base::string16::npos,
+ offsets[url_length + 2],
+ url_string,
+ std::string::npos,
+ formatted_url);
}
// Helper to strignize an IP number (used to define expectations).
@@ -480,45 +437,31 @@ TEST(NetUtilTest, GetIdentityFromURL) {
const char* expected_username;
const char* expected_password;
} tests[] = {
- {
- "http://username:password@google.com",
- "username",
- "password",
- },
- { // Test for http://crbug.com/19200
- "http://username:p@ssword@google.com",
- "username",
- "p@ssword",
- },
- { // Special URL characters should be unescaped.
- "http://username:p%3fa%26s%2fs%23@google.com",
- "username",
- "p?a&s/s#",
- },
- { // Username contains %20.
- "http://use rname:password@google.com",
- "use rname",
- "password",
- },
- { // Keep %00 as is.
- "http://use%00rname:password@google.com",
- "use%00rname",
- "password",
- },
- { // Use a '+' in the username.
- "http://use+rname:password@google.com",
- "use+rname",
- "password",
- },
- { // Use a '&' in the password.
- "http://username:p&ssword@google.com",
- "username",
- "p&ssword",
- },
- };
+ {
+ "http://username:password@google.com", "username", "password",
+ },
+ {// Test for http://crbug.com/19200
+ "http://username:p@ssword@google.com", "username", "p@ssword",
+ },
+ {// Special URL characters should be unescaped.
+ "http://username:p%3fa%26s%2fs%23@google.com", "username", "p?a&s/s#",
+ },
+ {// Username contains %20.
+ "http://use rname:password@google.com", "use rname", "password",
+ },
+ {// Keep %00 as is.
+ "http://use%00rname:password@google.com", "use%00rname", "password",
+ },
+ {// Use a '+' in the username.
+ "http://use+rname:password@google.com", "use+rname", "password",
+ },
+ {// Use a '&' in the password.
+ "http://username:p&ssword@google.com", "username", "p&ssword",
+ },
+ };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
- tests[i].input_url));
+ SCOPED_TRACE(
+ base::StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url));
GURL url(tests[i].input_url);
base::string16 username, password;
@@ -558,7 +501,7 @@ const char* google_headers =
"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"
+ "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"
@@ -570,11 +513,11 @@ const char* google_headers =
TEST(NetUtilTest, GetSpecificHeader) {
const HeaderCase tests[] = {
- {"content-type", "text/html; charset=utf-8"},
- {"CONTENT-LENGTH", "378557"},
- {"Date", "Mon, 13 Nov 2006 21:38:09 GMT"},
- {"Bad-Header", ""},
- {"", ""},
+ {"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.
@@ -598,9 +541,9 @@ TEST(NetUtilTest, IDNToUnicodeFast) {
if (j == 3 || j == 17 || j == 18)
continue;
base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j]));
- base::string16 expected(idn_cases[i].unicode_allowed[j] ?
- WideToUTF16(idn_cases[i].unicode_output) :
- ASCIIToUTF16(idn_cases[i].input));
+ base::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);
}
@@ -614,9 +557,9 @@ TEST(NetUtilTest, IDNToUnicodeSlow) {
if (!(j == 3 || j == 17 || j == 18))
continue;
base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j]));
- base::string16 expected(idn_cases[i].unicode_allowed[j] ?
- WideToUTF16(idn_cases[i].unicode_output) :
- ASCIIToUTF16(idn_cases[i].input));
+ base::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);
}
@@ -625,33 +568,34 @@ TEST(NetUtilTest, IDNToUnicodeSlow) {
TEST(NetUtilTest, CompliantHost) {
const CompliantHostCase compliant_host_cases[] = {
- {"", "", false},
- {"a", "", true},
- {"-", "", false},
- {".", "", false},
- {"9", "", true},
- {"9a", "", true},
- {"a.", "", true},
- {"a.a", "", true},
- {"9.a", "", true},
- {"a.9", "", true},
- {"_9a", "", false},
- {"-9a", "", false},
- {"-9a", "a", true},
- {"a.a9", "", true},
- {"a.-a9", "", false},
- {"a+9a", "", false},
- {"-a.a9", "", true},
- {"1-.a-b", "", true},
- {"1_.a-b", "", false},
- {"1-2.a_b", "", true},
- {"a.b.c.d.e", "", true},
- {"1.2.3.4.5", "", true},
- {"1.2.3.4.5.", "", true},
+ {"", "", false},
+ {"a", "", true},
+ {"-", "", false},
+ {".", "", false},
+ {"9", "", true},
+ {"9a", "", true},
+ {"a.", "", true},
+ {"a.a", "", true},
+ {"9.a", "", true},
+ {"a.9", "", true},
+ {"_9a", "", false},
+ {"-9a", "", false},
+ {"-9a", "a", true},
+ {"a.a9", "", true},
+ {"a.-a9", "", false},
+ {"a+9a", "", false},
+ {"-a.a9", "", true},
+ {"1-.a-b", "", true},
+ {"1_.a-b", "", false},
+ {"1-2.a_b", "", true},
+ {"a.b.c.d.e", "", true},
+ {"1.2.3.4.5", "", true},
+ {"1.2.3.4.5.", "", true},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(compliant_host_cases); ++i) {
- EXPECT_EQ(compliant_host_cases[i].expected_output,
+ EXPECT_EQ(
+ compliant_host_cases[i].expected_output,
IsCanonicalizedHostCompliant(compliant_host_cases[i].host,
compliant_host_cases[i].desired_tld));
}
@@ -680,53 +624,35 @@ struct GetDirectoryListingEntryCase {
} // 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"},
+ {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_UNSAFE(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);
+ 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);
}
}
@@ -739,30 +665,27 @@ TEST(NetUtilTest, ParseHostAndPort) {
bool success;
const char* expected_host;
int expected_port;
- } tests[] = {
- // Valid inputs:
- {"foo:10", true, "foo", 10},
- {"foo", true, "foo", -1},
- {
- "[1080:0:0:0:8:800:200C:4171]:11",
- true,
- "[1080:0:0:0:8:800:200C:4171]",
- 11,
- },
- // Invalid inputs:
- {"foo:bar", false, "", -1},
- {"foo:", false, "", -1},
- {":", false, "", -1},
- {":80", false, "", -1},
- {"", false, "", -1},
- {"porttoolong:300000", false, "", -1},
- {"usrname@host", false, "", -1},
- {"usrname:password@host", false, "", -1},
- {":password@host", false, "", -1},
- {":password@host:80", false, "", -1},
- {":password@host", false, "", -1},
- {"@host", false, "", -1},
- };
+ } tests[] = {// Valid inputs:
+ {"foo:10", true, "foo", 10},
+ {"foo", true, "foo", -1},
+ {
+ "[1080:0:0:0:8:800:200C:4171]:11", true,
+ "[1080:0:0:0:8:800:200C:4171]", 11,
+ },
+ // Invalid inputs:
+ {"foo:bar", false, "", -1},
+ {"foo:", false, "", -1},
+ {":", false, "", -1},
+ {":80", false, "", -1},
+ {"", false, "", -1},
+ {"porttoolong:300000", false, "", -1},
+ {"usrname@host", false, "", -1},
+ {"usrname:password@host", false, "", -1},
+ {":password@host", false, "", -1},
+ {":password@host:80", false, "", -1},
+ {":password@host", false, "", -1},
+ {"@host", false, "", -1},
+ };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
std::string host;
@@ -783,13 +706,13 @@ TEST(NetUtilTest, GetHostAndPort) {
GURL url;
const char* expected_host_and_port;
} tests[] = {
- { GURL("http://www.foo.com/x"), "www.foo.com:80"},
- { GURL("http://www.foo.com:21/x"), "www.foo.com:21"},
+ {GURL("http://www.foo.com/x"), "www.foo.com:80"},
+ {GURL("http://www.foo.com:21/x"), "www.foo.com:21"},
- // For IPv6 literals should always include the brackets.
- { GURL("http://[1::2]/x"), "[1::2]:80"},
- { GURL("http://[::a]:33/x"), "[::a]:33"},
- };
+ // For IPv6 literals should always include the brackets.
+ {GURL("http://[1::2]/x"), "[1::2]:80"},
+ {GURL("http://[::a]:33/x"), "[::a]:33"},
+ };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
std::string host_and_port = GetHostAndPort(tests[i].url);
EXPECT_EQ(std::string(tests[i].expected_host_and_port), host_and_port);
@@ -801,13 +724,13 @@ TEST(NetUtilTest, GetHostAndOptionalPort) {
GURL url;
const char* expected_host_and_port;
} tests[] = {
- { GURL("http://www.foo.com/x"), "www.foo.com"},
- { GURL("http://www.foo.com:21/x"), "www.foo.com:21"},
+ {GURL("http://www.foo.com/x"), "www.foo.com"},
+ {GURL("http://www.foo.com:21/x"), "www.foo.com:21"},
- // For IPv6 literals should always include the brackets.
- { GURL("http://[1::2]/x"), "[1::2]"},
- { GURL("http://[::a]:33/x"), "[::a]:33"},
- };
+ // For IPv6 literals should always include the brackets.
+ {GURL("http://[1::2]/x"), "[1::2]"},
+ {GURL("http://[::a]:33/x"), "[::a]:33"},
+ };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
std::string host_and_port = GetHostAndOptionalPort(tests[i].url);
EXPECT_EQ(std::string(tests[i].expected_host_and_port), host_and_port);
@@ -843,10 +766,10 @@ TEST(NetUtilTest, NetAddressToString_IPv4) {
uint8 addr[4];
const char* result;
} tests[] = {
- {{0, 0, 0, 0}, "0.0.0.0"},
- {{127, 0, 0, 1}, "127.0.0.1"},
- {{192, 168, 0, 1}, "192.168.0.1"},
- };
+ {{0, 0, 0, 0}, "0.0.0.0"},
+ {{127, 0, 0, 1}, "127.0.0.1"},
+ {{192, 168, 0, 1}, "192.168.0.1"},
+ };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
SockaddrStorage storage;
@@ -861,16 +784,16 @@ TEST(NetUtilTest, NetAddressToString_IPv6) {
uint8 addr[16];
const char* result;
} tests[] = {
- {{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA,
- 0x98, 0x76, 0x54, 0x32, 0x10},
- "fedc:ba98:7654:3210:fedc:ba98:7654:3210"},
- };
+ {{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA,
+ 0x98, 0x76, 0x54, 0x32, 0x10},
+ "fedc:ba98:7654:3210:fedc:ba98:7654:3210"},
+ };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
SockaddrStorage storage;
MakeIPv6Address(tests[i].addr, 80, &storage);
EXPECT_EQ(std::string(tests[i].result),
- NetAddressToString(storage.addr, storage.addr_len));
+ NetAddressToString(storage.addr, storage.addr_len));
}
}
@@ -878,20 +801,18 @@ TEST(NetUtilTest, NetAddressToStringWithPort_IPv4) {
uint8 addr[] = {127, 0, 0, 1};
SockaddrStorage storage;
MakeIPv4Address(addr, 166, &storage);
- std::string result = NetAddressToStringWithPort(storage.addr,
- storage.addr_len);
+ std::string result =
+ NetAddressToStringWithPort(storage.addr, storage.addr_len);
EXPECT_EQ("127.0.0.1:166", result);
}
TEST(NetUtilTest, NetAddressToStringWithPort_IPv6) {
- uint8 addr[] = {
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA,
- 0x98, 0x76, 0x54, 0x32, 0x10
- };
+ uint8 addr[] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
+ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10};
SockaddrStorage storage;
MakeIPv6Address(addr, 361, &storage);
- std::string result = NetAddressToStringWithPort(storage.addr,
- storage.addr_len);
+ std::string result =
+ NetAddressToStringWithPort(storage.addr, storage.addr_len);
// May fail on systems that don't support IPv6.
if (!result.empty())
@@ -909,181 +830,146 @@ TEST(NetUtilTest, GetHostName) {
TEST(NetUtilTest, 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, 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},
};
for (size_t i = 0; i < arraysize(tests); ++i) {
size_t prefix_len;
- base::string16 formatted = FormatUrl(
- GURL(tests[i].input), tests[i].languages, tests[i].format_types,
- tests[i].escape_rules, NULL, &prefix_len, NULL);
+ base::string16 formatted = FormatUrl(GURL(tests[i].input),
+ tests[i].languages,
+ tests[i].format_types,
+ tests[i].escape_rules,
+ NULL,
+ &prefix_len,
+ NULL);
EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description;
EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
}
@@ -1092,72 +978,92 @@ TEST(NetUtilTest, FormatUrl) {
TEST(NetUtilTest, 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,
+ 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);
+ L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
+ L"/%E3%82%B0/?q=%E3%82%B0#\x30B0"),
+ formatted);
EXPECT_EQ(WideToUTF16(L"%E3%82%B0"),
- formatted.substr(parsed.username.begin, parsed.username.len));
+ formatted.substr(parsed.username.begin, parsed.username.len));
EXPECT_EQ(WideToUTF16(L"%E3%83%BC"),
- formatted.substr(parsed.password.begin, parsed.password.len));
+ formatted.substr(parsed.password.begin, parsed.password.len));
EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
- formatted.substr(parsed.host.begin, parsed.host.len));
+ formatted.substr(parsed.host.begin, parsed.host.len));
EXPECT_EQ(WideToUTF16(L"8080"),
- formatted.substr(parsed.port.begin, parsed.port.len));
+ formatted.substr(parsed.port.begin, parsed.port.len));
EXPECT_EQ(WideToUTF16(L"/%E3%82%B0/"),
- formatted.substr(parsed.path.begin, parsed.path.len));
+ formatted.substr(parsed.path.begin, parsed.path.len));
EXPECT_EQ(WideToUTF16(L"q=%E3%82%B0"),
- formatted.substr(parsed.query.begin, parsed.query.len));
+ formatted.substr(parsed.query.begin, parsed.query.len));
EXPECT_EQ(WideToUTF16(L"\x30B0"),
- formatted.substr(parsed.ref.begin, parsed.ref.len));
+ 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);
- EXPECT_EQ(WideToUTF16(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
- L"/\x30B0/?q=\x30B0#\x30B0"), formatted);
+ 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);
+ EXPECT_EQ(WideToUTF16(
+ L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
+ L"/\x30B0/?q=\x30B0#\x30B0"),
+ formatted);
EXPECT_EQ(WideToUTF16(L"\x30B0"),
- formatted.substr(parsed.username.begin, parsed.username.len));
+ formatted.substr(parsed.username.begin, parsed.username.len));
EXPECT_EQ(WideToUTF16(L"\x30FC"),
- formatted.substr(parsed.password.begin, parsed.password.len));
+ formatted.substr(parsed.password.begin, parsed.password.len));
EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
- formatted.substr(parsed.host.begin, parsed.host.len));
+ formatted.substr(parsed.host.begin, parsed.host.len));
EXPECT_EQ(WideToUTF16(L"8080"),
- formatted.substr(parsed.port.begin, parsed.port.len));
+ formatted.substr(parsed.port.begin, parsed.port.len));
EXPECT_EQ(WideToUTF16(L"/\x30B0/"),
- formatted.substr(parsed.path.begin, parsed.path.len));
+ formatted.substr(parsed.path.begin, parsed.path.len));
EXPECT_EQ(WideToUTF16(L"q=\x30B0"),
- formatted.substr(parsed.query.begin, parsed.query.len));
+ formatted.substr(parsed.query.begin, parsed.query.len));
EXPECT_EQ(WideToUTF16(L"\x30B0"),
- formatted.substr(parsed.ref.begin, parsed.ref.len));
+ 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);
- EXPECT_EQ(WideToUTF16(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
- L"/\x30B0/?q=\x30B0#\x30B0"), formatted);
+ 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);
+ EXPECT_EQ(WideToUTF16(
+ L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
+ L"/\x30B0/?q=\x30B0#\x30B0"),
+ formatted);
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
- formatted.substr(parsed.host.begin, parsed.host.len));
+ formatted.substr(parsed.host.begin, parsed.host.len));
EXPECT_EQ(WideToUTF16(L"8080"),
- formatted.substr(parsed.port.begin, parsed.port.len));
+ formatted.substr(parsed.port.begin, parsed.port.len));
EXPECT_EQ(WideToUTF16(L"/\x30B0/"),
- formatted.substr(parsed.path.begin, parsed.path.len));
+ formatted.substr(parsed.path.begin, parsed.path.len));
EXPECT_EQ(WideToUTF16(L"q=\x30B0"),
- formatted.substr(parsed.query.begin, parsed.query.len));
+ formatted.substr(parsed.query.begin, parsed.query.len));
EXPECT_EQ(WideToUTF16(L"\x30B0"),
- formatted.substr(parsed.ref.begin, parsed.ref.len));
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// View-source case.
formatted =
@@ -1169,21 +1075,21 @@ TEST(NetUtilTest, FormatUrlParsed) {
NULL,
NULL);
EXPECT_EQ(WideToUTF16(L"view-source:http://host:81/path?query#ref"),
- formatted);
+ formatted);
EXPECT_EQ(WideToUTF16(L"view-source:http"),
- formatted.substr(parsed.scheme.begin, parsed.scheme.len));
+ formatted.substr(parsed.scheme.begin, parsed.scheme.len));
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
EXPECT_EQ(WideToUTF16(L"host"),
- formatted.substr(parsed.host.begin, parsed.host.len));
+ formatted.substr(parsed.host.begin, parsed.host.len));
EXPECT_EQ(WideToUTF16(L"81"),
- formatted.substr(parsed.port.begin, parsed.port.len));
+ formatted.substr(parsed.port.begin, parsed.port.len));
EXPECT_EQ(WideToUTF16(L"/path"),
- formatted.substr(parsed.path.begin, parsed.path.len));
+ formatted.substr(parsed.path.begin, parsed.path.len));
EXPECT_EQ(WideToUTF16(L"query"),
- formatted.substr(parsed.query.begin, parsed.query.len));
+ formatted.substr(parsed.query.begin, parsed.query.len));
EXPECT_EQ(WideToUTF16(L"ref"),
- formatted.substr(parsed.ref.begin, parsed.ref.len));
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// omit http case.
formatted = FormatUrl(GURL("http://host:8000/a?b=c#d"),
@@ -1198,15 +1104,15 @@ TEST(NetUtilTest, FormatUrlParsed) {
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
EXPECT_EQ(WideToUTF16(L"host"),
- formatted.substr(parsed.host.begin, parsed.host.len));
+ formatted.substr(parsed.host.begin, parsed.host.len));
EXPECT_EQ(WideToUTF16(L"8000"),
- formatted.substr(parsed.port.begin, parsed.port.len));
+ formatted.substr(parsed.port.begin, parsed.port.len));
EXPECT_EQ(WideToUTF16(L"/a"),
- formatted.substr(parsed.path.begin, parsed.path.len));
+ formatted.substr(parsed.path.begin, parsed.path.len));
EXPECT_EQ(WideToUTF16(L"b=c"),
- formatted.substr(parsed.query.begin, parsed.query.len));
+ formatted.substr(parsed.query.begin, parsed.query.len));
EXPECT_EQ(WideToUTF16(L"d"),
- formatted.substr(parsed.ref.begin, parsed.ref.len));
+ 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"),
@@ -1221,17 +1127,17 @@ TEST(NetUtilTest, FormatUrlParsed) {
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
EXPECT_EQ(WideToUTF16(L"http"),
- formatted.substr(parsed.scheme.begin, parsed.scheme.len));
+ formatted.substr(parsed.scheme.begin, parsed.scheme.len));
EXPECT_EQ(WideToUTF16(L"ftp.host"),
- formatted.substr(parsed.host.begin, parsed.host.len));
+ formatted.substr(parsed.host.begin, parsed.host.len));
EXPECT_EQ(WideToUTF16(L"8000"),
- formatted.substr(parsed.port.begin, parsed.port.len));
+ formatted.substr(parsed.port.begin, parsed.port.len));
EXPECT_EQ(WideToUTF16(L"/a"),
- formatted.substr(parsed.path.begin, parsed.path.len));
+ formatted.substr(parsed.path.begin, parsed.path.len));
EXPECT_EQ(WideToUTF16(L"b=c"),
- formatted.substr(parsed.query.begin, parsed.query.len));
+ formatted.substr(parsed.query.begin, parsed.query.len));
EXPECT_EQ(WideToUTF16(L"d"),
- formatted.substr(parsed.ref.begin, parsed.ref.len));
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// omit http starts with 'f' case.
formatted = FormatUrl(GURL("http://f/"),
@@ -1250,9 +1156,9 @@ TEST(NetUtilTest, FormatUrlParsed) {
EXPECT_FALSE(parsed.query.is_valid());
EXPECT_FALSE(parsed.ref.is_valid());
EXPECT_EQ(WideToUTF16(L"f"),
- formatted.substr(parsed.host.begin, parsed.host.len));
+ formatted.substr(parsed.host.begin, parsed.host.len));
EXPECT_EQ(WideToUTF16(L"/"),
- formatted.substr(parsed.path.begin, parsed.path.len));
+ formatted.substr(parsed.path.begin, parsed.path.len));
}
// Make sure that calling FormatUrl on a GURL and then converting back to a GURL
@@ -1344,115 +1250,140 @@ TEST(NetUtilTest, FormatUrlRoundTripQueryEscaped) {
}
TEST(NetUtilTest, FormatUrlWithOffsets) {
- CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing,
- 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,
+ CheckAdjustedOffsets(
+ std::string(), "en", kFormatUrlOmitNothing, 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,
basic_offsets);
const size_t omit_auth_offsets_1[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7,
- 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,
+ 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos,
+ kNpos, kNpos, kNpos, kNpos, kNpos, 7, 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);
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,
+ 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);
const size_t dont_omit_auth_offsets[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
- kNpos, kNpos, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
- kNpos, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31
- };
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 11,
+ 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 13,
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31};
// 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,
+ CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/",
+ "en",
+ kFormatUrlOmitNothing,
+ UnescapeRule::NORMAL,
dont_omit_auth_offsets);
const size_t view_source_offsets[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, kNpos,
- 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,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 18, 19, kNpos, 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);
const size_t idn_hostname_offsets_1[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
- kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12,
- 13, 14, 15, 16, 17, 18, 19
- };
+ 0, 1, 2, 3, 4, 5, 6, 7, kNpos,
+ kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
+ kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, 13,
+ 14, 15, 16, 17, 18, 19};
// Convert punycode to "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/".
- CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja",
- kFormatUrlOmitNothing, UnescapeRule::NORMAL,
+ CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/",
+ "ja",
+ kFormatUrlOmitNothing,
+ UnescapeRule::NORMAL,
idn_hostname_offsets_1);
const size_t idn_hostname_offsets_2[] = {
- 0, 1, 2, 3, 4, 5, 6, 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, 24
- };
+ 0, 1, 2, 3, 4, 5, 6, 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, 24};
// 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,
+ "zh-CN",
+ kFormatUrlOmitNothing,
+ 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,
- 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27, 28, 29, 30, kNpos, kNpos, kNpos,
- kNpos, kNpos, kNpos, kNpos, kNpos, 31, kNpos, kNpos, kNpos, kNpos, kNpos,
- kNpos, kNpos, kNpos, 32, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
- kNpos, 33, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos
- };
+ 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, kNpos, kNpos, 26, 27,
+ 28, 29, 30, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
+ kNpos, 31, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
+ 32, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 33,
+ kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos};
// 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,
+ 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,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, kNpos, kNpos, 32, kNpos, kNpos,
- 33
- };
+ 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,
+ 26, 27, 28, 29, 30, 31, kNpos, kNpos, 32, kNpos, kNpos, 33};
// 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);
+ "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z",
+ "en",
+ kFormatUrlOmitNothing,
+ 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);
+ 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);
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);
+ 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);
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);
+ 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);
}
TEST(NetUtilTest, SimplifyUrlForRequest) {
@@ -1460,40 +1391,39 @@ TEST(NetUtilTest, SimplifyUrlForRequest) {
const char* input_url;
const char* expected_simplified_url;
} tests[] = {
- {
- // Reference section should be stripped.
- "http://www.google.com:78/foobar?query=1#hash",
- "http://www.google.com:78/foobar?query=1",
- },
- {
- // Reference section can itself contain #.
- "http://192.168.0.1?query=1#hash#10#11#13#14",
- "http://192.168.0.1?query=1",
- },
- { // Strip username/password.
- "http://user:pass@google.com",
- "http://google.com/",
- },
- { // Strip both the reference and the username/password.
- "http://user:pass@google.com:80/sup?yo#X#X",
- "http://google.com/sup?yo",
- },
- { // Try an HTTPS URL -- strip both the reference and the username/password.
- "https://user:pass@google.com:80/sup?yo#X#X",
- "https://google.com:80/sup?yo",
- },
- { // Try an FTP URL -- strip both the reference and the username/password.
- "ftp://user:pass@google.com:80/sup?yo#X#X",
- "ftp://google.com:80/sup?yo",
- },
- { // Try a nonstandard URL
- "foobar://user:pass@google.com:80/sup?yo#X#X",
- "foobar://user:pass@google.com:80/sup?yo",
- },
- };
+ {// Reference section should be stripped.
+ "http://www.google.com:78/foobar?query=1#hash",
+ "http://www.google.com:78/foobar?query=1",
+ },
+ {// Reference section can itself contain #.
+ "http://192.168.0.1?query=1#hash#10#11#13#14",
+ "http://192.168.0.1?query=1",
+ },
+ {// Strip username/password.
+ "http://user:pass@google.com", "http://google.com/",
+ },
+ {// Strip both the reference and the username/password.
+ "http://user:pass@google.com:80/sup?yo#X#X",
+ "http://google.com/sup?yo",
+ },
+ {// Try an HTTPS URL -- strip both the reference and the
+ // username/password.
+ "https://user:pass@google.com:80/sup?yo#X#X",
+ "https://google.com:80/sup?yo",
+ },
+ {// Try an FTP URL -- strip both the reference and the
+ // username/password.
+ "ftp://user:pass@google.com:80/sup?yo#X#X",
+ "ftp://google.com:80/sup?yo",
+ },
+ {// Try a nonstandard URL
+ "foobar://user:pass@google.com:80/sup?yo#X#X",
+ "foobar://user:pass@google.com:80/sup?yo",
+ },
+ };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
- tests[i].input_url));
+ SCOPED_TRACE(
+ base::StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url));
GURL input_url(GURL(tests[i].input_url));
GURL expected_url(GURL(tests[i].expected_simplified_url));
EXPECT_EQ(expected_url, SimplifyUrlForRequest(input_url));
@@ -1501,8 +1431,8 @@ TEST(NetUtilTest, SimplifyUrlForRequest) {
}
TEST(NetUtilTest, SetExplicitlyAllowedPortsTest) {
- std::string invalid[] = { "1,2,a", "'1','2'", "1, 2, 3", "1 0,11,12" };
- std::string valid[] = { "", "1", "1,2", "1,2,3", "10,11,12,13" };
+ std::string invalid[] = {"1,2,a", "'1','2'", "1, 2, 3", "1 0,11,12"};
+ std::string valid[] = {"", "1", "1,2", "1,2,3", "10,11,12,13"};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) {
SetExplicitlyAllowedPorts(invalid[i]);
@@ -1565,8 +1495,7 @@ TEST(NetUtilTest, ConvertIPv4NumberToIPv6Number) {
IPAddressNumber ipv4_number;
EXPECT_TRUE(ParseIPLiteralToNumber("192.168.0.1", &ipv4_number));
- IPAddressNumber ipv6_number =
- ConvertIPv4NumberToIPv6Number(ipv4_number);
+ IPAddressNumber ipv6_number = ConvertIPv4NumberToIPv6Number(ipv4_number);
// ::ffff:192.168.0.1
EXPECT_EQ("0,0,0,0,0,0,0,0,0,0,255,255,192,168,0,1",
@@ -1600,28 +1529,16 @@ TEST(NetUtilTest, ConvertIPv4MappedToIPv4) {
// Test parsing invalid CIDR notation literals.
TEST(NetUtilTest, ParseCIDRBlock_Invalid) {
const char* bad_literals[] = {
- "foobar",
- "",
- "192.168.0.1",
- "::1",
- "/",
- "/1",
- "1",
- "192.168.1.1/-1",
- "192.168.1.1/33",
- "::1/-3",
- "a::3/129",
- "::1/x",
- "192.168.0.1//11"
- };
+ "foobar", "", "192.168.0.1", "::1", "/",
+ "/1", "1", "192.168.1.1/-1", "192.168.1.1/33", "::1/-3",
+ "a::3/129", "::1/x", "192.168.0.1//11"};
for (size_t i = 0; i < arraysize(bad_literals); ++i) {
IPAddressNumber ip_number;
size_t prefix_length_in_bits;
- EXPECT_FALSE(ParseCIDRBlock(bad_literals[i],
- &ip_number,
- &prefix_length_in_bits));
+ EXPECT_FALSE(
+ ParseCIDRBlock(bad_literals[i], &ip_number, &prefix_length_in_bits));
}
}
@@ -1630,9 +1547,8 @@ TEST(NetUtilTest, ParseCIDRBlock_Valid) {
IPAddressNumber ip_number;
size_t prefix_length_in_bits;
- EXPECT_TRUE(ParseCIDRBlock("192.168.0.1/11",
- &ip_number,
- &prefix_length_in_bits));
+ EXPECT_TRUE(
+ ParseCIDRBlock("192.168.0.1/11", &ip_number, &prefix_length_in_bits));
EXPECT_EQ("192,168,0,1", DumpIPNumber(ip_number));
EXPECT_EQ(11u, prefix_length_in_bits);
@@ -1643,62 +1559,26 @@ TEST(NetUtilTest, IPNumberMatchesPrefix) {
const char* cidr_literal;
const char* ip_literal;
bool expected_to_match;
- } tests[] = {
- // IPv4 prefix with IPv4 inputs.
- {
- "10.10.1.32/27",
- "10.10.1.44",
- true
- },
- {
- "10.10.1.32/27",
- "10.10.1.90",
- false
- },
- {
- "10.10.1.32/27",
- "10.10.1.90",
- false
- },
-
- // IPv6 prefix with IPv6 inputs.
- {
- "2001:db8::/32",
- "2001:DB8:3:4::5",
- true
- },
- {
- "2001:db8::/32",
- "2001:c8::",
- false
- },
-
- // IPv6 prefix with IPv4 inputs.
- {
- "2001:db8::/33",
- "192.168.0.1",
- false
- },
- {
- "::ffff:192.168.0.1/112",
- "192.168.33.77",
- true
- },
-
- // IPv4 prefix with IPv6 inputs.
- {
- "10.11.33.44/16",
- "::ffff:0a0b:89",
- true
- },
- {
- "10.11.33.44/16",
- "::ffff:10.12.33.44",
- false
- },
- };
+ } tests[] = {// IPv4 prefix with IPv4 inputs.
+ {"10.10.1.32/27", "10.10.1.44", true},
+ {"10.10.1.32/27", "10.10.1.90", false},
+ {"10.10.1.32/27", "10.10.1.90", false},
+
+ // IPv6 prefix with IPv6 inputs.
+ {"2001:db8::/32", "2001:DB8:3:4::5", true},
+ {"2001:db8::/32", "2001:c8::", false},
+
+ // IPv6 prefix with IPv4 inputs.
+ {"2001:db8::/33", "192.168.0.1", false},
+ {"::ffff:192.168.0.1/112", "192.168.33.77", true},
+
+ // IPv4 prefix with IPv6 inputs.
+ {"10.11.33.44/16", "::ffff:0a0b:89", true},
+ {"10.11.33.44/16", "::ffff:10.12.33.44", false},
+ };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s, %s", i,
+ SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s, %s",
+ i,
tests[i].cidr_literal,
tests[i].ip_literal));
@@ -1708,14 +1588,12 @@ TEST(NetUtilTest, IPNumberMatchesPrefix) {
IPAddressNumber ip_prefix;
size_t prefix_length_in_bits;
- EXPECT_TRUE(ParseCIDRBlock(tests[i].cidr_literal,
- &ip_prefix,
- &prefix_length_in_bits));
+ EXPECT_TRUE(ParseCIDRBlock(
+ tests[i].cidr_literal, &ip_prefix, &prefix_length_in_bits));
- EXPECT_EQ(tests[i].expected_to_match,
- IPNumberMatchesPrefix(ip_number,
- ip_prefix,
- prefix_length_in_bits));
+ EXPECT_EQ(
+ tests[i].expected_to_match,
+ IPNumberMatchesPrefix(ip_number, ip_prefix, prefix_length_in_bits));
}
}
@@ -1751,8 +1629,8 @@ TEST(NetUtilTest, IsLocalhost) {
TEST(NetUtilTest, GetNetworkList) {
NetworkInterfaceList list;
ASSERT_TRUE(GetNetworkList(&list, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES));
- for (NetworkInterfaceList::iterator it = list.begin();
- it != list.end(); ++it) {
+ for (NetworkInterfaceList::iterator it = list.begin(); it != list.end();
+ ++it) {
// Verify that the names are not empty.
EXPECT_FALSE(it->name.empty());
EXPECT_FALSE(it->friendly_name.empty());
@@ -1777,14 +1655,13 @@ TEST(NetUtilTest, GetNetworkList) {
base::ScopedNativeLibrary phlpapi_lib(
base::FilePath(FILE_PATH_LITERAL("iphlpapi.dll")));
ASSERT_TRUE(phlpapi_lib.is_valid());
- typedef NETIO_STATUS (WINAPI* ConvertInterfaceIndexToLuid)(NET_IFINDEX,
+ typedef NETIO_STATUS(WINAPI * ConvertInterfaceIndexToLuid)(NET_IFINDEX,
PNET_LUID);
ConvertInterfaceIndexToLuid interface_to_luid =
reinterpret_cast<ConvertInterfaceIndexToLuid>(
phlpapi_lib.GetFunctionPointer("ConvertInterfaceIndexToLuid"));
- typedef NETIO_STATUS (WINAPI* ConvertInterfaceLuidToGuid)(NET_LUID*,
- GUID*);
+ typedef NETIO_STATUS(WINAPI * ConvertInterfaceLuidToGuid)(NET_LUID*, GUID*);
ConvertInterfaceLuidToGuid luid_to_guid =
reinterpret_cast<ConvertInterfaceLuidToGuid>(
phlpapi_lib.GetFunctionPointer("ConvertInterfaceLuidToGuid"));
@@ -1802,7 +1679,7 @@ TEST(NetUtilTest, GetNetworkList) {
} else {
EXPECT_LT(base::win::GetVersion(), base::win::VERSION_VISTA);
EXPECT_LT(it->interface_index, 1u << 24u); // Must fit 0.x.x.x.
- EXPECT_NE(it->interface_index, 0u); // 0 means to use default.
+ EXPECT_NE(it->interface_index, 0u); // 0 means to use default.
}
if (it->type == NetworkChangeNotifier::CONNECTION_WIFI) {
EXPECT_NE(WIFI_PHY_LAYER_PROTOCOL_NONE, GetWifiPHYLayerProtocol());
@@ -1829,47 +1706,47 @@ void PrintTo(const NonUniqueNameTestData& data, std::ostream* os) {
const NonUniqueNameTestData kNonUniqueNameTestData[] = {
// Domains under ICANN-assigned domains.
- { true, "google.com" },
- { true, "google.co.uk" },
+ {true, "google.com"},
+ {true, "google.co.uk"},
// Domains under private registries.
- { true, "appspot.com" },
- { true, "test.appspot.com" },
+ {true, "appspot.com"},
+ {true, "test.appspot.com"},
// Unreserved IPv4 addresses (in various forms).
- { true, "8.8.8.8" },
- { true, "99.64.0.0" },
- { true, "212.15.0.0" },
- { true, "212.15" },
- { true, "212.15.0" },
- { true, "3557752832" },
+ {true, "8.8.8.8"},
+ {true, "99.64.0.0"},
+ {true, "212.15.0.0"},
+ {true, "212.15"},
+ {true, "212.15.0"},
+ {true, "3557752832"},
// Reserved IPv4 addresses (in various forms).
- { false, "192.168.0.0" },
- { false, "192.168.0.6" },
- { false, "10.0.0.5" },
- { false, "10.0" },
- { false, "10.0.0" },
- { false, "3232235526" },
+ {false, "192.168.0.0"},
+ {false, "192.168.0.6"},
+ {false, "10.0.0.5"},
+ {false, "10.0"},
+ {false, "10.0.0"},
+ {false, "3232235526"},
// Unreserved IPv6 addresses.
- { true, "FFC0:ba98:7654:3210:FEDC:BA98:7654:3210" },
- { true, "2000:ba98:7654:2301:EFCD:BA98:7654:3210" },
+ {true, "FFC0:ba98:7654:3210:FEDC:BA98:7654:3210"},
+ {true, "2000:ba98:7654:2301:EFCD:BA98:7654:3210"},
// Reserved IPv6 addresses.
- { false, "::192.9.5.5" },
- { false, "FEED::BEEF" },
- { false, "FEC0:ba98:7654:3210:FEDC:BA98:7654:3210" },
+ {false, "::192.9.5.5"},
+ {false, "FEED::BEEF"},
+ {false, "FEC0:ba98:7654:3210:FEDC:BA98:7654:3210"},
// 'internal'/non-IANA assigned domains.
- { false, "intranet" },
- { false, "intranet." },
- { false, "intranet.example" },
- { false, "host.intranet.example" },
+ {false, "intranet"},
+ {false, "intranet."},
+ {false, "intranet.example"},
+ {false, "host.intranet.example"},
// gTLDs under discussion, but not yet assigned.
- { false, "intranet.corp" },
- { false, "example.tech" },
- { false, "intranet.internal" },
+ {false, "intranet.corp"},
+ {false, "example.tech"},
+ {false, "intranet.internal"},
// Invalid host names are treated as unique - but expected to be
// filtered out before then.
- { true, "junk)(£)$*!@~#" },
- { true, "w$w.example.com" },
- { true, "nocolonsallowed:example" },
- { true, "[::4.5.6.9]" },
+ {true, "junk)(£)$*!@~#"},
+ {true, "w$w.example.com"},
+ {true, "nocolonsallowed:example"},
+ {true, "[::4.5.6.9]"},
};
class NetUtilNonUniqueNameTest
@@ -1892,7 +1769,8 @@ TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) {
EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname));
}
-INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest,
+INSTANTIATE_TEST_CASE_P(,
+ NetUtilNonUniqueNameTest,
testing::ValuesIn(kNonUniqueNameTestData));
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698