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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 size_t position, | 445 size_t position, |
446 const base::string16& formatted_url) { | 446 const base::string16& formatted_url) { |
447 EXPECT_EQ(expected, actual) << "Original URL: " << original_url | 447 EXPECT_EQ(expected, actual) << "Original URL: " << original_url |
448 << " (at char " << position << ")\nFormatted URL: " << formatted_url; | 448 << " (at char " << position << ")\nFormatted URL: " << formatted_url; |
449 } | 449 } |
450 | 450 |
451 void CheckAdjustedOffsets(const std::string& url_string, | 451 void CheckAdjustedOffsets(const std::string& url_string, |
452 const std::string& languages, | 452 const std::string& languages, |
453 FormatUrlTypes format_types, | 453 FormatUrlTypes format_types, |
454 UnescapeRule::Type unescape_rules, | 454 UnescapeRule::Type unescape_rules, |
455 const AdjustOffsetCase* cases, | 455 const size_t* output_offsets) { |
456 size_t num_cases, | |
457 const size_t* all_offsets) { | |
458 GURL url(url_string); | 456 GURL url(url_string); |
459 for (size_t i = 0; i < num_cases; ++i) { | 457 size_t url_length = url_string.length(); |
460 size_t offset = cases[i].input_offset; | |
461 base::string16 formatted_url = FormatUrl(url, languages, format_types, | |
462 unescape_rules, NULL, NULL, &offset); | |
463 VerboseExpect(cases[i].output_offset, offset, url_string, i, formatted_url); | |
464 } | |
465 | |
466 size_t url_size = url_string.length(); | |
467 std::vector<size_t> offsets; | 458 std::vector<size_t> offsets; |
468 for (size_t i = 0; i < url_size + 1; ++i) | 459 for (size_t i = 0; i <= url_length + 1; ++i) |
469 offsets.push_back(i); | 460 offsets.push_back(i); |
461 offsets.push_back(500000); // Something larger than any input length. | |
462 offsets.push_back(std::string::npos); | |
470 base::string16 formatted_url = FormatUrlWithOffsets(url, languages, | 463 base::string16 formatted_url = FormatUrlWithOffsets(url, languages, |
471 format_types, unescape_rules, NULL, NULL, &offsets); | 464 format_types, unescape_rules, NULL, NULL, &offsets); |
472 for (size_t i = 0; i < url_size; ++i) | 465 for (size_t i = 0; i < url_length; ++i) |
473 VerboseExpect(all_offsets[i], offsets[i], url_string, i, formatted_url); | 466 VerboseExpect(output_offsets[i], offsets[i], url_string, i, formatted_url); |
474 VerboseExpect(kNpos, offsets[url_size], url_string, url_size, formatted_url); | 467 VerboseExpect(formatted_url.length(), offsets[url_length], url_string, |
468 url_length, formatted_url); | |
469 VerboseExpect(base::string16::npos, offsets[url_length + 1], url_string, | |
470 500000, formatted_url); | |
471 VerboseExpect(base::string16::npos, offsets[url_length + 2], url_string, | |
472 std::string::npos, formatted_url); | |
475 } | 473 } |
476 | 474 |
477 // Helper to strignize an IP number (used to define expectations). | 475 // Helper to strignize an IP number (used to define expectations). |
478 std::string DumpIPNumber(const IPAddressNumber& v) { | 476 std::string DumpIPNumber(const IPAddressNumber& v) { |
479 std::string out; | 477 std::string out; |
480 for (size_t i = 0; i < v.size(); ++i) { | 478 for (size_t i = 0; i < v.size(); ++i) { |
481 if (i != 0) | 479 if (i != 0) |
482 out.append(","); | 480 out.append(","); |
483 out.append(base::IntToString(static_cast<int>(v[i]))); | 481 out.append(base::IntToString(static_cast<int>(v[i]))); |
484 } | 482 } |
(...skipping 2394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2879 if (test_char && | 2877 if (test_char && |
2880 strchr(kUnescapedCharacters, static_cast<char>(test_char))) { | 2878 strchr(kUnescapedCharacters, static_cast<char>(test_char))) { |
2881 EXPECT_NE(url.spec(), GURL(formatted).spec()); | 2879 EXPECT_NE(url.spec(), GURL(formatted).spec()); |
2882 } else { | 2880 } else { |
2883 EXPECT_EQ(url.spec(), GURL(formatted).spec()); | 2881 EXPECT_EQ(url.spec(), GURL(formatted).spec()); |
2884 } | 2882 } |
2885 } | 2883 } |
2886 } | 2884 } |
2887 | 2885 |
2888 TEST(NetUtilTest, FormatUrlWithOffsets) { | 2886 TEST(NetUtilTest, FormatUrlWithOffsets) { |
2889 const AdjustOffsetCase null_cases[] = { | 2887 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing, |
2890 {0, base::string16::npos}, | 2888 UnescapeRule::NORMAL, NULL); |
2889 | |
2890 const size_t basic_offsets[] = { | |
2891 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, | |
2892 21, 22, 23, 24, 25 | |
2891 }; | 2893 }; |
2892 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing, | 2894 CheckAdjustedOffsets("http://www.google.com/foo/", "en", |
2893 UnescapeRule::NORMAL, null_cases, arraysize(null_cases), NULL); | 2895 kFormatUrlOmitNothing, UnescapeRule::NORMAL, |
2896 basic_offsets); | |
2894 | 2897 |
2895 const AdjustOffsetCase basic_cases[] = { | 2898 const size_t omit_auth_offsets_1[] = { |
2896 {0, 0}, | 2899 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7, |
2897 {3, 3}, | 2900 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 |
2898 {5, 5}, | |
2899 {6, 6}, | |
2900 {13, 13}, | |
2901 {21, 21}, | |
2902 {22, 22}, | |
2903 {23, 23}, | |
2904 {25, 25}, | |
2905 {26, base::string16::npos}, | |
2906 {500000, base::string16::npos}, | |
2907 {base::string16::npos, base::string16::npos}, | |
2908 }; | 2901 }; |
2909 const size_t basic_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, | 2902 CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en", |
2910 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}; | 2903 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, |
2911 CheckAdjustedOffsets("http://www.google.com/foo/", "en", | 2904 omit_auth_offsets_1); |
2912 kFormatUrlOmitNothing, UnescapeRule::NORMAL, basic_cases, | |
2913 arraysize(basic_cases), basic_offsets); | |
2914 | 2905 |
2915 const AdjustOffsetCase omit_auth_cases_1[] = { | 2906 const size_t omit_auth_offsets_2[] = { |
2916 {6, 6}, | 2907 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14, |
2917 {7, base::string16::npos}, | 2908 15, 16, 17, 18, 19, 20, 21 |
2918 {8, base::string16::npos}, | |
2919 {10, base::string16::npos}, | |
2920 {12, base::string16::npos}, | |
2921 {14, base::string16::npos}, | |
2922 {15, 7}, | |
2923 {25, 17}, | |
2924 }; | 2909 }; |
2925 const size_t omit_auth_offsets_1[] = {0, 1, 2, 3, 4, 5, 6, kNpos, kNpos, | 2910 CheckAdjustedOffsets("http://foo@www.google.com/", "en", |
2926 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14, 15, | 2911 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, |
2927 16, 17, 18, 19, 20, 21}; | 2912 omit_auth_offsets_2); |
2928 CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en", | |
2929 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, omit_auth_cases_1, | |
2930 arraysize(omit_auth_cases_1), omit_auth_offsets_1); | |
2931 | 2913 |
2932 const AdjustOffsetCase omit_auth_cases_2[] = { | 2914 const size_t dont_omit_auth_offsets[] = { |
2933 {9, base::string16::npos}, | 2915 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
2934 {11, 7}, | 2916 kNpos, kNpos, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
2917 kNpos, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, | |
2918 30, 31 | |
2935 }; | 2919 }; |
2936 const size_t omit_auth_offsets_2[] = {0, 1, 2, 3, 4, 5, 6, kNpos, kNpos, | 2920 // Unescape to "http://foo\x30B0:\x30B0bar@www.google.com". |
2937 kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; | 2921 CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en", |
2938 CheckAdjustedOffsets("http://foo@www.google.com/", "en", | 2922 kFormatUrlOmitNothing, UnescapeRule::NORMAL, |
2939 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, omit_auth_cases_2, | 2923 dont_omit_auth_offsets); |
2940 arraysize(omit_auth_cases_2), omit_auth_offsets_2); | |
2941 | 2924 |
2942 // "http://foo\x30B0:\x30B0bar@www.google.com" | 2925 const size_t view_source_offsets[] = { |
2943 const AdjustOffsetCase dont_omit_auth_cases[] = { | 2926 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, kNpos, |
2944 {0, 0}, | 2927 kNpos, kNpos, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 |
2945 /*{3, base::string16::npos}, | |
2946 {7, 0}, | |
2947 {11, 4}, | |
2948 {12, base::string16::npos}, | |
2949 {20, 5}, | |
2950 {24, 9},*/ | |
2951 }; | 2928 }; |
2952 const size_t dont_omit_auth_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | 2929 CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en", |
2953 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 11, 12, kNpos, | 2930 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, |
2954 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 13, 14, 15, 16, 17, 18, | 2931 view_source_offsets); |
2955 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; | |
2956 CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en", | |
2957 kFormatUrlOmitNothing, UnescapeRule::NORMAL, dont_omit_auth_cases, | |
2958 arraysize(dont_omit_auth_cases), dont_omit_auth_offsets); | |
2959 | 2932 |
2960 const AdjustOffsetCase view_source_cases[] = { | 2933 const size_t idn_hostname_offsets_1[] = { |
2961 {0, 0}, | 2934 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
2962 {3, 3}, | 2935 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, |
2963 {11, 11}, | 2936 13, 14, 15, 16, 17, 18, 19 |
2964 {12, 12}, | |
2965 {13, 13}, | |
2966 {18, 18}, | |
2967 {19, base::string16::npos}, | |
2968 {20, base::string16::npos}, | |
2969 {23, 19}, | |
2970 {26, 22}, | |
2971 {base::string16::npos, base::string16::npos}, | |
2972 }; | 2937 }; |
2973 const size_t view_source_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, | 2938 // Convert punycode to "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/". |
2974 12, 13, 14, 15, 16, 17, 18, kNpos, kNpos, kNpos, kNpos, 19, 20, 21, 22, | 2939 CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja", |
2975 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33}; | 2940 kFormatUrlOmitNothing, UnescapeRule::NORMAL, |
2976 CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en", | 2941 idn_hostname_offsets_1); |
2977 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, view_source_cases, | |
2978 arraysize(view_source_cases), view_source_offsets); | |
2979 | 2942 |
2980 // "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/" | 2943 const size_t idn_hostname_offsets_2[] = { |
2981 const AdjustOffsetCase idn_hostname_cases_1[] = { | 2944 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, |
2982 {8, base::string16::npos}, | 2945 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 14, 15, kNpos, kNpos, kNpos, |
2983 {16, base::string16::npos}, | 2946 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
2984 {24, base::string16::npos}, | 2947 kNpos, 19, 20, 21, 22, 23, 24 |
2985 {25, 12}, | |
2986 {30, 17}, | |
2987 }; | 2948 }; |
2988 const size_t idn_hostname_offsets_1[] = {0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, | 2949 // Convert punycode to |
2989 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | 2950 // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/". |
2990 kNpos, kNpos, kNpos, kNpos, kNpos, 12, 13, 14, 15, 16, 17, 18, 19}; | |
2991 CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja", | |
2992 kFormatUrlOmitNothing, UnescapeRule::NORMAL, idn_hostname_cases_1, | |
2993 arraysize(idn_hostname_cases_1), idn_hostname_offsets_1); | |
2994 | |
2995 // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/" | |
2996 const AdjustOffsetCase idn_hostname_cases_2[] = { | |
2997 {7, 7}, | |
2998 {9, 9}, | |
2999 {11, 11}, | |
3000 {12, 12}, | |
3001 {13, base::string16::npos}, | |
3002 {23, base::string16::npos}, | |
3003 {24, 14}, | |
3004 {25, 15}, | |
3005 {26, base::string16::npos}, | |
3006 {32, base::string16::npos}, | |
3007 {41, 19}, | |
3008 {42, 20}, | |
3009 {45, 23}, | |
3010 {46, 24}, | |
3011 {47, base::string16::npos}, | |
3012 {base::string16::npos, base::string16::npos}, | |
3013 }; | |
3014 const size_t idn_hostname_offsets_2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, | |
3015 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | |
3016 kNpos, 14, 15, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | |
3017 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 19, 20, 21, 22, 23, 24}; | |
3018 CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/", | 2951 CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/", |
3019 "zh-CN", kFormatUrlOmitNothing, UnescapeRule::NORMAL, | 2952 "zh-CN", kFormatUrlOmitNothing, UnescapeRule::NORMAL, |
3020 idn_hostname_cases_2, arraysize(idn_hostname_cases_2), | |
3021 idn_hostname_offsets_2); | 2953 idn_hostname_offsets_2); |
3022 | 2954 |
3023 // "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB" | 2955 const size_t unescape_offsets[] = { |
3024 const AdjustOffsetCase unescape_cases[] = { | 2956 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
3025 {25, 25}, | 2957 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27, 28, 29, 30, kNpos, kNpos, kNpos, |
3026 {26, base::string16::npos}, | 2958 kNpos, kNpos, kNpos, kNpos, kNpos, 31, kNpos, kNpos, kNpos, kNpos, kNpos, |
3027 {27, base::string16::npos}, | 2959 kNpos, kNpos, kNpos, 32, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
3028 {28, 26}, | 2960 kNpos, 33, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos |
3029 {35, base::string16::npos}, | |
3030 {41, 31}, | |
3031 {59, 33}, | |
3032 {60, base::string16::npos}, | |
3033 {67, base::string16::npos}, | |
3034 {68, base::string16::npos}, | |
3035 }; | 2961 }; |
3036 const size_t unescape_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, | 2962 // Unescape to "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB". |
3037 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27, | |
3038 28, 29, 30, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 31, | |
3039 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 32, kNpos, kNpos, | |
3040 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 33, kNpos, kNpos, kNpos, kNpos, | |
3041 kNpos, kNpos, kNpos, kNpos}; | |
3042 CheckAdjustedOffsets( | 2963 CheckAdjustedOffsets( |
3043 "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", | 2964 "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", |
3044 "en", kFormatUrlOmitNothing, UnescapeRule::SPACES, unescape_cases, | 2965 "en", kFormatUrlOmitNothing, UnescapeRule::SPACES, unescape_offsets); |
3045 arraysize(unescape_cases), unescape_offsets); | |
3046 | 2966 |
3047 // "http://www.google.com/foo.html#\x30B0\x30B0z" | 2967 const size_t ref_offsets[] = { |
3048 const AdjustOffsetCase ref_cases[] = { | 2968 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
3049 {30, 30}, | 2969 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, kNpos, kNpos, 32, kNpos, kNpos, |
3050 {31, 31}, | 2970 33 |
3051 {32, base::string16::npos}, | |
3052 {34, 32}, | |
3053 {35, base::string16::npos}, | |
3054 {37, 33}, | |
3055 {38, base::string16::npos}, | |
3056 }; | 2971 }; |
3057 const size_t ref_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, | 2972 // Unescape to "http://www.google.com/foo.html#\x30B0\x30B0z". |
3058 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, | |
3059 kNpos, kNpos, 32, kNpos, kNpos, 33}; | |
3060 CheckAdjustedOffsets( | 2973 CheckAdjustedOffsets( |
3061 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en", | 2974 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en", |
3062 kFormatUrlOmitNothing, UnescapeRule::NORMAL, ref_cases, | 2975 kFormatUrlOmitNothing, UnescapeRule::NORMAL, ref_offsets); |
3063 arraysize(ref_cases), ref_offsets); | |
3064 | 2976 |
3065 const AdjustOffsetCase omit_http_cases[] = { | 2977 const size_t omit_http_offsets[] = { |
3066 {0, base::string16::npos}, | 2978 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
3067 {3, base::string16::npos}, | 2979 10, 11, 12, 13, 14 |
3068 {7, 0}, | |
3069 {8, 1}, | |
3070 }; | 2980 }; |
3071 const size_t omit_http_offsets[] = {kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | 2981 CheckAdjustedOffsets("http://www.google.com/", "en", kFormatUrlOmitHTTP, |
3072 kNpos, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; | 2982 UnescapeRule::NORMAL, omit_http_offsets); |
msw
2013/09/10 17:01:14
nit: extra space between args.
| |
3073 CheckAdjustedOffsets("http://www.google.com/", "en", | |
3074 kFormatUrlOmitHTTP, UnescapeRule::NORMAL, omit_http_cases, | |
3075 arraysize(omit_http_cases), omit_http_offsets); | |
3076 | 2983 |
3077 const AdjustOffsetCase omit_http_start_with_ftp_cases[] = { | 2984 const size_t omit_http_start_with_ftp_offsets[] = { |
3078 {0, 0}, | 2985 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 |
3079 {3, 3}, | |
3080 {8, 8}, | |
3081 }; | 2986 }; |
3082 const size_t omit_http_start_with_ftp_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, | |
3083 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; | |
3084 CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP, | 2987 CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP, |
3085 UnescapeRule::NORMAL, omit_http_start_with_ftp_cases, | 2988 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets); |
3086 arraysize(omit_http_start_with_ftp_cases), | |
3087 omit_http_start_with_ftp_offsets); | |
3088 | 2989 |
3089 const AdjustOffsetCase omit_all_cases[] = { | 2990 const size_t omit_all_offsets[] = { |
3090 {12, 0}, | 2991 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, |
3091 {13, 1}, | 2992 0, 1, 2, 3, 4, 5, 6, 7 |
3092 {0, base::string16::npos}, | |
3093 {3, base::string16::npos}, | |
3094 }; | 2993 }; |
3095 const size_t omit_all_offsets[] = {kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | |
3096 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, kNpos}; | |
3097 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, | 2994 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, |
3098 UnescapeRule::NORMAL, omit_all_cases, | 2995 UnescapeRule::NORMAL, omit_all_offsets); |
3099 arraysize(omit_all_cases), omit_all_offsets); | |
3100 } | 2996 } |
3101 | 2997 |
3102 TEST(NetUtilTest, SimplifyUrlForRequest) { | 2998 TEST(NetUtilTest, SimplifyUrlForRequest) { |
3103 struct { | 2999 struct { |
3104 const char* input_url; | 3000 const char* input_url; |
3105 const char* expected_simplified_url; | 3001 const char* expected_simplified_url; |
3106 } tests[] = { | 3002 } tests[] = { |
3107 { | 3003 { |
3108 // Reference section should be stripped. | 3004 // Reference section should be stripped. |
3109 "http://www.google.com:78/foobar?query=1#hash", | 3005 "http://www.google.com:78/foobar?query=1#hash", |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3572 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { | 3468 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { |
3573 const NonUniqueNameTestData& test_data = GetParam(); | 3469 const NonUniqueNameTestData& test_data = GetParam(); |
3574 | 3470 |
3575 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); | 3471 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); |
3576 } | 3472 } |
3577 | 3473 |
3578 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, | 3474 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, |
3579 testing::ValuesIn(kNonUniqueNameTestData)); | 3475 testing::ValuesIn(kNonUniqueNameTestData)); |
3580 | 3476 |
3581 } // namespace net | 3477 } // namespace net |
OLD | NEW |