| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.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/gurl.h" | 9 #include "url/gurl.h" |
| 10 #include "url/url_canon.h" | 10 #include "url/url_canon.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 const char* scheme; | 394 const char* scheme; |
| 395 const char* username; | 395 const char* username; |
| 396 const char* password; | 396 const char* password; |
| 397 const char* host; | 397 const char* host; |
| 398 const char* port; | 398 const char* port; |
| 399 const char* path; | 399 const char* path; |
| 400 const char* query; | 400 const char* query; |
| 401 const char* ref; | 401 const char* ref; |
| 402 const char* expected; | 402 const char* expected; |
| 403 } replace_cases[] = { | 403 } replace_cases[] = { |
| 404 {"http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL, NULL, NULL,
"/", "", "", "http://www.google.com/"}, | 404 {"http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL, NULL, |
| 405 {"http://www.google.com/foo/bar.html?foo#bar", "javascript", "", "", "", "",
"window.open('foo');", "", "", "javascript:window.open('foo');"}, | 405 NULL, "/", "", "", "http://www.google.com/"}, |
| 406 {"file:///C:/foo/bar.txt", "http", NULL, NULL, "www.google.com", "99", "/foo
", "search", "ref", "http://www.google.com:99/foo?search#ref"}, | 406 {"http://www.google.com/foo/bar.html?foo#bar", "javascript", "", "", "", |
| 407 "", "window.open('foo');", "", "", "javascript:window.open('foo');"}, |
| 408 {"file:///C:/foo/bar.txt", "http", NULL, NULL, "www.google.com", "99", |
| 409 "/foo", "search", "ref", "http://www.google.com:99/foo?search#ref"}, |
| 407 #ifdef WIN32 | 410 #ifdef WIN32 |
| 408 {"http://www.google.com/foo/bar.html?foo#bar", "file", "", "", "", "", "c:\\
", "", "", "file:///C:/"}, | 411 {"http://www.google.com/foo/bar.html?foo#bar", "file", "", "", "", "", |
| 412 "c:\\", "", "", "file:///C:/"}, |
| 409 #endif | 413 #endif |
| 410 {"filesystem:http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL,
NULL, NULL, "/", "", "", "filesystem:http://www.google.com/foo/"}, | 414 {"filesystem:http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, |
| 415 NULL, NULL, NULL, "/", "", "", "filesystem:http://www.google.com/foo/"}, |
| 416 // Lengthen the URL instead of shortening it, to test creation of |
| 417 // inner_url. |
| 418 {"filesystem:http://www.google.com/foo/", NULL, NULL, NULL, NULL, NULL, |
| 419 "bar.html", "foo", "bar", |
| 420 "filesystem:http://www.google.com/foo/bar.html?foo#bar"}, |
| 411 }; | 421 }; |
| 412 | 422 |
| 413 for (size_t i = 0; i < arraysize(replace_cases); i++) { | 423 for (size_t i = 0; i < arraysize(replace_cases); i++) { |
| 414 const ReplaceCase& cur = replace_cases[i]; | 424 const ReplaceCase& cur = replace_cases[i]; |
| 415 GURL url(cur.base); | 425 GURL url(cur.base); |
| 416 GURL::Replacements repl; | 426 GURL::Replacements repl; |
| 417 SetupReplacement(&GURL::Replacements::SetScheme, &repl, cur.scheme); | 427 SetupReplacement(&GURL::Replacements::SetScheme, &repl, cur.scheme); |
| 418 SetupReplacement(&GURL::Replacements::SetUsername, &repl, cur.username); | 428 SetupReplacement(&GURL::Replacements::SetUsername, &repl, cur.username); |
| 419 SetupReplacement(&GURL::Replacements::SetPassword, &repl, cur.password); | 429 SetupReplacement(&GURL::Replacements::SetPassword, &repl, cur.password); |
| 420 SetupReplacement(&GURL::Replacements::SetHost, &repl, cur.host); | 430 SetupReplacement(&GURL::Replacements::SetHost, &repl, cur.host); |
| 421 SetupReplacement(&GURL::Replacements::SetPort, &repl, cur.port); | 431 SetupReplacement(&GURL::Replacements::SetPort, &repl, cur.port); |
| 422 SetupReplacement(&GURL::Replacements::SetPath, &repl, cur.path); | 432 SetupReplacement(&GURL::Replacements::SetPath, &repl, cur.path); |
| 423 SetupReplacement(&GURL::Replacements::SetQuery, &repl, cur.query); | 433 SetupReplacement(&GURL::Replacements::SetQuery, &repl, cur.query); |
| 424 SetupReplacement(&GURL::Replacements::SetRef, &repl, cur.ref); | 434 SetupReplacement(&GURL::Replacements::SetRef, &repl, cur.ref); |
| 425 GURL output = url.ReplaceComponents(repl); | 435 GURL output = url.ReplaceComponents(repl); |
| 426 | 436 |
| 427 EXPECT_EQ(replace_cases[i].expected, output.spec()); | 437 EXPECT_EQ(replace_cases[i].expected, output.spec()); |
| 438 |
| 428 EXPECT_EQ(output.SchemeIsFileSystem(), output.inner_url() != NULL); | 439 EXPECT_EQ(output.SchemeIsFileSystem(), output.inner_url() != NULL); |
| 440 if (output.SchemeIsFileSystem()) { |
| 441 // TODO(mmenke): inner_url()->spec() is currently the same as the spec() |
| 442 // for the GURL itself. This should be fixed. |
| 443 // See https://crbug.com/619596 |
| 444 EXPECT_EQ(replace_cases[i].expected, output.inner_url()->spec()); |
| 445 } |
| 429 } | 446 } |
| 430 } | 447 } |
| 431 | 448 |
| 432 TEST(GURLTest, ClearFragmentOnDataUrl) { | 449 TEST(GURLTest, ClearFragmentOnDataUrl) { |
| 433 // http://crbug.com/291747 - a data URL may legitimately have trailing | 450 // http://crbug.com/291747 - a data URL may legitimately have trailing |
| 434 // whitespace in the spec after the ref is cleared. Test this does not trigger | 451 // whitespace in the spec after the ref is cleared. Test this does not trigger |
| 435 // the Parsed importing validation DCHECK in GURL. | 452 // the Parsed importing validation DCHECK in GURL. |
| 436 GURL url(" data: one ? two # three "); | 453 GURL url(" data: one ? two # three "); |
| 437 | 454 |
| 438 // By default the trailing whitespace will have been stripped. | 455 // By default the trailing whitespace will have been stripped. |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 }; | 699 }; |
| 683 | 700 |
| 684 for (const auto& test : cases) { | 701 for (const auto& test : cases) { |
| 685 GURL url(test.url); | 702 GURL url(test.url); |
| 686 EXPECT_EQ(test.expected, url.path()) << test.url; | 703 EXPECT_EQ(test.expected, url.path()) << test.url; |
| 687 EXPECT_EQ(test.expected, url.GetContent()) << test.url; | 704 EXPECT_EQ(test.expected, url.GetContent()) << test.url; |
| 688 } | 705 } |
| 689 } | 706 } |
| 690 | 707 |
| 691 } // namespace url | 708 } // namespace url |
| OLD | NEW |