| 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 |
| 64 TEST(URLUtilTest, ReplaceComponents) { | 96 TEST(URLUtilTest, ReplaceComponents) { |
| 65 Parsed parsed; | 97 Parsed parsed; |
| 66 RawCanonOutputT<char> output; | 98 RawCanonOutputT<char> output; |
| 67 Parsed new_parsed; | 99 Parsed new_parsed; |
| 68 | 100 |
| 69 // Check that the following calls do not cause crash | 101 // Check that the following calls do not cause crash |
| 70 Replacements<char> replacements; | 102 Replacements<char> replacements; |
| 71 replacements.SetRef("test", Component(0, 4)); | 103 replacements.SetRef("test", Component(0, 4)); |
| 72 ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, &new_parsed); | 104 ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, &new_parsed); |
| 73 ReplaceComponents("", 0, parsed, replacements, NULL, &output, &new_parsed); | 105 ReplaceComponents("", 0, parsed, replacements, NULL, &output, &new_parsed); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 for (size_t i = 0; i < arraysize(encode_cases); i++) { | 245 for (size_t i = 0; i < arraysize(encode_cases); i++) { |
| 214 const char* input = encode_cases[i].input; | 246 const char* input = encode_cases[i].input; |
| 215 RawCanonOutputT<char> buffer; | 247 RawCanonOutputT<char> buffer; |
| 216 EncodeURIComponent(input, strlen(input), &buffer); | 248 EncodeURIComponent(input, strlen(input), &buffer); |
| 217 std::string output(buffer.data(), buffer.length()); | 249 std::string output(buffer.data(), buffer.length()); |
| 218 EXPECT_EQ(encode_cases[i].output, output); | 250 EXPECT_EQ(encode_cases[i].output, output); |
| 219 } | 251 } |
| 220 } | 252 } |
| 221 | 253 |
| 222 TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { | 254 TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { |
| 223 // This tests non-standard (in the sense that GIsStandard() == false) | 255 // This tests non-standard (in the sense that IsStandard() == false) |
| 224 // hierarchical schemes. | 256 // hierarchical schemes. |
| 225 struct ResolveRelativeCase { | 257 struct ResolveRelativeCase { |
| 226 const char* base; | 258 const char* base; |
| 227 const char* rel; | 259 const char* rel; |
| 228 bool is_valid; | 260 bool is_valid; |
| 229 const char* out; | 261 const char* out; |
| 230 } resolve_non_standard_cases[] = { | 262 } resolve_non_standard_cases[] = { |
| 231 // Resolving a relative path against a non-hierarchical URL should fail. | 263 // Resolving a relative path against a non-hierarchical URL should fail. |
| 232 {"scheme:opaque_data", "/path", false, ""}, | 264 {"scheme:opaque_data", "/path", false, ""}, |
| 233 // Resolving a relative path against a non-standard authority-based base | 265 // Resolving a relative path against a non-standard authority-based base |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 351 |
| 320 bool valid = ResolveRelative(base, strlen(base), | 352 bool valid = ResolveRelative(base, strlen(base), |
| 321 base_parsed, rel, | 353 base_parsed, rel, |
| 322 strlen(rel), NULL, &output, | 354 strlen(rel), NULL, &output, |
| 323 &resolved_parsed); | 355 &resolved_parsed); |
| 324 EXPECT_TRUE(valid); | 356 EXPECT_TRUE(valid); |
| 325 EXPECT_FALSE(resolved_parsed.ref.is_valid()); | 357 EXPECT_FALSE(resolved_parsed.ref.is_valid()); |
| 326 } | 358 } |
| 327 | 359 |
| 328 } // namespace url | 360 } // namespace url |
| OLD | NEW |