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_to_filename_encoder.h" | 5 #include "net/tools/dump_cache/url_to_filename_encoder.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using base::StringPiece; | 15 using base::StringPiece; |
16 using std::string; | 16 using std::string; |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 #ifdef WIN32 | 20 #ifdef WIN32 |
21 char kDirSeparator = '\\'; | 21 char kDirSeparator = '\\'; |
22 char kOtherDirSeparator = '/'; | 22 char kOtherDirSeparator = '/'; |
23 #else | 23 #else |
24 char kDirSeparator = '/'; | 24 char kDirSeparator = '/'; |
25 char kOtherDirSeparator = '\\'; | 25 char kOtherDirSeparator = '\\'; |
26 #endif | 26 #endif |
27 | 27 |
28 class UrlToFilenameEncoderTest : public ::testing::Test { | 28 class UrlToFilenameEncoderTest : public ::testing::Test { |
29 protected: | 29 protected: |
30 UrlToFilenameEncoderTest() : escape_(1, UrlToFilenameEncoder::kEscapeChar), | 30 UrlToFilenameEncoderTest() |
31 dir_sep_(1, kDirSeparator) { | 31 : escape_(1, UrlToFilenameEncoder::kEscapeChar), |
32 } | 32 dir_sep_(1, kDirSeparator) {} |
33 | 33 |
34 void CheckSegmentLength(const StringPiece& escaped_word) { | 34 void CheckSegmentLength(const StringPiece& escaped_word) { |
35 std::vector<StringPiece> components; | 35 std::vector<StringPiece> components; |
36 Tokenize(escaped_word, StringPiece("/"), &components); | 36 Tokenize(escaped_word, StringPiece("/"), &components); |
37 for (size_t i = 0; i < components.size(); ++i) { | 37 for (size_t i = 0; i < components.size(); ++i) { |
38 EXPECT_GE(UrlToFilenameEncoder::kMaximumSubdirectoryLength, | 38 EXPECT_GE(UrlToFilenameEncoder::kMaximumSubdirectoryLength, |
39 components[i].size()); | 39 components[i].size()); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 void ValidateEscaped(unsigned char ch) { | 84 void ValidateEscaped(unsigned char ch) { |
85 // We always suffix the leaf with kEscapeChar, unless the leaf is empty. | 85 // We always suffix the leaf with kEscapeChar, unless the leaf is empty. |
86 char escaped[100]; | 86 char escaped[100]; |
87 const char escape = UrlToFilenameEncoder::kEscapeChar; | 87 const char escape = UrlToFilenameEncoder::kEscapeChar; |
88 base::snprintf(escaped, sizeof(escaped), "%c%02X%c", escape, ch, escape); | 88 base::snprintf(escaped, sizeof(escaped), "%c%02X%c", escape, ch, escape); |
89 Validate(string(1, ch), escaped); | 89 Validate(string(1, ch), escaped); |
90 } | 90 } |
91 | 91 |
92 void ValidateUrl(const string& url, const string& base_path, | 92 void ValidateUrl(const string& url, |
93 bool legacy_escape, const string& gold_filename) { | 93 const string& base_path, |
94 string encoded_filename = UrlToFilenameEncoder::Encode( | 94 bool legacy_escape, |
95 url, base_path, legacy_escape); | 95 const string& gold_filename) { |
| 96 string encoded_filename = |
| 97 UrlToFilenameEncoder::Encode(url, base_path, legacy_escape); |
96 EXPECT_EQ(gold_filename, encoded_filename); | 98 EXPECT_EQ(gold_filename, encoded_filename); |
97 if (!legacy_escape) { | 99 if (!legacy_escape) { |
98 CheckSegmentLength(encoded_filename); | 100 CheckSegmentLength(encoded_filename); |
99 CheckValidChars(encoded_filename, kOtherDirSeparator); | 101 CheckValidChars(encoded_filename, kOtherDirSeparator); |
100 string decoded_url; | 102 string decoded_url; |
101 UrlToFilenameEncoder::Decode(encoded_filename, kDirSeparator, | 103 UrlToFilenameEncoder::Decode( |
102 &decoded_url); | 104 encoded_filename, kDirSeparator, &decoded_url); |
103 if (url != decoded_url) { | 105 if (url != decoded_url) { |
104 EXPECT_EQ(url, "http://" + decoded_url); | 106 EXPECT_EQ(url, "http://" + decoded_url); |
105 } | 107 } |
106 } | 108 } |
107 } | 109 } |
108 | 110 |
109 void ValidateUrlOldNew(const string& url, const string& gold_old_filename, | 111 void ValidateUrlOldNew(const string& url, |
| 112 const string& gold_old_filename, |
110 const string& gold_new_filename) { | 113 const string& gold_new_filename) { |
111 ValidateUrl(url, std::string(), true, gold_old_filename); | 114 ValidateUrl(url, std::string(), true, gold_old_filename); |
112 ValidateUrl(url, std::string(), false, gold_new_filename); | 115 ValidateUrl(url, std::string(), false, gold_new_filename); |
113 } | 116 } |
114 | 117 |
115 void ValidateEncodeSame(const string& url1, const string& url2) { | 118 void ValidateEncodeSame(const string& url1, const string& url2) { |
116 string filename1 = UrlToFilenameEncoder::Encode(url1, std::string(), false); | 119 string filename1 = UrlToFilenameEncoder::Encode(url1, std::string(), false); |
117 string filename2 = UrlToFilenameEncoder::Encode(url2, std::string(), false); | 120 string filename2 = UrlToFilenameEncoder::Encode(url2, std::string(), false); |
118 EXPECT_EQ(filename1, filename2); | 121 EXPECT_EQ(filename1, filename2); |
119 } | 122 } |
120 | 123 |
121 string escape_; | 124 string escape_; |
122 string dir_sep_; | 125 string dir_sep_; |
123 }; | 126 }; |
124 | 127 |
125 TEST_F(UrlToFilenameEncoderTest, DoesNotEscape) { | 128 TEST_F(UrlToFilenameEncoderTest, DoesNotEscape) { |
126 ValidateNoChange(std::string()); | 129 ValidateNoChange(std::string()); |
127 ValidateNoChange("abcdefg"); | 130 ValidateNoChange("abcdefg"); |
128 ValidateNoChange("abcdefghijklmnopqrstuvwxyz"); | 131 ValidateNoChange("abcdefghijklmnopqrstuvwxyz"); |
129 ValidateNoChange("ZYXWVUT"); | 132 ValidateNoChange("ZYXWVUT"); |
130 ValidateNoChange("ZYXWVUTSRQPONMLKJIHGFEDCBA"); | 133 ValidateNoChange("ZYXWVUTSRQPONMLKJIHGFEDCBA"); |
131 ValidateNoChange("01234567689"); | 134 ValidateNoChange("01234567689"); |
132 ValidateNoChange("_.=+-"); | 135 ValidateNoChange("_.=+-"); |
133 ValidateNoChange("abcdefghijklmnopqrstuvwxyzZYXWVUTSRQPONMLKJIHGFEDCBA" | 136 ValidateNoChange( |
134 "01234567689_.=+-"); | 137 "abcdefghijklmnopqrstuvwxyzZYXWVUTSRQPONMLKJIHGFEDCBA" |
| 138 "01234567689_.=+-"); |
135 ValidateNoChange("index.html"); | 139 ValidateNoChange("index.html"); |
136 ValidateNoChange("/"); | 140 ValidateNoChange("/"); |
137 ValidateNoChange("/."); | 141 ValidateNoChange("/."); |
138 ValidateNoChange("."); | 142 ValidateNoChange("."); |
139 ValidateNoChange(".."); | 143 ValidateNoChange(".."); |
140 } | 144 } |
141 | 145 |
142 TEST_F(UrlToFilenameEncoderTest, Escapes) { | 146 TEST_F(UrlToFilenameEncoderTest, Escapes) { |
143 const string bad_chars = | 147 const string bad_chars = |
144 "<>:\"\\|?*" // Illegal on Windows | 148 "<>:\"\\|?*" // Illegal on Windows |
(...skipping 14 matching lines...) Expand all Loading... |
159 } | 163 } |
160 | 164 |
161 TEST_F(UrlToFilenameEncoderTest, DoesEscapeCorrectly) { | 165 TEST_F(UrlToFilenameEncoderTest, DoesEscapeCorrectly) { |
162 Validate("mysite.com&x", "mysite.com" + escape_ + "26x" + escape_); | 166 Validate("mysite.com&x", "mysite.com" + escape_ + "26x" + escape_); |
163 Validate("/./", "/" + escape_ + "./" + escape_); | 167 Validate("/./", "/" + escape_ + "./" + escape_); |
164 Validate("/../", "/" + escape_ + "../" + escape_); | 168 Validate("/../", "/" + escape_ + "../" + escape_); |
165 Validate("//", "/" + escape_ + "2F" + escape_); | 169 Validate("//", "/" + escape_ + "2F" + escape_); |
166 Validate("/./leaf", "/" + escape_ + "./leaf" + escape_); | 170 Validate("/./leaf", "/" + escape_ + "./leaf" + escape_); |
167 Validate("/../leaf", "/" + escape_ + "../leaf" + escape_); | 171 Validate("/../leaf", "/" + escape_ + "../leaf" + escape_); |
168 Validate("//leaf", "/" + escape_ + "2Fleaf" + escape_); | 172 Validate("//leaf", "/" + escape_ + "2Fleaf" + escape_); |
169 Validate("mysite/u?param1=x¶m2=y", | 173 Validate( |
170 "mysite/u" + escape_ + "3Fparam1=x" + escape_ + "26param2=y" + | 174 "mysite/u?param1=x¶m2=y", |
171 escape_); | 175 "mysite/u" + escape_ + "3Fparam1=x" + escape_ + "26param2=y" + escape_); |
172 Validate("search?q=dogs&go=&form=QBLH&qs=n", // from Latency Labs bing test. | 176 Validate("search?q=dogs&go=&form=QBLH&qs=n", // from Latency Labs bing test. |
173 "search" + escape_ + "3Fq=dogs" + escape_ + "26go=" + escape_ + | 177 "search" + escape_ + "3Fq=dogs" + escape_ + "26go=" + escape_ + |
174 "26form=QBLH" + escape_ + "26qs=n" + escape_); | 178 "26form=QBLH" + escape_ + "26qs=n" + escape_); |
175 Validate("~joebob/my_neeto-website+with_stuff.asp?id=138&content=true", | 179 Validate("~joebob/my_neeto-website+with_stuff.asp?id=138&content=true", |
176 "" + escape_ + "7Ejoebob/my_neeto-website+with_stuff.asp" + escape_ + | 180 "" + escape_ + "7Ejoebob/my_neeto-website+with_stuff.asp" + escape_ + |
177 "3Fid=138" + escape_ + "26content=true" + escape_); | 181 "3Fid=138" + escape_ + "26content=true" + escape_); |
178 } | 182 } |
179 | 183 |
180 TEST_F(UrlToFilenameEncoderTest, EncodeUrlCorrectly) { | 184 TEST_F(UrlToFilenameEncoderTest, EncodeUrlCorrectly) { |
181 ValidateUrlOldNew("http://www.google.com/index.html", | 185 ValidateUrlOldNew("http://www.google.com/index.html", |
182 "www.google.com" + dir_sep_ + "indexx2Ehtml", | 186 "www.google.com" + dir_sep_ + "indexx2Ehtml", |
183 "www.google.com" + dir_sep_ + "index.html" + escape_); | 187 "www.google.com" + dir_sep_ + "index.html" + escape_); |
184 ValidateUrlOldNew("http://www.google.com/x/search?hl=en&q=dogs&oq=", | 188 ValidateUrlOldNew("http://www.google.com/x/search?hl=en&q=dogs&oq=", |
185 "www.google.com" + dir_sep_ + "x" + dir_sep_ + | 189 "www.google.com" + dir_sep_ + "x" + dir_sep_ + |
186 "searchx3Fhlx3Denx26qx3Ddogsx26oqx3D", | 190 "searchx3Fhlx3Denx26qx3Ddogsx26oqx3D", |
187 | |
188 "www.google.com" + dir_sep_ + "x" + dir_sep_ + "search" + | 191 "www.google.com" + dir_sep_ + "x" + dir_sep_ + "search" + |
189 escape_ + "3Fhl=en" + escape_ + "26q=dogs" + escape_ + | 192 escape_ + "3Fhl=en" + escape_ + "26q=dogs" + escape_ + |
190 "26oq=" + escape_); | 193 "26oq=" + escape_); |
191 ValidateUrlOldNew("http://www.foo.com/a//", | 194 ValidateUrlOldNew( |
192 "www.foo.com" + dir_sep_ + "ax255Cx255Cindexx2Ehtml", | 195 "http://www.foo.com/a//", |
193 "www.foo.com" + dir_sep_ + "a" + dir_sep_ + escape_ + "2F" + | 196 "www.foo.com" + dir_sep_ + "ax255Cx255Cindexx2Ehtml", |
194 escape_); | 197 "www.foo.com" + dir_sep_ + "a" + dir_sep_ + escape_ + "2F" + escape_); |
195 | 198 |
196 // From bug: Double slash preserved. | 199 // From bug: Double slash preserved. |
197 ValidateUrl("http://www.foo.com/u?site=http://www.google.com/index.html", | 200 ValidateUrl("http://www.foo.com/u?site=http://www.google.com/index.html", |
198 std::string(), | 201 std::string(), |
199 false, | 202 false, |
200 "www.foo.com" + dir_sep_ + "u" + escape_ + "3Fsite=http" + | 203 "www.foo.com" + dir_sep_ + "u" + escape_ + "3Fsite=http" + |
201 escape_ + "3A" + dir_sep_ + escape_ + "2Fwww.google.com" + | 204 escape_ + "3A" + dir_sep_ + escape_ + "2Fwww.google.com" + |
202 dir_sep_ + "index.html" + escape_); | 205 dir_sep_ + "index.html" + escape_); |
203 ValidateUrlOldNew( | 206 ValidateUrlOldNew( |
204 "http://blogutils.net/olct/online.php?" | 207 "http://blogutils.net/olct/online.php?" |
205 "site=http://thelwordfanfics.blogspot.&interval=600", | 208 "site=http://thelwordfanfics.blogspot.&interval=600", |
206 | 209 "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + |
207 "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "onlinex2Ephpx3F" | 210 "onlinex2Ephpx3F" |
208 "sitex3Dhttpx3Ax255Cx255Cthelwordfanficsx2Eblogspotx2Ex26intervalx3D600", | 211 "sitex3Dhttpx3Ax255Cx255Cthelwordfanficsx2Eblogspotx2Ex26intervalx3D6" |
209 | 212 "00", |
210 "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "online.php" + escape_ + | 213 "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "online.php" + escape_ + |
211 "3Fsite=http" + escape_ + "3A" + dir_sep_ + escape_ + | 214 "3Fsite=http" + escape_ + "3A" + dir_sep_ + escape_ + |
212 "2Fthelwordfanfics.blogspot." + escape_ + "26interval=600" + escape_); | 215 "2Fthelwordfanfics.blogspot." + escape_ + "26interval=600" + escape_); |
213 } | 216 } |
214 | 217 |
215 // From bug: Escapes treated the same as normal char. | 218 // From bug: Escapes treated the same as normal char. |
216 TEST_F(UrlToFilenameEncoderTest, UnescapeUrlsBeforeEncode) { | 219 TEST_F(UrlToFilenameEncoderTest, UnescapeUrlsBeforeEncode) { |
217 for (int i = 0; i < 128; ++i) { | 220 for (int i = 0; i < 128; ++i) { |
218 string unescaped(1, static_cast<char>(i)); | 221 string unescaped(1, static_cast<char>(i)); |
219 string escaped = base::StringPrintf("%%%02X", i); | 222 string escaped = base::StringPrintf("%%%02X", i); |
220 ValidateEncodeSame(unescaped, escaped); | 223 ValidateEncodeSame(unescaped, escaped); |
221 } | 224 } |
222 | 225 |
223 ValidateEncodeSame( | 226 ValidateEncodeSame( |
224 "http://www.blogger.com/navbar.g?bName=God!&Mode=FOO&searchRoot" | 227 "http://www.blogger.com/navbar.g?bName=God!&Mode=FOO&searchRoot" |
225 "=http%3A%2F%2Fsurvivorscanthrive.blogspot.com%2Fsearch", | 228 "=http%3A%2F%2Fsurvivorscanthrive.blogspot.com%2Fsearch", |
226 | |
227 "http://www.blogger.com/navbar.g?bName=God%21&Mode=FOO&searchRoot" | 229 "http://www.blogger.com/navbar.g?bName=God%21&Mode=FOO&searchRoot" |
228 "=http%3A%2F%2Fsurvivorscanthrive.blogspot.com%2Fsearch"); | 230 "=http%3A%2F%2Fsurvivorscanthrive.blogspot.com%2Fsearch"); |
229 } | 231 } |
230 | 232 |
231 // From bug: Filename encoding is not prefix-free. | 233 // From bug: Filename encoding is not prefix-free. |
232 TEST_F(UrlToFilenameEncoderTest, EscapeSecondSlash) { | 234 TEST_F(UrlToFilenameEncoderTest, EscapeSecondSlash) { |
233 Validate("/", "/" + escape_); | 235 Validate("/", "/" + escape_); |
234 Validate("//", "/" + escape_ + "2F" + escape_); | 236 Validate("//", "/" + escape_ + "2F" + escape_); |
235 Validate("///", "/" + escape_ + "2F" + "/" + escape_); | 237 Validate("///", "/" + escape_ + "2F" + "/" + escape_); |
236 } | 238 } |
237 | 239 |
238 TEST_F(UrlToFilenameEncoderTest, LongTail) { | 240 TEST_F(UrlToFilenameEncoderTest, LongTail) { |
239 static char long_word[] = | 241 static char long_word[] = |
240 "~joebob/briggs/12345678901234567890123456789012345678901234567890" | 242 "~joebob/briggs/12345678901234567890123456789012345678901234567890" |
241 "1234567890123456789012345678901234567890123456789012345678901234567890" | 243 "1234567890123456789012345678901234567890123456789012345678901234567890" |
242 "1234567890123456789012345678901234567890123456789012345678901234567890" | 244 "1234567890123456789012345678901234567890123456789012345678901234567890" |
243 "1234567890123456789012345678901234567890123456789012345678901234567890" | 245 "1234567890123456789012345678901234567890123456789012345678901234567890" |
244 "1234567890123456789012345678901234567890123456789012345678901234567890" | 246 "1234567890123456789012345678901234567890123456789012345678901234567890" |
245 "1234567890123456789012345678901234567890123456789012345678901234567890"; | 247 "1234567890123456789012345678901234567890123456789012345678901234567890"; |
246 | 248 |
247 // the long lines in the string below are 64 characters, so we can see | 249 // the long lines in the string below are 64 characters, so we can see |
248 // the slashes every 128. | 250 // the slashes every 128. |
249 string gold_long_word = | 251 string gold_long_word = |
250 escape_ + "7Ejoebob/briggs/" | 252 escape_ + |
| 253 "7Ejoebob/briggs/" |
251 "1234567890123456789012345678901234567890123456789012345678901234" | 254 "1234567890123456789012345678901234567890123456789012345678901234" |
252 "56789012345678901234567890123456789012345678901234567890123456" + | 255 "56789012345678901234567890123456789012345678901234567890123456" + |
253 escape_ + "-/" | 256 escape_ + |
| 257 "-/" |
254 "7890123456789012345678901234567890123456789012345678901234567890" | 258 "7890123456789012345678901234567890123456789012345678901234567890" |
255 "12345678901234567890123456789012345678901234567890123456789012" + | 259 "12345678901234567890123456789012345678901234567890123456789012" + |
256 escape_ + "-/" | 260 escape_ + |
| 261 "-/" |
257 "3456789012345678901234567890123456789012345678901234567890123456" | 262 "3456789012345678901234567890123456789012345678901234567890123456" |
258 "78901234567890123456789012345678901234567890123456789012345678" + | 263 "78901234567890123456789012345678901234567890123456789012345678" + |
259 escape_ + "-/" | 264 escape_ + |
260 "9012345678901234567890" + escape_; | 265 "-/" |
| 266 "9012345678901234567890" + |
| 267 escape_; |
261 EXPECT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, | 268 EXPECT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, |
262 sizeof(long_word)); | 269 sizeof(long_word)); |
263 Validate(long_word, gold_long_word); | 270 Validate(long_word, gold_long_word); |
264 } | 271 } |
265 | 272 |
266 TEST_F(UrlToFilenameEncoderTest, LongTailQuestion) { | 273 TEST_F(UrlToFilenameEncoderTest, LongTailQuestion) { |
267 // Here the '?' in the last path segment expands to @3F, making | 274 // Here the '?' in the last path segment expands to @3F, making |
268 // it hit 128 chars before the input segment gets that big. | 275 // it hit 128 chars before the input segment gets that big. |
269 static char long_word[] = | 276 static char long_word[] = |
270 "~joebob/briggs/1234567?1234567?1234567?1234567?1234567?" | 277 "~joebob/briggs/1234567?1234567?1234567?1234567?1234567?" |
271 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?" | 278 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?" |
272 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?" | 279 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?" |
273 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?" | 280 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?" |
274 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?" | 281 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?" |
275 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?"; | 282 "1234567?1234567?1234567?1234567?1234567?1234567?1234567?"; |
276 | 283 |
277 // Notice that at the end of the third segment, we avoid splitting | 284 // Notice that at the end of the third segment, we avoid splitting |
278 // the (escape_ + "3F") that was generated from the "?", so that segment is | 285 // the (escape_ + "3F") that was generated from the "?", so that segment is |
279 // only 127 characters. | 286 // only 127 characters. |
280 string pattern = "1234567" + escape_ + "3F"; // 10 characters | 287 string pattern = "1234567" + escape_ + "3F"; // 10 characters |
281 string gold_long_word = | 288 string gold_long_word = |
282 escape_ + "7Ejoebob/briggs/" + | 289 escape_ + "7Ejoebob/briggs/" + pattern + pattern + pattern + pattern + |
283 pattern + pattern + pattern + pattern + pattern + pattern + "1234" | 290 pattern + pattern + |
284 "567" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern + | 291 "1234" |
285 "123456" + escape_ + "-/" | 292 "567" + |
286 "7" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern + | 293 escape_ + "3F" + pattern + pattern + pattern + pattern + pattern + |
| 294 "123456" + escape_ + |
| 295 "-/" |
| 296 "7" + |
| 297 escape_ + "3F" + pattern + pattern + pattern + pattern + pattern + |
287 pattern + pattern + pattern + pattern + pattern + pattern + pattern + | 298 pattern + pattern + pattern + pattern + pattern + pattern + pattern + |
288 "12" + | 299 "12" + escape_ + |
289 escape_ + "-/" | 300 "-/" |
290 "34567" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern | 301 "34567" + |
291 + "1234567" + escape_ + "3F" + pattern + pattern + pattern + pattern | 302 escape_ + "3F" + pattern + pattern + pattern + pattern + pattern + |
292 + pattern + "1234567" + | 303 "1234567" + escape_ + "3F" + pattern + pattern + pattern + pattern + |
293 escape_ + "-/" + | 304 pattern + "1234567" + escape_ + "-/" + escape_ + "3F" + pattern + |
294 escape_ + "3F" + pattern + pattern + escape_; | 305 pattern + escape_; |
295 EXPECT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, | 306 EXPECT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, |
296 sizeof(long_word)); | 307 sizeof(long_word)); |
297 Validate(long_word, gold_long_word); | 308 Validate(long_word, gold_long_word); |
298 } | 309 } |
299 | 310 |
300 TEST_F(UrlToFilenameEncoderTest, CornerCasesNearMaxLenNoEscape) { | 311 TEST_F(UrlToFilenameEncoderTest, CornerCasesNearMaxLenNoEscape) { |
301 // hit corner cases, +/- 4 characters from kMaxLen | 312 // hit corner cases, +/- 4 characters from kMaxLen |
302 for (int i = -4; i <= 4; ++i) { | 313 for (int i = -4; i <= 4; ++i) { |
303 string input; | 314 string input; |
304 input.append(i + UrlToFilenameEncoder::kMaximumSubdirectoryLength, 'x'); | 315 input.append(i + UrlToFilenameEncoder::kMaximumSubdirectoryLength, 'x'); |
305 ValidateAllSegmentsSmall(input); | 316 ValidateAllSegmentsSmall(input); |
306 } | 317 } |
307 } | 318 } |
308 | 319 |
309 TEST_F(UrlToFilenameEncoderTest, CornerCasesNearMaxLenWithEscape) { | 320 TEST_F(UrlToFilenameEncoderTest, CornerCasesNearMaxLenWithEscape) { |
310 // hit corner cases, +/- 4 characters from kMaxLen. This time we | 321 // hit corner cases, +/- 4 characters from kMaxLen. This time we |
311 // leave off the last 'x' and put in a '.', which ensures that we | 322 // leave off the last 'x' and put in a '.', which ensures that we |
312 // are truncating with '/' *after* the expansion. | 323 // are truncating with '/' *after* the expansion. |
313 for (int i = -4; i <= 4; ++i) { | 324 for (int i = -4; i <= 4; ++i) { |
314 string input; | 325 string input; |
315 input.append(i + UrlToFilenameEncoder::kMaximumSubdirectoryLength - 1, 'x'); | 326 input.append(i + UrlToFilenameEncoder::kMaximumSubdirectoryLength - 1, 'x'); |
316 input.append(1, '.'); // this will expand to 3 characters. | 327 input.append(1, '.'); // this will expand to 3 characters. |
317 ValidateAllSegmentsSmall(input); | 328 ValidateAllSegmentsSmall(input); |
318 } | 329 } |
319 } | 330 } |
320 | 331 |
321 TEST_F(UrlToFilenameEncoderTest, LeafBranchAlias) { | 332 TEST_F(UrlToFilenameEncoderTest, LeafBranchAlias) { |
322 Validate("/a/b/c", "/a/b/c" + escape_); // c is leaf file "c," | 333 Validate("/a/b/c", "/a/b/c" + escape_); // c is leaf file "c," |
323 Validate("/a/b/c/d", "/a/b/c/d" + escape_); // c is directory "c" | 334 Validate("/a/b/c/d", "/a/b/c/d" + escape_); // c is directory "c" |
324 Validate("/a/b/c/d/", "/a/b/c/d/" + escape_); | 335 Validate("/a/b/c/d/", "/a/b/c/d/" + escape_); |
325 } | 336 } |
326 | 337 |
327 | |
328 TEST_F(UrlToFilenameEncoderTest, BackslashSeparator) { | 338 TEST_F(UrlToFilenameEncoderTest, BackslashSeparator) { |
329 string long_word; | 339 string long_word; |
330 string escaped_word; | 340 string escaped_word; |
331 long_word.append(UrlToFilenameEncoder::kMaximumSubdirectoryLength + 1, 'x'); | 341 long_word.append(UrlToFilenameEncoder::kMaximumSubdirectoryLength + 1, 'x'); |
332 UrlToFilenameEncoder::EncodeSegment( | 342 UrlToFilenameEncoder::EncodeSegment( |
333 std::string(), long_word, '\\', &escaped_word); | 343 std::string(), long_word, '\\', &escaped_word); |
334 | 344 |
335 // check that one backslash, plus the escape ",-", and the ending , got added. | 345 // check that one backslash, plus the escape ",-", and the ending , got added. |
336 EXPECT_EQ(long_word.size() + 4, escaped_word.size()); | 346 EXPECT_EQ(long_word.size() + 4, escaped_word.size()); |
337 ASSERT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, | 347 ASSERT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, |
338 escaped_word.size()); | 348 escaped_word.size()); |
339 // Check that the backslash got inserted at the correct spot. | 349 // Check that the backslash got inserted at the correct spot. |
340 EXPECT_EQ('\\', escaped_word[ | 350 EXPECT_EQ('\\', |
341 UrlToFilenameEncoder::kMaximumSubdirectoryLength]); | 351 escaped_word[UrlToFilenameEncoder::kMaximumSubdirectoryLength]); |
342 } | 352 } |
343 | 353 |
344 } // namespace net | 354 } // namespace net |
345 | |
OLD | NEW |