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 <errno.h> | 5 #include <errno.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "url/third_party/mozilla/url_parse.h" | 10 #include "url/third_party/mozilla/url_parse.h" |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 | 880 |
881 // This tests tests. | 881 // This tests tests. |
882 const char spec[] = "192.168.0.1"; | 882 const char spec[] = "192.168.0.1"; |
883 CanonicalizeIPAddress(spec, Component(), &output1, &host_info); | 883 CanonicalizeIPAddress(spec, Component(), &output1, &host_info); |
884 EXPECT_FALSE(host_info.IsIPAddress()); | 884 EXPECT_FALSE(host_info.IsIPAddress()); |
885 | 885 |
886 CanonicalizeIPAddress(spec, Component(0, 0), &output1, &host_info); | 886 CanonicalizeIPAddress(spec, Component(0, 0), &output1, &host_info); |
887 EXPECT_FALSE(host_info.IsIPAddress()); | 887 EXPECT_FALSE(host_info.IsIPAddress()); |
888 } | 888 } |
889 | 889 |
890 // Verifies that CanonicalizeHostSubstring produces the expected output and | |
891 // does not "fix" IP addresses. Because this code is a subset of | |
892 // CanonicalizeHost, the shared functionality is not tested. | |
893 TEST(URLCanonTest, CanonicalizeHostSubstring) { | |
894 // Basic sanity check. | |
895 { | |
896 std::string out_str; | |
897 StdStringCanonOutput output(&out_str); | |
898 EXPECT_TRUE(CanonicalizeHostSubstring( | |
899 "M\xc3\x9cNCHEN.com", Component(0, 12), &output)); | |
900 output.Complete(); | |
901 EXPECT_EQ("xn--mnchen-3ya.com", out_str); | |
902 } | |
903 | |
904 // Failure case. | |
905 { | |
906 std::string out_str; | |
907 StdStringCanonOutput output(&out_str); | |
908 EXPECT_FALSE(CanonicalizeHostSubstring( | |
909 WStringToUTF16(L"\xfdd0zyx.com").c_str(), Component(0, 8), &output)); | |
910 output.Complete(); | |
911 EXPECT_EQ("%EF%BF%BDzyx.com", out_str); | |
912 } | |
913 | |
914 // Should return true for empty input strings. | |
915 { | |
916 std::string out_str; | |
917 StdStringCanonOutput output(&out_str); | |
918 EXPECT_TRUE(CanonicalizeHostSubstring("", Component(0, 0), &output)); | |
919 output.Complete(); | |
920 EXPECT_EQ("", out_str); | |
Peter Kasting
2016/10/22 05:04:20
Nit: Since |out_str| is a std::string I tend to pr
| |
921 } | |
922 | |
923 // Numbers that look like IP addresses should not be changed. | |
924 { | |
925 std::string out_str; | |
926 StdStringCanonOutput output(&out_str); | |
927 EXPECT_TRUE(CanonicalizeHostSubstring( | |
928 "01.02.03.04", Component(0, 11), &output)); | |
929 output.Complete(); | |
930 EXPECT_EQ("01.02.03.04", out_str); | |
931 } | |
932 } | |
933 | |
890 TEST(URLCanonTest, UserInfo) { | 934 TEST(URLCanonTest, UserInfo) { |
891 // Note that the canonicalizer should escape and treat empty components as | 935 // Note that the canonicalizer should escape and treat empty components as |
892 // not being there. | 936 // not being there. |
893 | 937 |
894 // We actually parse a full input URL so we can get the initial components. | 938 // We actually parse a full input URL so we can get the initial components. |
895 struct UserComponentCase { | 939 struct UserComponentCase { |
896 const char* input; | 940 const char* input; |
897 const char* expected; | 941 const char* expected; |
898 Component expected_username; | 942 Component expected_username; |
899 Component expected_password; | 943 Component expected_password; |
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2194 }; | 2238 }; |
2195 | 2239 |
2196 for (auto& test_case : cases) { | 2240 for (auto& test_case : cases) { |
2197 SCOPED_TRACE(test_case.scheme); | 2241 SCOPED_TRACE(test_case.scheme); |
2198 EXPECT_EQ(test_case.expected_port, | 2242 EXPECT_EQ(test_case.expected_port, |
2199 DefaultPortForScheme(test_case.scheme, strlen(test_case.scheme))); | 2243 DefaultPortForScheme(test_case.scheme, strlen(test_case.scheme))); |
2200 } | 2244 } |
2201 } | 2245 } |
2202 | 2246 |
2203 } // namespace url | 2247 } // namespace url |
OLD | NEW |