Chromium Code Reviews| 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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 }, | 605 }, |
| 606 { // The reference may itself contain # -- strip all of it. | 606 { // The reference may itself contain # -- strip all of it. |
| 607 "http://192.168.0.1?query=1#hash#10#11#13#14", | 607 "http://192.168.0.1?query=1#hash#10#11#13#14", |
| 608 "http://192.168.0.1/?query=1", | 608 "http://192.168.0.1/?query=1", |
| 609 "/?query=1" | 609 "/?query=1" |
| 610 }, | 610 }, |
| 611 { // Strip username/password. | 611 { // Strip username/password. |
| 612 "http://user:pass@google.com", | 612 "http://user:pass@google.com", |
| 613 "http://google.com/", | 613 "http://google.com/", |
| 614 "/" | 614 "/" |
| 615 } | 615 }, |
| 616 { // https scheme | |
| 617 "https://www.google.com:78/foobar?query=1#hash", | |
| 618 "https://www.google.com:78/foobar?query=1", | |
| 619 "/foobar?query=1" | |
| 620 }, | |
| 621 { // WebSocket's ws scheme | |
| 622 "ws://www.google.com:78/foobar?query=1#hash", | |
| 623 "ws://www.google.com:78/foobar?query=1", | |
| 624 "/foobar?query=1" | |
| 625 }, | |
| 626 { // WebSocket's wss scheme | |
| 627 "wss://www.google.com:78/foobar?query=1#hash", | |
| 628 "wss://www.google.com:78/foobar?query=1", | |
| 629 "/foobar?query=1" | |
| 630 }, | |
| 616 }; | 631 }; |
| 617 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 632 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 618 GURL url(GURL(tests[i].url)); | 633 GURL url(GURL(tests[i].url)); |
| 619 std::string expected_spec(tests[i].expected_spec); | 634 std::string expected_spec(tests[i].expected_spec); |
| 620 std::string expected_path(tests[i].expected_path); | 635 std::string expected_path(tests[i].expected_path); |
| 621 | 636 |
| 622 EXPECT_EQ(expected_spec, HttpUtil::SpecForRequest(url)); | 637 EXPECT_EQ(expected_spec, HttpUtil::SpecForRequest(url)); |
| 623 EXPECT_EQ(expected_path, HttpUtil::PathForRequest(url)); | 638 EXPECT_EQ(expected_path, HttpUtil::PathForRequest(url)); |
| 624 } | 639 } |
| 640 | |
| 641 // ftp scheme | |
|
Adam Rice
2013/11/15 08:01:44
I would prefer to have this as a separate test cas
tyoshino (SeeGerritForStatus)
2013/11/15 13:35:50
Done.
| |
| 642 GURL ftp_url("ftp://user:pass@google.com/pub/chromium/"); | |
| 643 EXPECT_EQ("ftp://google.com/pub/chromium/", | |
| 644 HttpUtil::SpecForRequest(ftp_url)); | |
| 625 } | 645 } |
| 626 | 646 |
| 627 TEST(HttpUtilTest, GenerateAcceptLanguageHeader) { | 647 TEST(HttpUtilTest, GenerateAcceptLanguageHeader) { |
| 628 EXPECT_EQ(std::string("en-US,fr;q=0.8,de;q=0.6"), | 648 EXPECT_EQ(std::string("en-US,fr;q=0.8,de;q=0.6"), |
| 629 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de")); | 649 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de")); |
| 630 EXPECT_EQ(std::string("en-US,fr;q=0.8,de;q=0.6,ko;q=0.4,zh-CN;q=0.2," | 650 EXPECT_EQ(std::string("en-US,fr;q=0.8,de;q=0.6,ko;q=0.4,zh-CN;q=0.2," |
| 631 "ja;q=0.2"), | 651 "ja;q=0.2"), |
| 632 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja")); | 652 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja")); |
| 633 } | 653 } |
| 634 | 654 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1042 TEST(HttpUtilTest, NameValuePairsIteratorMissingEndQuote) { | 1062 TEST(HttpUtilTest, NameValuePairsIteratorMissingEndQuote) { |
| 1043 std::string data = "name='value"; | 1063 std::string data = "name='value"; |
| 1044 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); | 1064 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
| 1045 EXPECT_TRUE(parser.valid()); | 1065 EXPECT_TRUE(parser.valid()); |
| 1046 | 1066 |
| 1047 ASSERT_NO_FATAL_FAILURE( | 1067 ASSERT_NO_FATAL_FAILURE( |
| 1048 CheckNextNameValuePair(&parser, true, true, "name", "value")); | 1068 CheckNextNameValuePair(&parser, true, true, "name", "value")); |
| 1049 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( | 1069 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( |
| 1050 &parser, false, true, std::string(), std::string())); | 1070 &parser, false, true, std::string(), std::string())); |
| 1051 } | 1071 } |
| OLD | NEW |