| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/tools/dump_cache/url_utilities.h" | 5 #include "net/tools/dump_cache/url_utilities.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace net { | 13 namespace net { |
| 13 | 14 |
| 14 TEST(UrlUtilitiesTest, GetUrlHost) { | 15 TEST(UrlUtilitiesTest, GetUrlHost) { |
| 15 EXPECT_EQ("www.foo.com", | 16 EXPECT_EQ("www.foo.com", |
| 16 UrlUtilities::GetUrlHost("http://www.foo.com")); | 17 UrlUtilities::GetUrlHost("http://www.foo.com")); |
| 17 EXPECT_EQ("www.foo.com", | 18 EXPECT_EQ("www.foo.com", |
| 18 UrlUtilities::GetUrlHost("http://www.foo.com:80")); | 19 UrlUtilities::GetUrlHost("http://www.foo.com:80")); |
| 19 EXPECT_EQ("www.foo.com", | 20 EXPECT_EQ("www.foo.com", |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 EXPECT_EQ("www.foo.com:80/news?q=hello", | 70 EXPECT_EQ("www.foo.com:80/news?q=hello", |
| 70 UrlUtilities::Unescape("www.foo.com:80/news?q=hello")); | 71 UrlUtilities::Unescape("www.foo.com:80/news?q=hello")); |
| 71 | 72 |
| 72 // All chars can be unescaped. | 73 // All chars can be unescaped. |
| 73 EXPECT_EQ("~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", | 74 EXPECT_EQ("~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", |
| 74 UrlUtilities::Unescape("%7E%60%21%40%23%24%25%5E%26%2A%28%29%5F%2D" | 75 UrlUtilities::Unescape("%7E%60%21%40%23%24%25%5E%26%2A%28%29%5F%2D" |
| 75 "%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22%27%3C%2C" | 76 "%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22%27%3C%2C" |
| 76 "%3E%2E%3F%2F")); | 77 "%3E%2E%3F%2F")); |
| 77 for (int c = 0; c < 256; ++c) { | 78 for (int c = 0; c < 256; ++c) { |
| 78 std::string unescaped_char(1, implicit_cast<unsigned char>(c)); | 79 std::string unescaped_char(1, implicit_cast<unsigned char>(c)); |
| 79 std::string escaped_char = StringPrintf("%%%02X", c); | 80 std::string escaped_char = base::StringPrintf("%%%02X", c); |
| 80 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char)) | 81 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char)) |
| 81 << "escaped_char = " << escaped_char; | 82 << "escaped_char = " << escaped_char; |
| 82 escaped_char = StringPrintf("%%%02x", c); | 83 escaped_char = base::StringPrintf("%%%02x", c); |
| 83 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char)) | 84 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char)) |
| 84 << "escaped_char = " << escaped_char; | 85 << "escaped_char = " << escaped_char; |
| 85 } | 86 } |
| 86 | 87 |
| 87 // All non-% chars are left alone. | 88 // All non-% chars are left alone. |
| 88 EXPECT_EQ("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/", | 89 EXPECT_EQ("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/", |
| 89 UrlUtilities::Unescape("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/")); | 90 UrlUtilities::Unescape("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/")); |
| 90 for (int c = 0; c < 256; ++c) { | 91 for (int c = 0; c < 256; ++c) { |
| 91 if (c != '%') { | 92 if (c != '%') { |
| 92 std::string just_char(1, implicit_cast<unsigned char>(c)); | 93 std::string just_char(1, implicit_cast<unsigned char>(c)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 104 EXPECT_EQ("%1", UrlUtilities::Unescape("%1")); | 105 EXPECT_EQ("%1", UrlUtilities::Unescape("%1")); |
| 105 EXPECT_EQ("%1x", UrlUtilities::Unescape("%1x")); | 106 EXPECT_EQ("%1x", UrlUtilities::Unescape("%1x")); |
| 106 EXPECT_EQ("%%", UrlUtilities::Unescape("%%")); | 107 EXPECT_EQ("%%", UrlUtilities::Unescape("%%")); |
| 107 // Escapes following non-escapes. | 108 // Escapes following non-escapes. |
| 108 EXPECT_EQ("%!", UrlUtilities::Unescape("%%21")); | 109 EXPECT_EQ("%!", UrlUtilities::Unescape("%%21")); |
| 109 EXPECT_EQ("%2!", UrlUtilities::Unescape("%2%21")); | 110 EXPECT_EQ("%2!", UrlUtilities::Unescape("%2%21")); |
| 110 } | 111 } |
| 111 | 112 |
| 112 } // namespace net | 113 } // namespace net |
| 113 | 114 |
| OLD | NEW |