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/basictypes.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 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 336 } |
337 | 337 |
338 // PathURL -------------------------------------------------------------------- | 338 // PathURL -------------------------------------------------------------------- |
339 | 339 |
340 // Various incarnations of path URLs. | 340 // Various incarnations of path URLs. |
341 static PathURLParseCase path_cases[] = { | 341 static PathURLParseCase path_cases[] = { |
342 {"", NULL, NULL}, | 342 {"", NULL, NULL}, |
343 {":", "", NULL}, | 343 {":", "", NULL}, |
344 {":/", "", "/"}, | 344 {":/", "", "/"}, |
345 {"/", NULL, "/"}, | 345 {"/", NULL, "/"}, |
346 {" This is \\interesting// \t", NULL, "This is \\interestin
g//"}, | 346 {" This is \\interesting// \t", NULL, "This is \\interestin
g// \t"}, |
347 {"about:", "about", NULL}, | 347 {"about:", "about", NULL}, |
348 {"about:blank", "about", "blank"}, | 348 {"about:blank", "about", "blank"}, |
349 {" about: blank ", "about", " blank"}, | 349 {" about: blank ", "about", " blank "}, |
350 {"javascript :alert(\"He:/l\\l#o?foo\"); ", "javascript ", "alert(\"He:/l\\l#o?f
oo\");"}, | 350 {"javascript :alert(\"He:/l\\l#o?foo\"); ", "javascript ", "alert(\"He:/l\\l#o?f
oo\"); "}, |
351 }; | 351 }; |
352 | 352 |
353 TEST(URLParser, PathURL) { | 353 TEST(URLParser, PathURL) { |
354 // Declared outside for loop to try to catch cases in init() where we forget | 354 // Declared outside for loop to try to catch cases in init() where we forget |
355 // to reset something that is reset by the construtor. | 355 // to reset something that is reset by the construtor. |
356 url_parse::Parsed parsed; | 356 url_parse::Parsed parsed; |
357 for (size_t i = 0; i < arraysize(path_cases); i++) { | 357 for (size_t i = 0; i < arraysize(path_cases); i++) { |
358 const char* url = path_cases[i].input; | 358 const char* url = path_cases[i].input; |
359 url_parse::ParsePathURL(url, static_cast<int>(strlen(url)), &parsed); | 359 url_parse::ParsePathURL(url, static_cast<int>(strlen(url)), false, &parsed); |
360 | 360 |
361 EXPECT_TRUE(ComponentMatches(url, path_cases[i].scheme, parsed.scheme)); | 361 EXPECT_TRUE(ComponentMatches(url, path_cases[i].scheme, parsed.scheme)) |
362 EXPECT_TRUE(ComponentMatches(url, path_cases[i].path, parsed.path)); | 362 << i; |
| 363 EXPECT_TRUE(ComponentMatches(url, path_cases[i].path, parsed.GetContent())) |
| 364 << i; |
363 | 365 |
364 // The remaining components are never used for path urls. | 366 // The remaining components are never used for path urls. |
365 ExpectInvalidComponent(parsed.username); | 367 ExpectInvalidComponent(parsed.username); |
366 ExpectInvalidComponent(parsed.password); | 368 ExpectInvalidComponent(parsed.password); |
367 ExpectInvalidComponent(parsed.host); | 369 ExpectInvalidComponent(parsed.host); |
368 ExpectInvalidComponent(parsed.port); | 370 ExpectInvalidComponent(parsed.port); |
369 ExpectInvalidComponent(parsed.query); | |
370 ExpectInvalidComponent(parsed.ref); | |
371 } | 371 } |
372 } | 372 } |
373 | 373 |
374 // Various incarnations of file URLs. | 374 // Various incarnations of file URLs. |
375 static URLParseCase file_cases[] = { | 375 static URLParseCase file_cases[] = { |
376 #ifdef WIN32 | 376 #ifdef WIN32 |
377 {"file:server", "file", NULL, NULL, "server", -1, NULL, NU
LL, NULL}, | 377 {"file:server", "file", NULL, NULL, "server", -1, NULL, NU
LL, NULL}, |
378 {" file: server \t", "file", NULL, NULL, " server",-1, NULL, NU
LL, NULL}, | 378 {" file: server \t", "file", NULL, NULL, " server",-1, NULL, NU
LL, NULL}, |
379 {"FiLe:c|", "FiLe", NULL, NULL, NULL, -1, "c|", NU
LL, NULL}, | 379 {"FiLe:c|", "FiLe", NULL, NULL, NULL, -1, "c|", NU
LL, NULL}, |
380 {"FILE:/\\\\/server/file", "FILE", NULL, NULL, "server", -1, "/file", NU
LL, NULL}, | 380 {"FILE:/\\\\/server/file", "FILE", NULL, NULL, "server", -1, "/file", NU
LL, NULL}, |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 // The remaining components are never used for filesystem urls. | 681 // The remaining components are never used for filesystem urls. |
682 ExpectInvalidComponent(parsed.username); | 682 ExpectInvalidComponent(parsed.username); |
683 ExpectInvalidComponent(parsed.password); | 683 ExpectInvalidComponent(parsed.password); |
684 ExpectInvalidComponent(parsed.host); | 684 ExpectInvalidComponent(parsed.host); |
685 ExpectInvalidComponent(parsed.port); | 685 ExpectInvalidComponent(parsed.port); |
686 } | 686 } |
687 } | 687 } |
688 | 688 |
689 } // namespace | 689 } // namespace |
690 } // namespace url_parse | 690 } // namespace url_parse |
OLD | NEW |