| 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/url_canon.h" | 8 #include "url/url_canon.h" |
| 8 #include "url/url_canon_stdstring.h" | 9 #include "url/url_canon_stdstring.h" |
| 9 #include "url/url_parse.h" | |
| 10 #include "url/url_test_utils.h" | 10 #include "url/url_test_utils.h" |
| 11 #include "url/url_util.h" | 11 #include "url/url_util.h" |
| 12 | 12 |
| 13 namespace url { | 13 namespace url { |
| 14 | 14 |
| 15 TEST(URLUtilTest, FindAndCompareScheme) { | 15 TEST(URLUtilTest, FindAndCompareScheme) { |
| 16 Component found_scheme; | 16 Component found_scheme; |
| 17 | 17 |
| 18 // Simple case where the scheme is found and matches. | 18 // Simple case where the scheme is found and matches. |
| 19 const char kStr1[] = "http://www.com/"; | 19 const char kStr1[] = "http://www.com/"; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 37 // When there is an empty scheme, it should match the empty scheme. | 37 // When there is an empty scheme, it should match the empty scheme. |
| 38 const char kStr3[] = ":foo.com/"; | 38 const char kStr3[] = ":foo.com/"; |
| 39 EXPECT_TRUE(FindAndCompareScheme( | 39 EXPECT_TRUE(FindAndCompareScheme( |
| 40 kStr3, static_cast<int>(strlen(kStr3)), "", &found_scheme)); | 40 kStr3, static_cast<int>(strlen(kStr3)), "", &found_scheme)); |
| 41 EXPECT_TRUE(found_scheme == Component(0, 0)); | 41 EXPECT_TRUE(found_scheme == Component(0, 0)); |
| 42 | 42 |
| 43 // But when there is no scheme, it should fail. | 43 // But when there is no scheme, it should fail. |
| 44 EXPECT_FALSE(FindAndCompareScheme("", 0, "", &found_scheme)); | 44 EXPECT_FALSE(FindAndCompareScheme("", 0, "", &found_scheme)); |
| 45 EXPECT_TRUE(found_scheme == Component()); | 45 EXPECT_TRUE(found_scheme == Component()); |
| 46 | 46 |
| 47 // When there is a whitespace char in scheme, it should canonicalize the url | 47 // When there is a whitespace char in scheme, it should canonicalize the URL |
| 48 // before comparison. | 48 // before comparison. |
| 49 const char whtspc_str[] = " \r\n\tjav\ra\nscri\tpt:alert(1)"; | 49 const char whtspc_str[] = " \r\n\tjav\ra\nscri\tpt:alert(1)"; |
| 50 EXPECT_TRUE(FindAndCompareScheme(whtspc_str, | 50 EXPECT_TRUE(FindAndCompareScheme(whtspc_str, |
| 51 static_cast<int>(strlen(whtspc_str)), | 51 static_cast<int>(strlen(whtspc_str)), |
| 52 "javascript", &found_scheme)); | 52 "javascript", &found_scheme)); |
| 53 EXPECT_TRUE(found_scheme == Component(1, 10)); | 53 EXPECT_TRUE(found_scheme == Component(1, 10)); |
| 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)"; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 &resolved_parsed); | 298 &resolved_parsed); |
| 299 output.Complete(); | 299 output.Complete(); |
| 300 | 300 |
| 301 EXPECT_EQ(test_data.is_valid, valid) << i; | 301 EXPECT_EQ(test_data.is_valid, valid) << i; |
| 302 if (test_data.is_valid && valid) | 302 if (test_data.is_valid && valid) |
| 303 EXPECT_EQ(test_data.out, resolved) << i; | 303 EXPECT_EQ(test_data.out, resolved) << i; |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 TEST(URLUtilTest, TestNoRefComponent) { | 307 TEST(URLUtilTest, TestNoRefComponent) { |
| 308 // The hash-mark must be ignored when mailto: scheme is | 308 // The hash-mark must be ignored when mailto: scheme is parsed, |
| 309 // parsed, even if the url has a base and relative part. | 309 // even if the URL has a base and relative part. |
| 310 const char* base = "mailto://to/"; | 310 const char* base = "mailto://to/"; |
| 311 const char* rel = "any#body"; | 311 const char* rel = "any#body"; |
| 312 | 312 |
| 313 Parsed base_parsed; | 313 Parsed base_parsed; |
| 314 ParsePathURL(base, strlen(base), false, &base_parsed); | 314 ParsePathURL(base, strlen(base), false, &base_parsed); |
| 315 | 315 |
| 316 std::string resolved; | 316 std::string resolved; |
| 317 StdStringCanonOutput output(&resolved); | 317 StdStringCanonOutput output(&resolved); |
| 318 Parsed resolved_parsed; | 318 Parsed resolved_parsed; |
| 319 | 319 |
| 320 bool valid = ResolveRelative(base, strlen(base), | 320 bool valid = ResolveRelative(base, strlen(base), |
| 321 base_parsed, rel, | 321 base_parsed, rel, |
| 322 strlen(rel), NULL, &output, | 322 strlen(rel), NULL, &output, |
| 323 &resolved_parsed); | 323 &resolved_parsed); |
| 324 EXPECT_TRUE(valid); | 324 EXPECT_TRUE(valid); |
| 325 EXPECT_FALSE(resolved_parsed.ref.is_valid()); | 325 EXPECT_FALSE(resolved_parsed.ref.is_valid()); |
| 326 } | 326 } |
| 327 | 327 |
| 328 } // namespace url | 328 } // namespace url |
| OLD | NEW |