Chromium Code Reviews| 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"}, | |
|
mmenke
2016/06/01 20:39:41
Other than the addition of the last test case, the
| |
| 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 EXPECT_EQ(replace_cases[i].expected, output.inner_url()->spec()); | |
|
mmenke
2016/06/01 20:39:41
I'm not sure if the inner_url's spec is suppose to
| |
| 429 } | 442 } |
| 430 } | 443 } |
| 431 | 444 |
| 432 TEST(GURLTest, ClearFragmentOnDataUrl) { | 445 TEST(GURLTest, ClearFragmentOnDataUrl) { |
| 433 // http://crbug.com/291747 - a data URL may legitimately have trailing | 446 // 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 | 447 // whitespace in the spec after the ref is cleared. Test this does not trigger |
| 435 // the Parsed importing validation DCHECK in GURL. | 448 // the Parsed importing validation DCHECK in GURL. |
| 436 GURL url(" data: one ? two # three "); | 449 GURL url(" data: one ? two # three "); |
| 437 | 450 |
| 438 // By default the trailing whitespace will have been stripped. | 451 // By default the trailing whitespace will have been stripped. |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 }; | 695 }; |
| 683 | 696 |
| 684 for (const auto& test : cases) { | 697 for (const auto& test : cases) { |
| 685 GURL url(test.url); | 698 GURL url(test.url); |
| 686 EXPECT_EQ(test.expected, url.path()) << test.url; | 699 EXPECT_EQ(test.expected, url.path()) << test.url; |
| 687 EXPECT_EQ(test.expected, url.GetContent()) << test.url; | 700 EXPECT_EQ(test.expected, url.GetContent()) << test.url; |
| 688 } | 701 } |
| 689 } | 702 } |
| 690 | 703 |
| 691 } // namespace url | 704 } // namespace url |
| OLD | NEW |