| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "net/http/http_util.h" | 9 #include "net/http/http_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 }; | 584 }; |
| 585 for (size_t i = 0; i < arraysize(tests); ++i) { | 585 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 586 std::string input = tests[i].input; | 586 std::string input = tests[i].input; |
| 587 std::replace(input.begin(), input.end(), '|', '\0'); | 587 std::replace(input.begin(), input.end(), '|', '\0'); |
| 588 std::string raw = HttpUtil::AssembleRawHeaders(input.data(), input.size()); | 588 std::string raw = HttpUtil::AssembleRawHeaders(input.data(), input.size()); |
| 589 std::replace(raw.begin(), raw.end(), '\0', '|'); | 589 std::replace(raw.begin(), raw.end(), '\0', '|'); |
| 590 EXPECT_EQ(tests[i].expected_result, raw); | 590 EXPECT_EQ(tests[i].expected_result, raw); |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 | 593 |
| 594 // Test SpecForRequest() and PathForRequest(). | 594 // Test SpecForRequest(). |
| 595 TEST(HttpUtilTest, RequestUrlSanitize) { | 595 TEST(HttpUtilTest, RequestUrlSanitize) { |
| 596 struct { | 596 struct { |
| 597 const char* const url; | 597 const char* const url; |
| 598 const char* const expected_spec; | 598 const char* const expected_spec; |
| 599 const char* const expected_path; | |
| 600 } tests[] = { | 599 } tests[] = { |
| 601 { // Check that #hash is removed. | 600 { // Check that #hash is removed. |
| 602 "http://www.google.com:78/foobar?query=1#hash", | 601 "http://www.google.com:78/foobar?query=1#hash", |
| 603 "http://www.google.com:78/foobar?query=1", | 602 "http://www.google.com:78/foobar?query=1", |
| 604 "/foobar?query=1" | |
| 605 }, | 603 }, |
| 606 { // The reference may itself contain # -- strip all of it. | 604 { // The reference may itself contain # -- strip all of it. |
| 607 "http://192.168.0.1?query=1#hash#10#11#13#14", | 605 "http://192.168.0.1?query=1#hash#10#11#13#14", |
| 608 "http://192.168.0.1/?query=1", | 606 "http://192.168.0.1/?query=1", |
| 609 "/?query=1" | |
| 610 }, | 607 }, |
| 611 { // Strip username/password. | 608 { // Strip username/password. |
| 612 "http://user:pass@google.com", | 609 "http://user:pass@google.com", |
| 613 "http://google.com/", | 610 "http://google.com/", |
| 614 "/" | |
| 615 }, | 611 }, |
| 616 { // https scheme | 612 { // https scheme |
| 617 "https://www.google.com:78/foobar?query=1#hash", | 613 "https://www.google.com:78/foobar?query=1#hash", |
| 618 "https://www.google.com:78/foobar?query=1", | 614 "https://www.google.com:78/foobar?query=1", |
| 619 "/foobar?query=1" | |
| 620 }, | 615 }, |
| 621 { // WebSocket's ws scheme | 616 { // WebSocket's ws scheme |
| 622 "ws://www.google.com:78/foobar?query=1#hash", | 617 "ws://www.google.com:78/foobar?query=1#hash", |
| 623 "ws://www.google.com:78/foobar?query=1", | 618 "ws://www.google.com:78/foobar?query=1", |
| 624 "/foobar?query=1" | |
| 625 }, | 619 }, |
| 626 { // WebSocket's wss scheme | 620 { // WebSocket's wss scheme |
| 627 "wss://www.google.com:78/foobar?query=1#hash", | 621 "wss://www.google.com:78/foobar?query=1#hash", |
| 628 "wss://www.google.com:78/foobar?query=1", | 622 "wss://www.google.com:78/foobar?query=1", |
| 629 "/foobar?query=1" | |
| 630 } | 623 } |
| 631 }; | 624 }; |
| 632 for (size_t i = 0; i < arraysize(tests); ++i) { | 625 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 626 SCOPED_TRACE(i); |
| 627 |
| 633 GURL url(GURL(tests[i].url)); | 628 GURL url(GURL(tests[i].url)); |
| 634 std::string expected_spec(tests[i].expected_spec); | 629 std::string expected_spec(tests[i].expected_spec); |
| 635 std::string expected_path(tests[i].expected_path); | |
| 636 | 630 |
| 637 EXPECT_EQ(expected_spec, HttpUtil::SpecForRequest(url)); | 631 EXPECT_EQ(expected_spec, HttpUtil::SpecForRequest(url)); |
| 638 EXPECT_EQ(expected_path, HttpUtil::PathForRequest(url)); | |
| 639 } | 632 } |
| 640 } | 633 } |
| 641 | 634 |
| 642 // Test SpecForRequest() for "ftp" scheme. | 635 // Test SpecForRequest() for "ftp" scheme. |
| 643 TEST(HttpUtilTest, SpecForRequestForUrlWithFtpScheme) { | 636 TEST(HttpUtilTest, SpecForRequestForUrlWithFtpScheme) { |
| 644 GURL ftp_url("ftp://user:pass@google.com/pub/chromium/"); | 637 GURL ftp_url("ftp://user:pass@google.com/pub/chromium/"); |
| 645 EXPECT_EQ("ftp://google.com/pub/chromium/", | 638 EXPECT_EQ("ftp://google.com/pub/chromium/", |
| 646 HttpUtil::SpecForRequest(ftp_url)); | 639 HttpUtil::SpecForRequest(ftp_url)); |
| 647 } | 640 } |
| 648 | 641 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); | 1102 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
| 1110 EXPECT_TRUE(parser.valid()); | 1103 EXPECT_TRUE(parser.valid()); |
| 1111 | 1104 |
| 1112 ASSERT_NO_FATAL_FAILURE( | 1105 ASSERT_NO_FATAL_FAILURE( |
| 1113 CheckNextNameValuePair(&parser, true, true, "name", "value")); | 1106 CheckNextNameValuePair(&parser, true, true, "name", "value")); |
| 1114 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( | 1107 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( |
| 1115 &parser, false, true, std::string(), std::string())); | 1108 &parser, false, true, std::string(), std::string())); |
| 1116 } | 1109 } |
| 1117 | 1110 |
| 1118 } // namespace net | 1111 } // namespace net |
| OLD | NEW |