| 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 "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "url/url_canon.h" | 7 #include "url/url_canon.h" |
| 7 #include "url/url_canon_stdstring.h" | 8 #include "url/url_canon_stdstring.h" |
| 8 #include "url/url_parse.h" | 9 #include "url/url_parse.h" |
| 9 #include "url/url_test_utils.h" | 10 #include "url/url_test_utils.h" |
| 10 #include "url/url_util.h" | 11 #include "url/url_util.h" |
| 11 | 12 |
| 12 namespace url { | 13 namespace url { |
| 13 | 14 |
| 14 TEST(URLUtilTest, FindAndCompareScheme) { | 15 TEST(URLUtilTest, FindAndCompareScheme) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 {"%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", | 153 {"%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", |
| 153 "PQRSTUVWXYZ[\\]^_/"}, | 154 "PQRSTUVWXYZ[\\]^_/"}, |
| 154 {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", | 155 {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", |
| 155 "`abcdefghijklmno/"}, | 156 "`abcdefghijklmno/"}, |
| 156 {"%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", | 157 {"%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", |
| 157 "pqrstuvwxyz{|}~\x7f/"}, | 158 "pqrstuvwxyz{|}~\x7f/"}, |
| 158 // Test un-UTF-8-ization. | 159 // Test un-UTF-8-ization. |
| 159 {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, | 160 {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(decode_cases); i++) { | 163 for (size_t i = 0; i < arraysize(decode_cases); i++) { |
| 163 const char* input = decode_cases[i].input; | 164 const char* input = decode_cases[i].input; |
| 164 RawCanonOutputT<base::char16> output; | 165 RawCanonOutputT<base::char16> output; |
| 165 DecodeURLEscapeSequences(input, strlen(input), &output); | 166 DecodeURLEscapeSequences(input, strlen(input), &output); |
| 166 EXPECT_EQ(decode_cases[i].output, | 167 EXPECT_EQ(decode_cases[i].output, |
| 167 test_utils::ConvertUTF16ToUTF8(base::string16(output.data(), | 168 test_utils::ConvertUTF16ToUTF8(base::string16(output.data(), |
| 168 output.length()))); | 169 output.length()))); |
| 169 } | 170 } |
| 170 | 171 |
| 171 // Our decode should decode %00 | 172 // Our decode should decode %00 |
| 172 const char zero_input[] = "%00"; | 173 const char zero_input[] = "%00"; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 202 {"@ABCDEFGHIJKLMNO", | 203 {"@ABCDEFGHIJKLMNO", |
| 203 "%40ABCDEFGHIJKLMNO"}, | 204 "%40ABCDEFGHIJKLMNO"}, |
| 204 {"PQRSTUVWXYZ[\\]^_", | 205 {"PQRSTUVWXYZ[\\]^_", |
| 205 "PQRSTUVWXYZ%5B%5C%5D%5E_"}, | 206 "PQRSTUVWXYZ%5B%5C%5D%5E_"}, |
| 206 {"`abcdefghijklmno", | 207 {"`abcdefghijklmno", |
| 207 "%60abcdefghijklmno"}, | 208 "%60abcdefghijklmno"}, |
| 208 {"pqrstuvwxyz{|}~\x7f", | 209 {"pqrstuvwxyz{|}~\x7f", |
| 209 "pqrstuvwxyz%7B%7C%7D~%7F"}, | 210 "pqrstuvwxyz%7B%7C%7D~%7F"}, |
| 210 }; | 211 }; |
| 211 | 212 |
| 212 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(encode_cases); i++) { | 213 for (size_t i = 0; i < arraysize(encode_cases); i++) { |
| 213 const char* input = encode_cases[i].input; | 214 const char* input = encode_cases[i].input; |
| 214 RawCanonOutputT<char> buffer; | 215 RawCanonOutputT<char> buffer; |
| 215 EncodeURIComponent(input, strlen(input), &buffer); | 216 EncodeURIComponent(input, strlen(input), &buffer); |
| 216 std::string output(buffer.data(), buffer.length()); | 217 std::string output(buffer.data(), buffer.length()); |
| 217 EXPECT_EQ(encode_cases[i].output, output); | 218 EXPECT_EQ(encode_cases[i].output, output); |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 | 221 |
| 221 TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { | 222 TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { |
| 222 // This tests non-standard (in the sense that GIsStandard() == false) | 223 // This tests non-standard (in the sense that GIsStandard() == false) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Test resolving a fragment (only) against any kind of base-URL. | 268 // Test resolving a fragment (only) against any kind of base-URL. |
| 268 {"about:blank", "#id42", true, "about:blank#id42" }, | 269 {"about:blank", "#id42", true, "about:blank#id42" }, |
| 269 {"about:blank", " #id42", true, "about:blank#id42" }, | 270 {"about:blank", " #id42", true, "about:blank#id42" }, |
| 270 {"about:blank#oldfrag", "#newfrag", true, "about:blank#newfrag" }, | 271 {"about:blank#oldfrag", "#newfrag", true, "about:blank#newfrag" }, |
| 271 // A surprising side effect of allowing fragments to resolve against | 272 // A surprising side effect of allowing fragments to resolve against |
| 272 // any URL scheme is we might break javascript: URLs by doing so... | 273 // any URL scheme is we might break javascript: URLs by doing so... |
| 273 {"javascript:alert('foo#bar')", "#badfrag", true, | 274 {"javascript:alert('foo#bar')", "#badfrag", true, |
| 274 "javascript:alert('foo#badfrag" }, | 275 "javascript:alert('foo#badfrag" }, |
| 275 }; | 276 }; |
| 276 | 277 |
| 277 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) { | 278 for (size_t i = 0; i < arraysize(resolve_non_standard_cases); i++) { |
| 278 const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; | 279 const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; |
| 279 Parsed base_parsed; | 280 Parsed base_parsed; |
| 280 ParsePathURL(test_data.base, strlen(test_data.base), false, &base_parsed); | 281 ParsePathURL(test_data.base, strlen(test_data.base), false, &base_parsed); |
| 281 | 282 |
| 282 std::string resolved; | 283 std::string resolved; |
| 283 StdStringCanonOutput output(&resolved); | 284 StdStringCanonOutput output(&resolved); |
| 284 Parsed resolved_parsed; | 285 Parsed resolved_parsed; |
| 285 bool valid = ResolveRelative(test_data.base, strlen(test_data.base), | 286 bool valid = ResolveRelative(test_data.base, strlen(test_data.base), |
| 286 base_parsed, test_data.rel, | 287 base_parsed, test_data.rel, |
| 287 strlen(test_data.rel), NULL, &output, | 288 strlen(test_data.rel), NULL, &output, |
| 288 &resolved_parsed); | 289 &resolved_parsed); |
| 289 output.Complete(); | 290 output.Complete(); |
| 290 | 291 |
| 291 EXPECT_EQ(test_data.is_valid, valid) << i; | 292 EXPECT_EQ(test_data.is_valid, valid) << i; |
| 292 if (test_data.is_valid && valid) | 293 if (test_data.is_valid && valid) |
| 293 EXPECT_EQ(test_data.out, resolved) << i; | 294 EXPECT_EQ(test_data.out, resolved) << i; |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 | 297 |
| 297 } // namespace url | 298 } // namespace url |
| OLD | NEW |