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

Side by Side Diff: third_party/WebKit/Source/platform/weborigin/DatabaseIdentifierTest.cpp

Issue 1548993002: Switch to standard integer types in base/strings/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 unified diff | Download patch
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 {"http", "invalidportnumber.org", -5, "__0"}, 52 {"http", "invalidportnumber.org", -5, "__0"},
53 {"http", "%E2%98%83.unicode.com", 80, "http_xn--n3h.unicode.com_0"}, 53 {"http", "%E2%98%83.unicode.com", 80, "http_xn--n3h.unicode.com_0"},
54 {"http", String::fromUTF8("\xe2\x98\x83.unicode.com"), 80, "http_xn--n3h .unicode.com_0"}, 54 {"http", String::fromUTF8("\xe2\x98\x83.unicode.com"), 80, "http_xn--n3h .unicode.com_0"},
55 {"http", String::fromUTF8("\xf0\x9f\x92\xa9.unicode.com"), 80, "http_xn- -ls8h.unicode.com_0"}, 55 {"http", String::fromUTF8("\xf0\x9f\x92\xa9.unicode.com"), 80, "http_xn- -ls8h.unicode.com_0"},
56 {"file", "", 0, "file__0"}, 56 {"file", "", 0, "file__0"},
57 {"data", "", 0, "__0"}, 57 {"data", "", 0, "__0"},
58 {"about", "blank", 0, "__0"}, 58 {"about", "blank", 0, "__0"},
59 {"non-standard", "foobar.com", 0, "non-standard__0"}, 59 {"non-standard", "foobar.com", 0, "non-standard__0"},
60 }; 60 };
61 61
62 for (size_t i = 0; i < arraysize(cases); ++i) { 62 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); ++i) {
63 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(cases[i].protocol , cases[i].host, cases[i].port); 63 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(cases[i].protocol , cases[i].host, cases[i].port);
64 String identifier = createDatabaseIdentifierFromSecurityOrigin(origin.ge t()); 64 String identifier = createDatabaseIdentifierFromSecurityOrigin(origin.ge t());
65 EXPECT_EQ(cases[i].expectedIdentifier, identifier) << "test case " << or igin->toString(); 65 EXPECT_EQ(cases[i].expectedIdentifier, identifier) << "test case " << or igin->toString();
66 } 66 }
67 } 67 }
68 68
69 // This tests the encoding of a hostname including every character in the range [\x1f, \x80]. 69 // This tests the encoding of a hostname including every character in the range [\x1f, \x80].
70 TEST(DatabaseIdentifierTest, CreateIdentifierAllHostChars) 70 TEST(DatabaseIdentifierTest, CreateIdentifierAllHostChars)
71 { 71 {
72 struct Case { 72 struct Case {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 {"x\x7ax", "http_xzx_0", true}, 174 {"x\x7ax", "http_xzx_0", true},
175 {"x\x7bx", "http_x%7bx_0", false}, 175 {"x\x7bx", "http_x%7bx_0", false},
176 {"x\x7cx", "http_x%7cx_0", false}, 176 {"x\x7cx", "http_x%7cx_0", false},
177 {"x\x7dx", "http_x%7dx_0", false}, 177 {"x\x7dx", "http_x%7dx_0", false},
178 {"x\x7ex", "__0", false}, 178 {"x\x7ex", "__0", false},
179 {"x\x7fx", "__0", false}, 179 {"x\x7fx", "__0", false},
180 180
181 {"x\x80x", "__0", false}, 181 {"x\x80x", "__0", false},
182 }; 182 };
183 183
184 for (size_t i = 0; i < arraysize(cases); ++i) { 184 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); ++i) {
185 RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", cases[i]. hostname, 80); 185 RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", cases[i]. hostname, 80);
186 String identifier = createDatabaseIdentifierFromSecurityOrigin(origin.ge t()); 186 String identifier = createDatabaseIdentifierFromSecurityOrigin(origin.ge t());
187 EXPECT_EQ(cases[i].expected, identifier) << "test case " << i << ": \"" << cases[i].hostname << "\""; 187 EXPECT_EQ(cases[i].expected, identifier) << "test case " << i << ": \"" << cases[i].hostname << "\"";
188 if (cases[i].shouldRoundTrip) { 188 if (cases[i].shouldRoundTrip) {
189 RefPtr<SecurityOrigin> parsedOrigin = createSecurityOriginFromDataba seIdentifier(identifier); 189 RefPtr<SecurityOrigin> parsedOrigin = createSecurityOriginFromDataba seIdentifier(identifier);
190 EXPECT_EQ(cases[i].hostname.lower(), parsedOrigin->host()) << "test case " << i << ": \"" << cases[i].hostname << "\""; 190 EXPECT_EQ(cases[i].hostname.lower(), parsedOrigin->host()) << "test case " << i << ": \"" << cases[i].hostname << "\"";
191 } 191 }
192 } 192 }
193 193
194 } 194 }
(...skipping 16 matching lines...) Expand all
211 {"unknown_google.com_0", "", "", 0, "null", true}, 211 {"unknown_google.com_0", "", "", 0, "null", true},
212 {"http_nondefaultport.net_8001", "http", "nondefaultport.net", 8001, "ht tp://nondefaultport.net:8001", false}, 212 {"http_nondefaultport.net_8001", "http", "nondefaultport.net", 8001, "ht tp://nondefaultport.net:8001", false},
213 {"file__0", "", "", 0, "null", true}, 213 {"file__0", "", "", 0, "null", true},
214 {"__0", "", "", 0, "null", true}, 214 {"__0", "", "", 0, "null", true},
215 {"http_foo_bar_baz.org_0", "http", "foo_bar_baz.org", 0, "http://foo_bar _baz.org", false}, 215 {"http_foo_bar_baz.org_0", "http", "foo_bar_baz.org", 0, "http://foo_bar _baz.org", false},
216 {"http_xn--n3h.unicode.com_0", "http", "xn--n3h.unicode.com", 0, "http:/ /xn--n3h.unicode.com", false}, 216 {"http_xn--n3h.unicode.com_0", "http", "xn--n3h.unicode.com", 0, "http:/ /xn--n3h.unicode.com", false},
217 {"http_dot.com_0", "http", "dot.com", 0, "http://dot.com", false}, 217 {"http_dot.com_0", "http", "dot.com", 0, "http://dot.com", false},
218 {"http_escaped%3Dfun.com_0", "http", "escaped%3dfun.com", 0, "http://esc aped%3dfun.com", false}, 218 {"http_escaped%3Dfun.com_0", "http", "escaped%3dfun.com", 0, "http://esc aped%3dfun.com", false},
219 }; 219 };
220 220
221 for (size_t i = 0; i < arraysize(validCases); ++i) { 221 for (size_t i = 0; i < WTF_ARRAY_LENGTH(validCases); ++i) {
222 RefPtr<SecurityOrigin> origin = createSecurityOriginFromDatabaseIdentifi er(validCases[i].identifier); 222 RefPtr<SecurityOrigin> origin = createSecurityOriginFromDatabaseIdentifi er(validCases[i].identifier);
223 EXPECT_EQ(validCases[i].expectedProtocol, origin->protocol()) << "test c ase " << i; 223 EXPECT_EQ(validCases[i].expectedProtocol, origin->protocol()) << "test c ase " << i;
224 EXPECT_EQ(validCases[i].expectedHost, origin->host()) << "test case " << i; 224 EXPECT_EQ(validCases[i].expectedHost, origin->host()) << "test case " << i;
225 EXPECT_EQ(validCases[i].expectedPort, origin->port()) << "test case " << i; 225 EXPECT_EQ(validCases[i].expectedPort, origin->port()) << "test case " << i;
226 EXPECT_EQ(validCases[i].expectedStringRepresentation, origin->toString() ) << "test case " << i; 226 EXPECT_EQ(validCases[i].expectedStringRepresentation, origin->toString() ) << "test case " << i;
227 EXPECT_EQ(validCases[i].expectedUnique, origin->isUnique()) << "test cas e " << i; 227 EXPECT_EQ(validCases[i].expectedUnique, origin->isUnique()) << "test cas e " << i;
228 } 228 }
229 229
230 String bogusIdentifiers[] = { 230 String bogusIdentifiers[] = {
231 "", "_", "__", 231 "", "_", "__",
232 String("\x00", 1), 232 String("\x00", 1),
233 String("http_\x00_0", 8), 233 String("http_\x00_0", 8),
234 "ht\x7ctp_badprotocol.com_0", 234 "ht\x7ctp_badprotocol.com_0",
235 "http_unescaped_percent_%.com_0", 235 "http_unescaped_percent_%.com_0",
236 "http_port_too_big.net_75000", 236 "http_port_too_big.net_75000",
237 "http_port_too_small.net_-25", 237 "http_port_too_small.net_-25",
238 "http_shouldbeescaped\x7c.com_0", 238 "http_shouldbeescaped\x7c.com_0",
239 "http_latin1\x8a.org_8001", 239 "http_latin1\x8a.org_8001",
240 String::fromUTF8("http_\xe2\x98\x83.unicode.com_0"), 240 String::fromUTF8("http_\xe2\x98\x83.unicode.com_0"),
241 "http_dot%252ecom_0", 241 "http_dot%252ecom_0",
242 "HtTp_NonCanonicalRepresenTation_0", 242 "HtTp_NonCanonicalRepresenTation_0",
243 "http_non_ascii.\xa1.com_0", 243 "http_non_ascii.\xa1.com_0",
244 "http_not_canonical_escape%3d_0", 244 "http_not_canonical_escape%3d_0",
245 }; 245 };
246 246
247 for (size_t i = 0; i < arraysize(bogusIdentifiers); ++i) { 247 for (size_t i = 0; i < WTF_ARRAY_LENGTH(bogusIdentifiers); ++i) {
248 RefPtr<SecurityOrigin> origin = createSecurityOriginFromDatabaseIdentifi er(bogusIdentifiers[i]); 248 RefPtr<SecurityOrigin> origin = createSecurityOriginFromDatabaseIdentifi er(bogusIdentifiers[i]);
249 EXPECT_EQ("null", origin->toString()) << "test case " << i; 249 EXPECT_EQ("null", origin->toString()) << "test case " << i;
250 EXPECT_EQ(true, origin->isUnique()) << "test case " << i; 250 EXPECT_EQ(true, origin->isUnique()) << "test case " << i;
251 } 251 }
252 } 252 }
253 253
254 } // namespace blink 254 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698