| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "storage/common/database/database_identifier.h" | 5 #include "storage/common/database/database_identifier.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 {"http://invalidportnumber.org:-6", "__0"}, | 28 {"http://invalidportnumber.org:-6", "__0"}, |
| 29 {"http://%E2%98%83.unicode.com", "http_xn--n3h.unicode.com_0"}, | 29 {"http://%E2%98%83.unicode.com", "http_xn--n3h.unicode.com_0"}, |
| 30 {"http://\xe2\x98\x83.unicode.com", "http_xn--n3h.unicode.com_0"}, | 30 {"http://\xe2\x98\x83.unicode.com", "http_xn--n3h.unicode.com_0"}, |
| 31 {"http://\xf0\x9f\x92\xa9.unicode.com", "http_xn--ls8h.unicode.com_0"}, | 31 {"http://\xf0\x9f\x92\xa9.unicode.com", "http_xn--ls8h.unicode.com_0"}, |
| 32 {"file:///", "file__0"}, | 32 {"file:///", "file__0"}, |
| 33 {"data:", "__0"}, | 33 {"data:", "__0"}, |
| 34 {"about:blank", "__0"}, | 34 {"about:blank", "__0"}, |
| 35 {"non-standard://foobar.com", "__0"}, | 35 {"non-standard://foobar.com", "__0"}, |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 38 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 39 GURL origin(cases[i].origin); | 39 GURL origin(cases[i].origin); |
| 40 DatabaseIdentifier identifier = | 40 DatabaseIdentifier identifier = |
| 41 DatabaseIdentifier::CreateFromOrigin(origin); | 41 DatabaseIdentifier::CreateFromOrigin(origin); |
| 42 EXPECT_EQ(cases[i].expectedIdentifier, identifier.ToString()) | 42 EXPECT_EQ(cases[i].expectedIdentifier, identifier.ToString()) |
| 43 << "test case " << cases[i].origin; | 43 << "test case " << cases[i].origin; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 // This tests the encoding of a hostname including every character in the range | 47 // This tests the encoding of a hostname including every character in the range |
| 48 // [\x1f, \x80]. | 48 // [\x1f, \x80]. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 {"x\x79x", "http_xyx_0", true}, | 145 {"x\x79x", "http_xyx_0", true}, |
| 146 {"x\x7ax", "http_xzx_0", true}, | 146 {"x\x7ax", "http_xzx_0", true}, |
| 147 {"x\x7bx", "http_x%7bx_0", false}, | 147 {"x\x7bx", "http_x%7bx_0", false}, |
| 148 {"x\x7cx", "http_x%7cx_0", false}, | 148 {"x\x7cx", "http_x%7cx_0", false}, |
| 149 {"x\x7dx", "http_x%7dx_0", false}, | 149 {"x\x7dx", "http_x%7dx_0", false}, |
| 150 {"x\x7ex", "__0", false}, | 150 {"x\x7ex", "__0", false}, |
| 151 {"x\x7fx", "__0", false}, | 151 {"x\x7fx", "__0", false}, |
| 152 {"x\x80x", "__0", false}, | 152 {"x\x80x", "__0", false}, |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 155 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 156 GURL origin("http://" + cases[i].hostname); | 156 GURL origin("http://" + cases[i].hostname); |
| 157 DatabaseIdentifier identifier = | 157 DatabaseIdentifier identifier = |
| 158 DatabaseIdentifier::CreateFromOrigin(origin); | 158 DatabaseIdentifier::CreateFromOrigin(origin); |
| 159 EXPECT_EQ(cases[i].expected, identifier.ToString()) | 159 EXPECT_EQ(cases[i].expected, identifier.ToString()) |
| 160 << "test case " << i << " :\"" << cases[i].hostname << "\""; | 160 << "test case " << i << " :\"" << cases[i].hostname << "\""; |
| 161 if (cases[i].shouldRoundTrip) { | 161 if (cases[i].shouldRoundTrip) { |
| 162 DatabaseIdentifier parsed_identifier = | 162 DatabaseIdentifier parsed_identifier = |
| 163 DatabaseIdentifier::Parse(identifier.ToString()); | 163 DatabaseIdentifier::Parse(identifier.ToString()); |
| 164 EXPECT_EQ(identifier.ToString(), parsed_identifier.ToString()) | 164 EXPECT_EQ(identifier.ToString(), parsed_identifier.ToString()) |
| 165 << "test case " << i << " :\"" << cases[i].hostname << "\""; | 165 << "test case " << i << " :\"" << cases[i].hostname << "\""; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 196 {"http_foo_bar_baz.org_0", | 196 {"http_foo_bar_baz.org_0", |
| 197 "http", "foo_bar_baz.org", 0, GURL("http://foo_bar_baz.org"), false}, | 197 "http", "foo_bar_baz.org", 0, GURL("http://foo_bar_baz.org"), false}, |
| 198 {"http_xn--n3h.unicode.com_0", | 198 {"http_xn--n3h.unicode.com_0", |
| 199 "http", "xn--n3h.unicode.com", 0, | 199 "http", "xn--n3h.unicode.com", 0, |
| 200 GURL("http://xn--n3h.unicode.com"), false}, | 200 GURL("http://xn--n3h.unicode.com"), false}, |
| 201 {"http_dot.com_0", "http", "dot.com", 0, GURL("http://dot.com"), false}, | 201 {"http_dot.com_0", "http", "dot.com", 0, GURL("http://dot.com"), false}, |
| 202 {"http_escaped%3Dfun.com_0", "http", "escaped%3dfun.com", 0, | 202 {"http_escaped%3Dfun.com_0", "http", "escaped%3dfun.com", 0, |
| 203 GURL("http://escaped%3dfun.com"), false}, | 203 GURL("http://escaped%3dfun.com"), false}, |
| 204 }; | 204 }; |
| 205 | 205 |
| 206 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid_cases); ++i) { | 206 for (size_t i = 0; i < arraysize(valid_cases); ++i) { |
| 207 DatabaseIdentifier identifier = | 207 DatabaseIdentifier identifier = |
| 208 DatabaseIdentifier::Parse(valid_cases[i].str); | 208 DatabaseIdentifier::Parse(valid_cases[i].str); |
| 209 EXPECT_EQ(valid_cases[i].expected_scheme, identifier.scheme()) | 209 EXPECT_EQ(valid_cases[i].expected_scheme, identifier.scheme()) |
| 210 << "test case " << valid_cases[i].str; | 210 << "test case " << valid_cases[i].str; |
| 211 EXPECT_EQ(valid_cases[i].expected_host, identifier.hostname()) | 211 EXPECT_EQ(valid_cases[i].expected_host, identifier.hostname()) |
| 212 << "test case " << valid_cases[i].str; | 212 << "test case " << valid_cases[i].str; |
| 213 EXPECT_EQ(valid_cases[i].expected_port, identifier.port()) | 213 EXPECT_EQ(valid_cases[i].expected_port, identifier.port()) |
| 214 << "test case " << valid_cases[i].str; | 214 << "test case " << valid_cases[i].str; |
| 215 EXPECT_EQ(valid_cases[i].expected_origin, identifier.ToOrigin()) | 215 EXPECT_EQ(valid_cases[i].expected_origin, identifier.ToOrigin()) |
| 216 << "test case " << valid_cases[i].str; | 216 << "test case " << valid_cases[i].str; |
| 217 EXPECT_EQ(valid_cases[i].expected_unique, identifier.is_unique()) | 217 EXPECT_EQ(valid_cases[i].expected_unique, identifier.is_unique()) |
| 218 << "test case " << valid_cases[i].str; | 218 << "test case " << valid_cases[i].str; |
| 219 } | 219 } |
| 220 | 220 |
| 221 std::string bogus_components[] = { | 221 std::string bogus_components[] = { |
| 222 "", "_", "__", std::string("\x00", 1), std::string("http_\x00_0", 8), | 222 "", "_", "__", std::string("\x00", 1), std::string("http_\x00_0", 8), |
| 223 "ht\x7ctp_badscheme.com_0", "http_unescaped_percent_%.com_0", | 223 "ht\x7ctp_badscheme.com_0", "http_unescaped_percent_%.com_0", |
| 224 "http_port_too_big.net_75000", "http_port_too_small.net_-25", | 224 "http_port_too_big.net_75000", "http_port_too_small.net_-25", |
| 225 "http_shouldbeescaped\x7c.com_0", "http_latin1\x8a.org_8001", | 225 "http_shouldbeescaped\x7c.com_0", "http_latin1\x8a.org_8001", |
| 226 "http_\xe2\x98\x83.unicode.com_0", | 226 "http_\xe2\x98\x83.unicode.com_0", |
| 227 "http_dot%252ecom_0", | 227 "http_dot%252ecom_0", |
| 228 "HtTp_NonCanonicalRepresenTation_0", | 228 "HtTp_NonCanonicalRepresenTation_0", |
| 229 "http_non_ascii.\xa1.com_0", | 229 "http_non_ascii.\xa1.com_0", |
| 230 "http_not_canonical_escape%3d_0", | 230 "http_not_canonical_escape%3d_0", |
| 231 "http_bytes_after_port_0abcd", | 231 "http_bytes_after_port_0abcd", |
| 232 }; | 232 }; |
| 233 | 233 |
| 234 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(bogus_components); ++i) { | 234 for (size_t i = 0; i < arraysize(bogus_components); ++i) { |
| 235 DatabaseIdentifier identifier = | 235 DatabaseIdentifier identifier = |
| 236 DatabaseIdentifier::Parse(bogus_components[i]); | 236 DatabaseIdentifier::Parse(bogus_components[i]); |
| 237 EXPECT_EQ("__0", identifier.ToString()) | 237 EXPECT_EQ("__0", identifier.ToString()) |
| 238 << "test case " << bogus_components[i]; | 238 << "test case " << bogus_components[i]; |
| 239 EXPECT_EQ(GURL("null"), identifier.ToOrigin()) | 239 EXPECT_EQ(GURL("null"), identifier.ToOrigin()) |
| 240 << "test case " << bogus_components[i]; | 240 << "test case " << bogus_components[i]; |
| 241 EXPECT_EQ(true, identifier.is_unique()) | 241 EXPECT_EQ(true, identifier.is_unique()) |
| 242 << "test case " << bogus_components[i]; | 242 << "test case " << bogus_components[i]; |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace | 246 } // namespace |
| 247 } // namespace content | 247 } // namespace content |
| OLD | NEW |