Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(941)

Side by Side Diff: net/base/net_util_unittest.cc

Issue 23619016: Switch the offset conversion routines from... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« net/base/net_util.cc ('K') | « net/base/net_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 FormatUrlTypes format_types, 453 FormatUrlTypes format_types,
454 UnescapeRule::Type unescape_rules, 454 UnescapeRule::Type unescape_rules,
455 const AdjustOffsetCase* cases, 455 const AdjustOffsetCase* cases,
456 size_t num_cases, 456 size_t num_cases,
457 const size_t* all_offsets) { 457 const size_t* all_offsets) {
458 GURL url(url_string); 458 GURL url(url_string);
459 for (size_t i = 0; i < num_cases; ++i) { 459 for (size_t i = 0; i < num_cases; ++i) {
460 size_t offset = cases[i].input_offset; 460 size_t offset = cases[i].input_offset;
461 base::string16 formatted_url = FormatUrl(url, languages, format_types, 461 base::string16 formatted_url = FormatUrl(url, languages, format_types,
462 unescape_rules, NULL, NULL, &offset); 462 unescape_rules, NULL, NULL, &offset);
463 VerboseExpect(cases[i].output_offset, offset, url_string, i, formatted_url); 463 VerboseExpect(cases[i].output_offset, offset, url_string,
464 cases[i].input_offset, formatted_url);
464 } 465 }
465 466
466 size_t url_size = url_string.length(); 467 size_t url_length = url_string.length();
467 std::vector<size_t> offsets; 468 std::vector<size_t> offsets;
468 for (size_t i = 0; i < url_size + 1; ++i) 469 for (size_t i = 0; i <= url_length; ++i)
469 offsets.push_back(i); 470 offsets.push_back(i);
470 base::string16 formatted_url = FormatUrlWithOffsets(url, languages, 471 base::string16 formatted_url = FormatUrlWithOffsets(url, languages,
471 format_types, unescape_rules, NULL, NULL, &offsets); 472 format_types, unescape_rules, NULL, NULL, &offsets);
472 for (size_t i = 0; i < url_size; ++i) 473 for (size_t i = 0; i < url_length; ++i)
473 VerboseExpect(all_offsets[i], offsets[i], url_string, i, formatted_url); 474 VerboseExpect(all_offsets[i], offsets[i], url_string, i, formatted_url);
474 VerboseExpect(kNpos, offsets[url_size], url_string, url_size, formatted_url); 475 VerboseExpect(formatted_url.length(), offsets[url_length], url_string,
476 url_length, formatted_url);
475 } 477 }
476 478
477 // Helper to strignize an IP number (used to define expectations). 479 // Helper to strignize an IP number (used to define expectations).
478 std::string DumpIPNumber(const IPAddressNumber& v) { 480 std::string DumpIPNumber(const IPAddressNumber& v) {
479 std::string out; 481 std::string out;
480 for (size_t i = 0; i < v.size(); ++i) { 482 for (size_t i = 0; i < v.size(); ++i) {
481 if (i != 0) 483 if (i != 0)
482 out.append(","); 484 out.append(",");
483 out.append(base::IntToString(static_cast<int>(v[i]))); 485 out.append(base::IntToString(static_cast<int>(v[i])));
484 } 486 }
(...skipping 2395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 strchr(kUnescapedCharacters, static_cast<char>(test_char))) { 2882 strchr(kUnescapedCharacters, static_cast<char>(test_char))) {
2881 EXPECT_NE(url.spec(), GURL(formatted).spec()); 2883 EXPECT_NE(url.spec(), GURL(formatted).spec());
2882 } else { 2884 } else {
2883 EXPECT_EQ(url.spec(), GURL(formatted).spec()); 2885 EXPECT_EQ(url.spec(), GURL(formatted).spec());
2884 } 2886 }
2885 } 2887 }
2886 } 2888 }
2887 2889
2888 TEST(NetUtilTest, FormatUrlWithOffsets) { 2890 TEST(NetUtilTest, FormatUrlWithOffsets) {
2889 const AdjustOffsetCase null_cases[] = { 2891 const AdjustOffsetCase null_cases[] = {
2890 {0, base::string16::npos}, 2892 {0, 0},
2893 {1, base::string16::npos},
2891 }; 2894 };
2892 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing, 2895 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing,
2893 UnescapeRule::NORMAL, null_cases, arraysize(null_cases), NULL); 2896 UnescapeRule::NORMAL, null_cases, arraysize(null_cases),
2897 NULL);
2894 2898
2895 const AdjustOffsetCase basic_cases[] = { 2899 const AdjustOffsetCase basic_cases[] = {
2896 {0, 0}, 2900 {0, 0},
2897 {3, 3}, 2901 {3, 3},
2898 {5, 5}, 2902 {5, 5},
2899 {6, 6}, 2903 {6, 6},
2900 {13, 13}, 2904 {13, 13},
2901 {21, 21}, 2905 {21, 21},
2902 {22, 22}, 2906 {22, 22},
2903 {23, 23}, 2907 {23, 23},
2904 {25, 25}, 2908 {25, 25},
2905 {26, base::string16::npos}, 2909 {26, 26},
2910 {27, base::string16::npos},
2906 {500000, base::string16::npos}, 2911 {500000, base::string16::npos},
2907 {base::string16::npos, base::string16::npos}, 2912 {base::string16::npos, base::string16::npos},
2908 }; 2913 };
2909 const size_t basic_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 2914 const size_t basic_offsets[] = {
2910 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}; 2915 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
2916 21, 22, 23, 24, 25
2917 };
2911 CheckAdjustedOffsets("http://www.google.com/foo/", "en", 2918 CheckAdjustedOffsets("http://www.google.com/foo/", "en",
2912 kFormatUrlOmitNothing, UnescapeRule::NORMAL, basic_cases, 2919 kFormatUrlOmitNothing, UnescapeRule::NORMAL, basic_cases,
2913 arraysize(basic_cases), basic_offsets); 2920 arraysize(basic_cases), basic_offsets);
2914 2921
2915 const AdjustOffsetCase omit_auth_cases_1[] = { 2922 const AdjustOffsetCase omit_auth_cases_1[] = {
2916 {6, 6}, 2923 {6, 6},
2917 {7, base::string16::npos}, 2924 {7, 7},
2918 {8, base::string16::npos}, 2925 {8, base::string16::npos},
2919 {10, base::string16::npos}, 2926 {10, base::string16::npos},
2920 {12, base::string16::npos}, 2927 {12, base::string16::npos},
2921 {14, base::string16::npos}, 2928 {14, base::string16::npos},
2922 {15, 7}, 2929 {15, 7},
2923 {25, 17}, 2930 {25, 17},
2924 }; 2931 };
2925 const size_t omit_auth_offsets_1[] = {0, 1, 2, 3, 4, 5, 6, kNpos, kNpos, 2932 const size_t omit_auth_offsets_1[] = {
2926 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14, 15, 2933 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7,
2927 16, 17, 18, 19, 20, 21}; 2934 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
2935 };
2928 CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en", 2936 CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en",
2929 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, omit_auth_cases_1, 2937 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
2930 arraysize(omit_auth_cases_1), omit_auth_offsets_1); 2938 omit_auth_cases_1, arraysize(omit_auth_cases_1),
2939 omit_auth_offsets_1);
2931 2940
2932 const AdjustOffsetCase omit_auth_cases_2[] = { 2941 const AdjustOffsetCase omit_auth_cases_2[] = {
2933 {9, base::string16::npos}, 2942 {9, base::string16::npos},
2934 {11, 7}, 2943 {11, 7},
2935 }; 2944 };
2936 const size_t omit_auth_offsets_2[] = {0, 1, 2, 3, 4, 5, 6, kNpos, kNpos, 2945 const size_t omit_auth_offsets_2[] = {
2937 kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; 2946 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14,
2947 15, 16, 17, 18, 19, 20, 21
2948 };
2938 CheckAdjustedOffsets("http://foo@www.google.com/", "en", 2949 CheckAdjustedOffsets("http://foo@www.google.com/", "en",
2939 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, omit_auth_cases_2, 2950 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
2940 arraysize(omit_auth_cases_2), omit_auth_offsets_2); 2951 omit_auth_cases_2, arraysize(omit_auth_cases_2),
2952 omit_auth_offsets_2);
2941 2953
2942 // "http://foo\x30B0:\x30B0bar@www.google.com"
2943 const AdjustOffsetCase dont_omit_auth_cases[] = { 2954 const AdjustOffsetCase dont_omit_auth_cases[] = {
2944 {0, 0}, 2955 {0, 0},
2945 /*{3, base::string16::npos}, 2956 {11, base::string16::npos},
2946 {7, 0}, 2957 {19, 11},
2947 {11, 4}, 2958 {20, 12},
2948 {12, base::string16::npos}, 2959 {21, base::string16::npos},
2949 {20, 5}, 2960 {29, 13},
2950 {24, 9},*/ 2961 {33, 17},
2951 }; 2962 };
2952 const size_t dont_omit_auth_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2963 const size_t dont_omit_auth_offsets[] = {
2953 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 11, 12, kNpos, 2964 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
2954 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 13, 14, 15, 16, 17, 18, 2965 kNpos, kNpos, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
2955 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; 2966 kNpos, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
2967 30, 31
2968 };
2969 // Unescape to "http://foo\x30B0:\x30B0bar@www.google.com".
2956 CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en", 2970 CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en",
2957 kFormatUrlOmitNothing, UnescapeRule::NORMAL, dont_omit_auth_cases, 2971 kFormatUrlOmitNothing, UnescapeRule::NORMAL,
2958 arraysize(dont_omit_auth_cases), dont_omit_auth_offsets); 2972 dont_omit_auth_cases, arraysize(dont_omit_auth_cases),
2973 dont_omit_auth_offsets);
2959 2974
2960 const AdjustOffsetCase view_source_cases[] = { 2975 const AdjustOffsetCase view_source_cases[] = {
2961 {0, 0}, 2976 {0, 0},
2962 {3, 3}, 2977 {3, 3},
2963 {11, 11}, 2978 {11, 11},
2964 {12, 12}, 2979 {12, 12},
2965 {13, 13}, 2980 {13, 13},
2966 {18, 18}, 2981 {18, 18},
2967 {19, base::string16::npos}, 2982 {19, 19},
2968 {20, base::string16::npos}, 2983 {20, base::string16::npos},
2969 {23, 19}, 2984 {23, 19},
2970 {26, 22}, 2985 {26, 22},
2971 {base::string16::npos, base::string16::npos}, 2986 {base::string16::npos, base::string16::npos},
2972 }; 2987 };
2973 const size_t view_source_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 2988 const size_t view_source_offsets[] = {
2974 12, 13, 14, 15, 16, 17, 18, kNpos, kNpos, kNpos, kNpos, 19, 20, 21, 22, 2989 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, kNpos,
2975 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33}; 2990 kNpos, kNpos, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33
2991 };
2976 CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en", 2992 CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en",
2977 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, view_source_cases, 2993 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
2978 arraysize(view_source_cases), view_source_offsets); 2994 view_source_cases, arraysize(view_source_cases),
2995 view_source_offsets);
2979 2996
2980 // "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/"
2981 const AdjustOffsetCase idn_hostname_cases_1[] = { 2997 const AdjustOffsetCase idn_hostname_cases_1[] = {
2982 {8, base::string16::npos}, 2998 {8, base::string16::npos},
2983 {16, base::string16::npos}, 2999 {16, base::string16::npos},
2984 {24, base::string16::npos}, 3000 {24, base::string16::npos},
2985 {25, 12}, 3001 {25, 12},
2986 {30, 17}, 3002 {30, 17},
2987 }; 3003 };
2988 const size_t idn_hostname_offsets_1[] = {0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, 3004 const size_t idn_hostname_offsets_1[] = {
2989 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 3005 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
2990 kNpos, kNpos, kNpos, kNpos, kNpos, 12, 13, 14, 15, 16, 17, 18, 19}; 3006 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12,
3007 13, 14, 15, 16, 17, 18, 19
3008 };
3009 // Convert punycode to "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/".
2991 CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja", 3010 CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja",
2992 kFormatUrlOmitNothing, UnescapeRule::NORMAL, idn_hostname_cases_1, 3011 kFormatUrlOmitNothing, UnescapeRule::NORMAL,
2993 arraysize(idn_hostname_cases_1), idn_hostname_offsets_1); 3012 idn_hostname_cases_1, arraysize(idn_hostname_cases_1),
3013 idn_hostname_offsets_1);
2994 3014
2995 // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/"
2996 const AdjustOffsetCase idn_hostname_cases_2[] = { 3015 const AdjustOffsetCase idn_hostname_cases_2[] = {
2997 {7, 7}, 3016 {7, 7},
2998 {9, 9}, 3017 {9, 9},
2999 {11, 11}, 3018 {11, 11},
3000 {12, 12}, 3019 {12, 12},
3001 {13, base::string16::npos}, 3020 {13, base::string16::npos},
3002 {23, base::string16::npos}, 3021 {23, base::string16::npos},
3003 {24, 14}, 3022 {24, 14},
3004 {25, 15}, 3023 {25, 15},
3005 {26, base::string16::npos}, 3024 {26, base::string16::npos},
3006 {32, base::string16::npos}, 3025 {32, base::string16::npos},
3007 {41, 19}, 3026 {41, 19},
3008 {42, 20}, 3027 {42, 20},
3009 {45, 23}, 3028 {45, 23},
3010 {46, 24}, 3029 {46, 24},
3011 {47, base::string16::npos}, 3030 {47, 25},
3012 {base::string16::npos, base::string16::npos}, 3031 {base::string16::npos, base::string16::npos},
3013 }; 3032 };
3014 const size_t idn_hostname_offsets_2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3033 const size_t idn_hostname_offsets_2[] = {
3015 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 3034 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos,
3016 kNpos, 14, 15, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 3035 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 14, 15, kNpos, kNpos, kNpos,
3017 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 19, 20, 21, 22, 23, 24}; 3036 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
3037 kNpos, 19, 20, 21, 22, 23, 24
3038 };
3039 // Convert punycode to
3040 // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/".
3018 CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/", 3041 CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/",
3019 "zh-CN", kFormatUrlOmitNothing, UnescapeRule::NORMAL, 3042 "zh-CN", kFormatUrlOmitNothing, UnescapeRule::NORMAL,
3020 idn_hostname_cases_2, arraysize(idn_hostname_cases_2), 3043 idn_hostname_cases_2, arraysize(idn_hostname_cases_2),
3021 idn_hostname_offsets_2); 3044 idn_hostname_offsets_2);
3022 3045
3023 // "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB"
3024 const AdjustOffsetCase unescape_cases[] = { 3046 const AdjustOffsetCase unescape_cases[] = {
3025 {25, 25}, 3047 {25, 25},
3026 {26, base::string16::npos}, 3048 {26, base::string16::npos},
3027 {27, base::string16::npos}, 3049 {27, base::string16::npos},
3028 {28, 26}, 3050 {28, 26},
3029 {35, base::string16::npos}, 3051 {35, base::string16::npos},
3030 {41, 31}, 3052 {41, 31},
3031 {59, 33}, 3053 {59, 33},
3032 {60, base::string16::npos}, 3054 {60, base::string16::npos},
3033 {67, base::string16::npos}, 3055 {67, base::string16::npos},
3034 {68, base::string16::npos}, 3056 {68, 34},
3035 }; 3057 };
3036 const size_t unescape_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 3058 const size_t unescape_offsets[] = {
3037 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27, 3059 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
3038 28, 29, 30, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 31, 3060 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27, 28, 29, 30, kNpos, kNpos, kNpos,
3039 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 32, kNpos, kNpos, 3061 kNpos, kNpos, kNpos, kNpos, kNpos, 31, kNpos, kNpos, kNpos, kNpos, kNpos,
3040 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 33, kNpos, kNpos, kNpos, kNpos, 3062 kNpos, kNpos, kNpos, 32, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
3041 kNpos, kNpos, kNpos, kNpos}; 3063 kNpos, 33, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos
3064 };
3065 // Unescape to "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB".
3042 CheckAdjustedOffsets( 3066 CheckAdjustedOffsets(
3043 "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 3067 "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, 3068 "en", kFormatUrlOmitNothing, UnescapeRule::SPACES, unescape_cases,
3045 arraysize(unescape_cases), unescape_offsets); 3069 arraysize(unescape_cases), unescape_offsets);
3046 3070
3047 // "http://www.google.com/foo.html#\x30B0\x30B0z"
3048 const AdjustOffsetCase ref_cases[] = { 3071 const AdjustOffsetCase ref_cases[] = {
3049 {30, 30}, 3072 {30, 30},
3050 {31, 31}, 3073 {31, 31},
3051 {32, base::string16::npos}, 3074 {32, base::string16::npos},
3052 {34, 32}, 3075 {34, 32},
3053 {35, base::string16::npos}, 3076 {35, base::string16::npos},
3054 {37, 33}, 3077 {37, 33},
3055 {38, base::string16::npos}, 3078 {38, 34},
3056 }; 3079 };
3057 const size_t ref_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 3080 const size_t ref_offsets[] = {
3058 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 3081 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
3059 kNpos, kNpos, 32, kNpos, kNpos, 33}; 3082 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, kNpos, kNpos, 32, kNpos, kNpos,
3083 33
3084 };
3085 // Unescape to "http://www.google.com/foo.html#\x30B0\x30B0z".
3060 CheckAdjustedOffsets( 3086 CheckAdjustedOffsets(
3061 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en", 3087 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en",
3062 kFormatUrlOmitNothing, UnescapeRule::NORMAL, ref_cases, 3088 kFormatUrlOmitNothing, UnescapeRule::NORMAL, ref_cases,
3063 arraysize(ref_cases), ref_offsets); 3089 arraysize(ref_cases), ref_offsets);
3064 3090
3065 const AdjustOffsetCase omit_http_cases[] = { 3091 const AdjustOffsetCase omit_http_cases[] = {
3066 {0, base::string16::npos}, 3092 {0, 0},
3067 {3, base::string16::npos}, 3093 {3, base::string16::npos},
3068 {7, 0}, 3094 {7, 0},
3069 {8, 1}, 3095 {8, 1},
3070 }; 3096 };
3071 const size_t omit_http_offsets[] = {kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 3097 const size_t omit_http_offsets[] = {
3072 kNpos, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; 3098 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
3073 CheckAdjustedOffsets("http://www.google.com/", "en", 3099 10, 11, 12, 13, 14
3074 kFormatUrlOmitHTTP, UnescapeRule::NORMAL, omit_http_cases, 3100 };
3075 arraysize(omit_http_cases), omit_http_offsets); 3101 CheckAdjustedOffsets("http://www.google.com/", "en", kFormatUrlOmitHTTP,
3102 UnescapeRule::NORMAL, omit_http_cases,
3103 arraysize(omit_http_cases), omit_http_offsets);
3076 3104
3077 const AdjustOffsetCase omit_http_start_with_ftp_cases[] = { 3105 const AdjustOffsetCase omit_http_start_with_ftp_cases[] = {
3078 {0, 0}, 3106 {0, 0},
3079 {3, 3}, 3107 {3, 3},
3080 {8, 8}, 3108 {8, 8},
3081 }; 3109 };
3082 const size_t omit_http_start_with_ftp_offsets[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 3110 const size_t omit_http_start_with_ftp_offsets[] = {
3083 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; 3111 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
3112 };
3084 CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP, 3113 CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP,
3085 UnescapeRule::NORMAL, omit_http_start_with_ftp_cases, 3114 UnescapeRule::NORMAL, omit_http_start_with_ftp_cases,
3086 arraysize(omit_http_start_with_ftp_cases), 3115 arraysize(omit_http_start_with_ftp_cases),
3087 omit_http_start_with_ftp_offsets); 3116 omit_http_start_with_ftp_offsets);
3088 3117
3089 const AdjustOffsetCase omit_all_cases[] = { 3118 const AdjustOffsetCase omit_all_cases[] = {
3119 {0, 0},
3120 {3, base::string16::npos},
3090 {12, 0}, 3121 {12, 0},
3091 {13, 1}, 3122 {13, 1},
3092 {0, base::string16::npos},
3093 {3, base::string16::npos},
3094 }; 3123 };
3095 const size_t omit_all_offsets[] = {kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 3124 const size_t omit_all_offsets[] = {
3096 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, kNpos}; 3125 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
3126 0, 1, 2, 3, 4, 5, 6, 7
3127 };
3097 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, 3128 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll,
3098 UnescapeRule::NORMAL, omit_all_cases, 3129 UnescapeRule::NORMAL, omit_all_cases,
3099 arraysize(omit_all_cases), omit_all_offsets); 3130 arraysize(omit_all_cases), omit_all_offsets);
3100 } 3131 }
3101 3132
3102 TEST(NetUtilTest, SimplifyUrlForRequest) { 3133 TEST(NetUtilTest, SimplifyUrlForRequest) {
3103 struct { 3134 struct {
3104 const char* input_url; 3135 const char* input_url;
3105 const char* expected_simplified_url; 3136 const char* expected_simplified_url;
3106 } tests[] = { 3137 } tests[] = {
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
3572 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { 3603 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) {
3573 const NonUniqueNameTestData& test_data = GetParam(); 3604 const NonUniqueNameTestData& test_data = GetParam();
3574 3605
3575 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); 3606 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname));
3576 } 3607 }
3577 3608
3578 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, 3609 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest,
3579 testing::ValuesIn(kNonUniqueNameTestData)); 3610 testing::ValuesIn(kNonUniqueNameTestData));
3580 3611
3581 } // namespace net 3612 } // namespace net
OLDNEW
« net/base/net_util.cc ('K') | « net/base/net_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698