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("M\xc3\x9cNCHEN.com", | |
899 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(std::string(), out_str); | |
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( | |
928 CanonicalizeHostSubstring("01.02.03.04", Component(0, 11), &output)); | |
929 output.Complete(); | |
930 EXPECT_EQ("01.02.03.04", out_str); | |
931 } | |
932 } | |
933 | |
934 TEST(URLCanonTest, UserInfo) { | 890 TEST(URLCanonTest, UserInfo) { |
935 // Note that the canonicalizer should escape and treat empty components as | 891 // Note that the canonicalizer should escape and treat empty components as |
936 // not being there. | 892 // not being there. |
937 | 893 |
938 // We actually parse a full input URL so we can get the initial components. | 894 // We actually parse a full input URL so we can get the initial components. |
939 struct UserComponentCase { | 895 struct UserComponentCase { |
940 const char* input; | 896 const char* input; |
941 const char* expected; | 897 const char* expected; |
942 Component expected_username; | 898 Component expected_username; |
943 Component expected_password; | 899 Component expected_password; |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2242 }; | 2198 }; |
2243 | 2199 |
2244 for (auto& test_case : cases) { | 2200 for (auto& test_case : cases) { |
2245 SCOPED_TRACE(test_case.scheme); | 2201 SCOPED_TRACE(test_case.scheme); |
2246 EXPECT_EQ(test_case.expected_port, | 2202 EXPECT_EQ(test_case.expected_port, |
2247 DefaultPortForScheme(test_case.scheme, strlen(test_case.scheme))); | 2203 DefaultPortForScheme(test_case.scheme, strlen(test_case.scheme))); |
2248 } | 2204 } |
2249 } | 2205 } |
2250 | 2206 |
2251 } // namespace url | 2207 } // namespace url |
OLD | NEW |