| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/basictypes.h" | |
| 6 #include "base/file_path.h" | |
| 7 #include "base/string_util.h" | |
| 8 #include "base/sys_string_conversions.h" | |
| 9 #include "base/time.h" | |
| 10 #include "googleurl/src/gurl.h" | |
| 11 #include "net/base/escape.h" | |
| 12 #include "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | 6 |
| 15 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 16 #include <ws2tcpip.h> | 8 #include <ws2tcpip.h> |
| 17 #else | 9 #else |
| 18 #include <netdb.h> | 10 #include <netdb.h> |
| 19 #endif | 11 #endif |
| 20 | 12 |
| 13 #include "base/file_path.h" |
| 14 #include "base/format_macros.h" |
| 15 #include "base/string_util.h" |
| 16 #include "base/sys_string_conversions.h" |
| 17 #include "base/time.h" |
| 18 #include "googleurl/src/gurl.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class NetUtilTest : public testing::Test { | 23 class NetUtilTest : public testing::Test { |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 struct FileCase { | 26 struct FileCase { |
| 27 const wchar_t* file; | 27 const wchar_t* file; |
| 28 const char* url; | 28 const char* url; |
| 29 }; | 29 }; |
| 30 | 30 |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 L"use+rname", | 572 L"use+rname", |
| 573 L"password", | 573 L"password", |
| 574 }, | 574 }, |
| 575 { // Use a '&' in the password. | 575 { // Use a '&' in the password. |
| 576 "http://username:p&ssword@google.com", | 576 "http://username:p&ssword@google.com", |
| 577 L"username", | 577 L"username", |
| 578 L"p&ssword", | 578 L"p&ssword", |
| 579 }, | 579 }, |
| 580 }; | 580 }; |
| 581 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 581 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 582 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, tests[i].input_url)); | 582 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url)); |
| 583 GURL url(tests[i].input_url); | 583 GURL url(tests[i].input_url); |
| 584 | 584 |
| 585 std::wstring username, password; | 585 std::wstring username, password; |
| 586 net::GetIdentityFromURL(url, &username, &password); | 586 net::GetIdentityFromURL(url, &username, &password); |
| 587 | 587 |
| 588 EXPECT_EQ(tests[i].expected_username, username); | 588 EXPECT_EQ(tests[i].expected_username, username); |
| 589 EXPECT_EQ(tests[i].expected_password, password); | 589 EXPECT_EQ(tests[i].expected_password, password); |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 { // Try an FTP URL -- strip both the reference and the username/password. | 1580 { // Try an FTP URL -- strip both the reference and the username/password. |
| 1581 "ftp://user:pass@google.com:80/sup?yo#X#X", | 1581 "ftp://user:pass@google.com:80/sup?yo#X#X", |
| 1582 "ftp://google.com:80/sup?yo", | 1582 "ftp://google.com:80/sup?yo", |
| 1583 }, | 1583 }, |
| 1584 { // Try an standard URL with unknow scheme. | 1584 { // Try an standard URL with unknow scheme. |
| 1585 "foobar://user:pass@google.com:80/sup?yo#X#X", | 1585 "foobar://user:pass@google.com:80/sup?yo#X#X", |
| 1586 "foobar://google.com:80/sup?yo", | 1586 "foobar://google.com:80/sup?yo", |
| 1587 }, | 1587 }, |
| 1588 }; | 1588 }; |
| 1589 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1589 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1590 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, tests[i].input_url)); | 1590 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url)); |
| 1591 GURL input_url(GURL(tests[i].input_url)); | 1591 GURL input_url(GURL(tests[i].input_url)); |
| 1592 GURL expected_url(GURL(tests[i].expected_simplified_url)); | 1592 GURL expected_url(GURL(tests[i].expected_simplified_url)); |
| 1593 EXPECT_EQ(expected_url, net::SimplifyUrlForRequest(input_url)); | 1593 EXPECT_EQ(expected_url, net::SimplifyUrlForRequest(input_url)); |
| 1594 } | 1594 } |
| 1595 } | 1595 } |
| 1596 | 1596 |
| 1597 TEST(NetUtilTest, SetExplicitlyAllowedPortsTest) { | 1597 TEST(NetUtilTest, SetExplicitlyAllowedPortsTest) { |
| 1598 std::wstring invalid[] = { L"1,2,a", L"'1','2'", L"1, 2, 3", L"1 0,11,12" }; | 1598 std::wstring invalid[] = { L"1,2,a", L"'1','2'", L"1, 2, 3", L"1 0,11,12" }; |
| 1599 std::wstring valid[] = { L"", L"1", L"1,2", L"1,2,3", L"10,11,12,13" }; | 1599 std::wstring valid[] = { L"", L"1", L"1,2", L"1,2,3", L"10,11,12,13" }; |
| 1600 | 1600 |
| 1601 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) { | 1601 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) { |
| 1602 net::SetExplicitlyAllowedPorts(invalid[i]); | 1602 net::SetExplicitlyAllowedPorts(invalid[i]); |
| 1603 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size())); | 1603 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size())); |
| 1604 } | 1604 } |
| 1605 | 1605 |
| 1606 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) { | 1606 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) { |
| 1607 net::SetExplicitlyAllowedPorts(valid[i]); | 1607 net::SetExplicitlyAllowedPorts(valid[i]); |
| 1608 EXPECT_EQ(i, net::explicitly_allowed_ports.size()); | 1608 EXPECT_EQ(i, net::explicitly_allowed_ports.size()); |
| 1609 } | 1609 } |
| 1610 } | 1610 } |
| OLD | NEW |