OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 {"http", "invalidportnumber.org", -5, "__0"}, | 59 {"http", "invalidportnumber.org", -5, "__0"}, |
60 {"http", "%E2%98%83.unicode.com", 80, "http_xn--n3h.unicode.com_0"}, | 60 {"http", "%E2%98%83.unicode.com", 80, "http_xn--n3h.unicode.com_0"}, |
61 {"http", String::fromUTF8("\xe2\x98\x83.unicode.com"), 80, "http_xn--n3h
.unicode.com_0"}, | 61 {"http", String::fromUTF8("\xe2\x98\x83.unicode.com"), 80, "http_xn--n3h
.unicode.com_0"}, |
62 {"http", String::fromUTF8("\xf0\x9f\x92\xa9.unicode.com"), 80, "http_xn-
-ls8h.unicode.com_0"}, | 62 {"http", String::fromUTF8("\xf0\x9f\x92\xa9.unicode.com"), 80, "http_xn-
-ls8h.unicode.com_0"}, |
63 {"file", "", 0, "file__0"}, | 63 {"file", "", 0, "file__0"}, |
64 {"data", "", 0, "__0"}, | 64 {"data", "", 0, "__0"}, |
65 {"about", "blank", 0, "__0"}, | 65 {"about", "blank", 0, "__0"}, |
66 {"non-standard", "foobar.com", 0, "non-standard__0"}, | 66 {"non-standard", "foobar.com", 0, "non-standard__0"}, |
67 }; | 67 }; |
68 | 68 |
69 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 69 for (size_t i = 0; i < arraysize(cases); ++i) { |
70 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(cases[i].protocol
, cases[i].host, cases[i].port); | 70 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(cases[i].protocol
, cases[i].host, cases[i].port); |
71 String identifier = createDatabaseIdentifierFromSecurityOrigin(origin.ge
t()); | 71 String identifier = createDatabaseIdentifierFromSecurityOrigin(origin.ge
t()); |
72 EXPECT_EQ(cases[i].expectedIdentifier, identifier) << "test case " << or
igin->toString(); | 72 EXPECT_EQ(cases[i].expectedIdentifier, identifier) << "test case " << or
igin->toString(); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 // This tests the encoding of a hostname including every character in the range
[\x1f, \x80]. | 76 // This tests the encoding of a hostname including every character in the range
[\x1f, \x80]. |
77 TEST(DatabaseIdentifierTest, CreateIdentifierAllHostChars) | 77 TEST(DatabaseIdentifierTest, CreateIdentifierAllHostChars) |
78 { | 78 { |
79 struct Case { | 79 struct Case { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 {"x\x7ax", "http_xzx_0", true}, | 181 {"x\x7ax", "http_xzx_0", true}, |
182 {"x\x7bx", "http_x%7bx_0", false}, | 182 {"x\x7bx", "http_x%7bx_0", false}, |
183 {"x\x7cx", "http_x%7cx_0", false}, | 183 {"x\x7cx", "http_x%7cx_0", false}, |
184 {"x\x7dx", "http_x%7dx_0", false}, | 184 {"x\x7dx", "http_x%7dx_0", false}, |
185 {"x\x7ex", "__0", false}, | 185 {"x\x7ex", "__0", false}, |
186 {"x\x7fx", "__0", false}, | 186 {"x\x7fx", "__0", false}, |
187 | 187 |
188 {"x\x80x", "__0", false}, | 188 {"x\x80x", "__0", false}, |
189 }; | 189 }; |
190 | 190 |
191 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 191 for (size_t i = 0; i < arraysize(cases); ++i) { |
192 RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", cases[i].
hostname, 80); | 192 RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", cases[i].
hostname, 80); |
193 String identifier = createDatabaseIdentifierFromSecurityOrigin(origin.ge
t()); | 193 String identifier = createDatabaseIdentifierFromSecurityOrigin(origin.ge
t()); |
194 EXPECT_EQ(cases[i].expected, identifier) << "test case " << i << ": \""
<< cases[i].hostname << "\""; | 194 EXPECT_EQ(cases[i].expected, identifier) << "test case " << i << ": \""
<< cases[i].hostname << "\""; |
195 if (cases[i].shouldRoundTrip) { | 195 if (cases[i].shouldRoundTrip) { |
196 RefPtr<SecurityOrigin> parsedOrigin = createSecurityOriginFromDataba
seIdentifier(identifier); | 196 RefPtr<SecurityOrigin> parsedOrigin = createSecurityOriginFromDataba
seIdentifier(identifier); |
197 EXPECT_EQ(cases[i].hostname.lower(), parsedOrigin->host()) << "test
case " << i << ": \"" << cases[i].hostname << "\""; | 197 EXPECT_EQ(cases[i].hostname.lower(), parsedOrigin->host()) << "test
case " << i << ": \"" << cases[i].hostname << "\""; |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 } | 201 } |
(...skipping 16 matching lines...) Expand all Loading... |
218 {"unknown_google.com_0", "", "", 0, "null", true}, | 218 {"unknown_google.com_0", "", "", 0, "null", true}, |
219 {"http_nondefaultport.net_8001", "http", "nondefaultport.net", 8001, "ht
tp://nondefaultport.net:8001", false}, | 219 {"http_nondefaultport.net_8001", "http", "nondefaultport.net", 8001, "ht
tp://nondefaultport.net:8001", false}, |
220 {"file__0", "", "", 0, "null", true}, | 220 {"file__0", "", "", 0, "null", true}, |
221 {"__0", "", "", 0, "null", true}, | 221 {"__0", "", "", 0, "null", true}, |
222 {"http_foo_bar_baz.org_0", "http", "foo_bar_baz.org", 0, "http://foo_bar
_baz.org", false}, | 222 {"http_foo_bar_baz.org_0", "http", "foo_bar_baz.org", 0, "http://foo_bar
_baz.org", false}, |
223 {"http_xn--n3h.unicode.com_0", "http", "xn--n3h.unicode.com", 0, "http:/
/xn--n3h.unicode.com", false}, | 223 {"http_xn--n3h.unicode.com_0", "http", "xn--n3h.unicode.com", 0, "http:/
/xn--n3h.unicode.com", false}, |
224 {"http_dot.com_0", "http", "dot.com", 0, "http://dot.com", false}, | 224 {"http_dot.com_0", "http", "dot.com", 0, "http://dot.com", false}, |
225 {"http_escaped%3Dfun.com_0", "http", "escaped%3dfun.com", 0, "http://esc
aped%3dfun.com", false}, | 225 {"http_escaped%3Dfun.com_0", "http", "escaped%3dfun.com", 0, "http://esc
aped%3dfun.com", false}, |
226 }; | 226 }; |
227 | 227 |
228 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(validCases); ++i) { | 228 for (size_t i = 0; i < arraysize(validCases); ++i) { |
229 RefPtr<SecurityOrigin> origin = createSecurityOriginFromDatabaseIdentifi
er(validCases[i].identifier); | 229 RefPtr<SecurityOrigin> origin = createSecurityOriginFromDatabaseIdentifi
er(validCases[i].identifier); |
230 EXPECT_EQ(validCases[i].expectedProtocol, origin->protocol()) << "test c
ase " << i; | 230 EXPECT_EQ(validCases[i].expectedProtocol, origin->protocol()) << "test c
ase " << i; |
231 EXPECT_EQ(validCases[i].expectedHost, origin->host()) << "test case " <<
i; | 231 EXPECT_EQ(validCases[i].expectedHost, origin->host()) << "test case " <<
i; |
232 EXPECT_EQ(validCases[i].expectedPort, origin->port()) << "test case " <<
i; | 232 EXPECT_EQ(validCases[i].expectedPort, origin->port()) << "test case " <<
i; |
233 EXPECT_EQ(validCases[i].expectedStringRepresentation, origin->toString()
) << "test case " << i; | 233 EXPECT_EQ(validCases[i].expectedStringRepresentation, origin->toString()
) << "test case " << i; |
234 EXPECT_EQ(validCases[i].expectedUnique, origin->isUnique()) << "test cas
e " << i; | 234 EXPECT_EQ(validCases[i].expectedUnique, origin->isUnique()) << "test cas
e " << i; |
235 } | 235 } |
236 | 236 |
237 String bogusIdentifiers[] = { | 237 String bogusIdentifiers[] = { |
238 "", "_", "__", | 238 "", "_", "__", |
239 String("\x00", 1), | 239 String("\x00", 1), |
240 String("http_\x00_0", 8), | 240 String("http_\x00_0", 8), |
241 "ht\x7ctp_badprotocol.com_0", | 241 "ht\x7ctp_badprotocol.com_0", |
242 "http_unescaped_percent_%.com_0", | 242 "http_unescaped_percent_%.com_0", |
243 "http_port_too_big.net_75000", | 243 "http_port_too_big.net_75000", |
244 "http_port_too_small.net_-25", | 244 "http_port_too_small.net_-25", |
245 "http_shouldbeescaped\x7c.com_0", | 245 "http_shouldbeescaped\x7c.com_0", |
246 "http_latin1\x8a.org_8001", | 246 "http_latin1\x8a.org_8001", |
247 String::fromUTF8("http_\xe2\x98\x83.unicode.com_0"), | 247 String::fromUTF8("http_\xe2\x98\x83.unicode.com_0"), |
248 "http_dot%252ecom_0", | 248 "http_dot%252ecom_0", |
249 "HtTp_NonCanonicalRepresenTation_0", | 249 "HtTp_NonCanonicalRepresenTation_0", |
250 "http_non_ascii.\xa1.com_0", | 250 "http_non_ascii.\xa1.com_0", |
251 "http_not_canonical_escape%3d_0", | 251 "http_not_canonical_escape%3d_0", |
252 }; | 252 }; |
253 | 253 |
254 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(bogusIdentifiers); ++i) { | 254 for (size_t i = 0; i < arraysize(bogusIdentifiers); ++i) { |
255 RefPtr<SecurityOrigin> origin = createSecurityOriginFromDatabaseIdentifi
er(bogusIdentifiers[i]); | 255 RefPtr<SecurityOrigin> origin = createSecurityOriginFromDatabaseIdentifi
er(bogusIdentifiers[i]); |
256 EXPECT_EQ("null", origin->toString()) << "test case " << i; | 256 EXPECT_EQ("null", origin->toString()) << "test case " << i; |
257 EXPECT_EQ(true, origin->isUnique()) << "test case " << i; | 257 EXPECT_EQ(true, origin->isUnique()) << "test case " << i; |
258 } | 258 } |
259 } | 259 } |
260 | 260 |
261 } // namespace | 261 } // namespace |
262 | 262 |
OLD | NEW |