| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "url/third_party/mozilla/url_parse.h" | 7 #include "url/third_party/mozilla/url_parse.h" |
| 8 #include "url/url_canon.h" | 8 #include "url/url_canon.h" |
| 9 #include "url/url_canon_stdstring.h" | 9 #include "url/url_canon_stdstring.h" |
| 10 #include "url/url_test_utils.h" | 10 #include "url/url_test_utils.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 // Control characters should be stripped out on the ends, and kept in the | 55 // Control characters should be stripped out on the ends, and kept in the |
| 56 // middle. | 56 // middle. |
| 57 const char ctrl_str[] = "\02jav\02scr\03ipt:alert(1)"; | 57 const char ctrl_str[] = "\02jav\02scr\03ipt:alert(1)"; |
| 58 EXPECT_FALSE(FindAndCompareScheme(ctrl_str, | 58 EXPECT_FALSE(FindAndCompareScheme(ctrl_str, |
| 59 static_cast<int>(strlen(ctrl_str)), | 59 static_cast<int>(strlen(ctrl_str)), |
| 60 "javascript", &found_scheme)); | 60 "javascript", &found_scheme)); |
| 61 EXPECT_TRUE(found_scheme == Component(1, 11)); | 61 EXPECT_TRUE(found_scheme == Component(1, 11)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 TEST(URLUtilTest, IsStandard) { | |
| 65 const char kHTTPScheme[] = "http"; | |
| 66 EXPECT_TRUE(IsStandard(kHTTPScheme, Component(0, strlen(kHTTPScheme)))); | |
| 67 | |
| 68 const char kFooScheme[] = "foo"; | |
| 69 EXPECT_FALSE(IsStandard(kFooScheme, Component(0, strlen(kFooScheme)))); | |
| 70 } | |
| 71 | |
| 72 TEST(URLUtilTest, GetStandardSchemeType) { | |
| 73 url::SchemeType scheme_type; | |
| 74 | |
| 75 const char kHTTPScheme[] = "http"; | |
| 76 scheme_type = url::SCHEME_WITHOUT_AUTHORITY; | |
| 77 EXPECT_TRUE(GetStandardSchemeType(kHTTPScheme, | |
| 78 Component(0, strlen(kHTTPScheme)), | |
| 79 &scheme_type)); | |
| 80 EXPECT_EQ(url::SCHEME_WITH_PORT, scheme_type); | |
| 81 | |
| 82 const char kFilesystemScheme[] = "filesystem"; | |
| 83 scheme_type = url::SCHEME_WITH_PORT; | |
| 84 EXPECT_TRUE(GetStandardSchemeType(kFilesystemScheme, | |
| 85 Component(0, strlen(kFilesystemScheme)), | |
| 86 &scheme_type)); | |
| 87 EXPECT_EQ(url::SCHEME_WITHOUT_AUTHORITY, scheme_type); | |
| 88 | |
| 89 const char kFooScheme[] = "foo"; | |
| 90 scheme_type = url::SCHEME_WITH_PORT; | |
| 91 EXPECT_FALSE(GetStandardSchemeType(kFooScheme, | |
| 92 Component(0, strlen(kFooScheme)), | |
| 93 &scheme_type)); | |
| 94 } | |
| 95 | |
| 96 TEST(URLUtilTest, ReplaceComponents) { | 64 TEST(URLUtilTest, ReplaceComponents) { |
| 97 Parsed parsed; | 65 Parsed parsed; |
| 98 RawCanonOutputT<char> output; | 66 RawCanonOutputT<char> output; |
| 99 Parsed new_parsed; | 67 Parsed new_parsed; |
| 100 | 68 |
| 101 // Check that the following calls do not cause crash | 69 // Check that the following calls do not cause crash |
| 102 Replacements<char> replacements; | 70 Replacements<char> replacements; |
| 103 replacements.SetRef("test", Component(0, 4)); | 71 replacements.SetRef("test", Component(0, 4)); |
| 104 ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, &new_parsed); | 72 ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, &new_parsed); |
| 105 ReplaceComponents("", 0, parsed, replacements, NULL, &output, &new_parsed); | 73 ReplaceComponents("", 0, parsed, replacements, NULL, &output, &new_parsed); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 for (size_t i = 0; i < arraysize(encode_cases); i++) { | 213 for (size_t i = 0; i < arraysize(encode_cases); i++) { |
| 246 const char* input = encode_cases[i].input; | 214 const char* input = encode_cases[i].input; |
| 247 RawCanonOutputT<char> buffer; | 215 RawCanonOutputT<char> buffer; |
| 248 EncodeURIComponent(input, strlen(input), &buffer); | 216 EncodeURIComponent(input, strlen(input), &buffer); |
| 249 std::string output(buffer.data(), buffer.length()); | 217 std::string output(buffer.data(), buffer.length()); |
| 250 EXPECT_EQ(encode_cases[i].output, output); | 218 EXPECT_EQ(encode_cases[i].output, output); |
| 251 } | 219 } |
| 252 } | 220 } |
| 253 | 221 |
| 254 TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { | 222 TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { |
| 255 // This tests non-standard (in the sense that IsStandard() == false) | 223 // This tests non-standard (in the sense that GIsStandard() == false) |
| 256 // hierarchical schemes. | 224 // hierarchical schemes. |
| 257 struct ResolveRelativeCase { | 225 struct ResolveRelativeCase { |
| 258 const char* base; | 226 const char* base; |
| 259 const char* rel; | 227 const char* rel; |
| 260 bool is_valid; | 228 bool is_valid; |
| 261 const char* out; | 229 const char* out; |
| 262 } resolve_non_standard_cases[] = { | 230 } resolve_non_standard_cases[] = { |
| 263 // Resolving a relative path against a non-hierarchical URL should fail. | 231 // Resolving a relative path against a non-hierarchical URL should fail. |
| 264 {"scheme:opaque_data", "/path", false, ""}, | 232 {"scheme:opaque_data", "/path", false, ""}, |
| 265 // Resolving a relative path against a non-standard authority-based base | 233 // Resolving a relative path against a non-standard authority-based base |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 319 |
| 352 bool valid = ResolveRelative(base, strlen(base), | 320 bool valid = ResolveRelative(base, strlen(base), |
| 353 base_parsed, rel, | 321 base_parsed, rel, |
| 354 strlen(rel), NULL, &output, | 322 strlen(rel), NULL, &output, |
| 355 &resolved_parsed); | 323 &resolved_parsed); |
| 356 EXPECT_TRUE(valid); | 324 EXPECT_TRUE(valid); |
| 357 EXPECT_FALSE(resolved_parsed.ref.is_valid()); | 325 EXPECT_FALSE(resolved_parsed.ref.is_valid()); |
| 358 } | 326 } |
| 359 | 327 |
| 360 } // namespace url | 328 } // namespace url |
| OLD | NEW |