| 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 "url/url_parse.h" | 5 #include "url/url_parse.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/macros.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/url_parse.h" | 9 #include "url/url_parse.h" |
| 10 | 10 |
| 11 // Some implementations of base/basictypes.h may define ARRAYSIZE. | |
| 12 // If it's not defined, we define it to the ARRAYSIZE_UNSAFE macro | |
| 13 // which is in our version of basictypes.h. | |
| 14 #ifndef ARRAYSIZE | |
| 15 #define ARRAYSIZE ARRAYSIZE_UNSAFE | |
| 16 #endif | |
| 17 | |
| 18 // Interesting IE file:isms... | 11 // Interesting IE file:isms... |
| 19 // | 12 // |
| 20 // file:/foo/bar file:///foo/bar | 13 // file:/foo/bar file:///foo/bar |
| 21 // The result here seems totally invalid!?!? This isn't UNC. | 14 // The result here seems totally invalid!?!? This isn't UNC. |
| 22 // | 15 // |
| 23 // file:/ | 16 // file:/ |
| 24 // file:// or any other number of slashes | 17 // file:// or any other number of slashes |
| 25 // IE6 doesn't do anything at all if you click on this link. No error: | 18 // IE6 doesn't do anything at all if you click on this link. No error: |
| 26 // nothing. IE6's history system seems to always color this link, so I'm | 19 // nothing. IE6's history system seems to always color this link, so I'm |
| 27 // guessing that it maps internally to the empty URL. | 20 // guessing that it maps internally to the empty URL. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 {"http:", Parsed::USERNAME, true, 5}, | 187 {"http:", Parsed::USERNAME, true, 5}, |
| 195 {"", Parsed::SCHEME, true, 0}, | 188 {"", Parsed::SCHEME, true, 0}, |
| 196 // Make sure a random component still works when there's nothing there. | 189 // Make sure a random component still works when there's nothing there. |
| 197 {"", Parsed::REF, true, 0}, | 190 {"", Parsed::REF, true, 0}, |
| 198 // File URLs are special with no host, so we test those. | 191 // File URLs are special with no host, so we test those. |
| 199 {"file:///c:/foo", Parsed::USERNAME, true, 7}, | 192 {"file:///c:/foo", Parsed::USERNAME, true, 7}, |
| 200 {"file:///c:/foo", Parsed::PASSWORD, true, 7}, | 193 {"file:///c:/foo", Parsed::PASSWORD, true, 7}, |
| 201 {"file:///c:/foo", Parsed::HOST, true, 7}, | 194 {"file:///c:/foo", Parsed::HOST, true, 7}, |
| 202 {"file:///c:/foo", Parsed::PATH, true, 7}, | 195 {"file:///c:/foo", Parsed::PATH, true, 7}, |
| 203 }; | 196 }; |
| 204 for (size_t i = 0; i < ARRAYSIZE(count_cases); i++) { | 197 for (size_t i = 0; i < arraysize(count_cases); i++) { |
| 205 int length = static_cast<int>(strlen(count_cases[i].url)); | 198 int length = static_cast<int>(strlen(count_cases[i].url)); |
| 206 | 199 |
| 207 // Simple test to distinguish file and standard URLs. | 200 // Simple test to distinguish file and standard URLs. |
| 208 Parsed parsed; | 201 Parsed parsed; |
| 209 if (length > 0 && count_cases[i].url[0] == 'f') | 202 if (length > 0 && count_cases[i].url[0] == 'f') |
| 210 ParseFileURL(count_cases[i].url, length, &parsed); | 203 ParseFileURL(count_cases[i].url, length, &parsed); |
| 211 else | 204 else |
| 212 ParseStandardURL(count_cases[i].url, length, &parsed); | 205 ParseStandardURL(count_cases[i].url, length, &parsed); |
| 213 | 206 |
| 214 int chars_before = parsed.CountCharactersBefore( | 207 int chars_before = parsed.CountCharactersBefore( |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 {"http://www.google.com/search", "search"}, | 495 {"http://www.google.com/search", "search"}, |
| 503 {"http://www.google.com/search/", ""}, | 496 {"http://www.google.com/search/", ""}, |
| 504 {"http://www.google.com/foo/bar.html?baz=22", "bar.html"}, | 497 {"http://www.google.com/foo/bar.html?baz=22", "bar.html"}, |
| 505 {"http://www.google.com/foo/bar.html#ref", "bar.html"}, | 498 {"http://www.google.com/foo/bar.html#ref", "bar.html"}, |
| 506 {"http://www.google.com/search/;param", ""}, | 499 {"http://www.google.com/search/;param", ""}, |
| 507 {"http://www.google.com/foo/bar.html;param#ref", "bar.html"}, | 500 {"http://www.google.com/foo/bar.html;param#ref", "bar.html"}, |
| 508 {"http://www.google.com/foo/bar.html;foo;param#ref", "bar.html;foo"}, | 501 {"http://www.google.com/foo/bar.html;foo;param#ref", "bar.html;foo"}, |
| 509 {"http://www.google.com/foo/bar.html?query#ref", "bar.html"}, | 502 {"http://www.google.com/foo/bar.html?query#ref", "bar.html"}, |
| 510 }; | 503 }; |
| 511 | 504 |
| 512 for (size_t i = 0; i < ARRAYSIZE(file_cases); i++) { | 505 for (size_t i = 0; i < arraysize(file_cases); i++) { |
| 513 const char* url = file_cases[i].input; | 506 const char* url = file_cases[i].input; |
| 514 int len = static_cast<int>(strlen(url)); | 507 int len = static_cast<int>(strlen(url)); |
| 515 | 508 |
| 516 Parsed parsed; | 509 Parsed parsed; |
| 517 ParseStandardURL(url, len, &parsed); | 510 ParseStandardURL(url, len, &parsed); |
| 518 | 511 |
| 519 Component file_name; | 512 Component file_name; |
| 520 ExtractFileName(url, parsed.path, &file_name); | 513 ExtractFileName(url, parsed.path, &file_name); |
| 521 | 514 |
| 522 EXPECT_TRUE(ComponentMatches(url, file_cases[i].expected, file_name)); | 515 EXPECT_TRUE(ComponentMatches(url, file_cases[i].expected, file_name)); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 // The remaining components are never used for filesystem urls. | 674 // The remaining components are never used for filesystem urls. |
| 682 ExpectInvalidComponent(parsed.username); | 675 ExpectInvalidComponent(parsed.username); |
| 683 ExpectInvalidComponent(parsed.password); | 676 ExpectInvalidComponent(parsed.password); |
| 684 ExpectInvalidComponent(parsed.host); | 677 ExpectInvalidComponent(parsed.host); |
| 685 ExpectInvalidComponent(parsed.port); | 678 ExpectInvalidComponent(parsed.port); |
| 686 } | 679 } |
| 687 } | 680 } |
| 688 | 681 |
| 689 } // namespace | 682 } // namespace |
| 690 } // namespace url | 683 } // namespace url |
| OLD | NEW |