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

Side by Side Diff: net/tools/dump_cache/url_to_filename_encoder_unittest.cc

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 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
« no previous file with comments | « net/test/base_test_server.cc ('k') | net/tools/fetch/fetch_server.cc » ('j') | 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) 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/string_piece.h" 10 #include "base/string_piece.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 char c = escaped_word[i]; 50 char c = escaped_word[i];
51 EXPECT_EQ(string::npos, kInvalidChars.find(c)); 51 EXPECT_EQ(string::npos, kInvalidChars.find(c));
52 EXPECT_NE(invalid_slash, c); 52 EXPECT_NE(invalid_slash, c);
53 EXPECT_NE('\0', c); // only invalid character in Posix 53 EXPECT_NE('\0', c); // only invalid character in Posix
54 EXPECT_GT(0x7E, c); // only English printable characters 54 EXPECT_GT(0x7E, c); // only English printable characters
55 } 55 }
56 } 56 }
57 57
58 void Validate(const string& in_word, const string& gold_word) { 58 void Validate(const string& in_word, const string& gold_word) {
59 string escaped_word, url; 59 string escaped_word, url;
60 UrlToFilenameEncoder::EncodeSegment("", in_word, '/', &escaped_word); 60 UrlToFilenameEncoder::EncodeSegment(
61 std::string(), in_word, '/', &escaped_word);
61 EXPECT_EQ(gold_word, escaped_word); 62 EXPECT_EQ(gold_word, escaped_word);
62 CheckSegmentLength(escaped_word); 63 CheckSegmentLength(escaped_word);
63 CheckValidChars(escaped_word, '\\'); 64 CheckValidChars(escaped_word, '\\');
64 UrlToFilenameEncoder::Decode(escaped_word, '/', &url); 65 UrlToFilenameEncoder::Decode(escaped_word, '/', &url);
65 EXPECT_EQ(in_word, url); 66 EXPECT_EQ(in_word, url);
66 } 67 }
67 68
68 void ValidateAllSegmentsSmall(const string& in_word) { 69 void ValidateAllSegmentsSmall(const string& in_word) {
69 string escaped_word, url; 70 string escaped_word, url;
70 UrlToFilenameEncoder::EncodeSegment("", in_word, '/', &escaped_word); 71 UrlToFilenameEncoder::EncodeSegment(
72 std::string(), in_word, '/', &escaped_word);
71 CheckSegmentLength(escaped_word); 73 CheckSegmentLength(escaped_word);
72 CheckValidChars(escaped_word, '\\'); 74 CheckValidChars(escaped_word, '\\');
73 UrlToFilenameEncoder::Decode(escaped_word, '/', &url); 75 UrlToFilenameEncoder::Decode(escaped_word, '/', &url);
74 EXPECT_EQ(in_word, url); 76 EXPECT_EQ(in_word, url);
75 } 77 }
76 78
77 void ValidateNoChange(const string& word) { 79 void ValidateNoChange(const string& word) {
78 // We always suffix the leaf with kEscapeChar, unless the leaf is empty. 80 // We always suffix the leaf with kEscapeChar, unless the leaf is empty.
79 Validate(word, word + escape_); 81 Validate(word, word + escape_);
80 } 82 }
(...skipping 18 matching lines...) Expand all
99 UrlToFilenameEncoder::Decode(encoded_filename, kDirSeparator, 101 UrlToFilenameEncoder::Decode(encoded_filename, kDirSeparator,
100 &decoded_url); 102 &decoded_url);
101 if (url != decoded_url) { 103 if (url != decoded_url) {
102 EXPECT_EQ(url, "http://" + decoded_url); 104 EXPECT_EQ(url, "http://" + decoded_url);
103 } 105 }
104 } 106 }
105 } 107 }
106 108
107 void ValidateUrlOldNew(const string& url, const string& gold_old_filename, 109 void ValidateUrlOldNew(const string& url, const string& gold_old_filename,
108 const string& gold_new_filename) { 110 const string& gold_new_filename) {
109 ValidateUrl(url, "", true, gold_old_filename); 111 ValidateUrl(url, std::string(), true, gold_old_filename);
110 ValidateUrl(url, "", false, gold_new_filename); 112 ValidateUrl(url, std::string(), false, gold_new_filename);
111 } 113 }
112 114
113 void ValidateEncodeSame(const string& url1, const string& url2) { 115 void ValidateEncodeSame(const string& url1, const string& url2) {
114 string filename1 = UrlToFilenameEncoder::Encode(url1, "", false); 116 string filename1 = UrlToFilenameEncoder::Encode(url1, std::string(), false);
115 string filename2 = UrlToFilenameEncoder::Encode(url2, "", false); 117 string filename2 = UrlToFilenameEncoder::Encode(url2, std::string(), false);
116 EXPECT_EQ(filename1, filename2); 118 EXPECT_EQ(filename1, filename2);
117 } 119 }
118 120
119 string escape_; 121 string escape_;
120 string dir_sep_; 122 string dir_sep_;
121 }; 123 };
122 124
123 TEST_F(UrlToFilenameEncoderTest, DoesNotEscape) { 125 TEST_F(UrlToFilenameEncoderTest, DoesNotEscape) {
124 ValidateNoChange(""); 126 ValidateNoChange(std::string());
125 ValidateNoChange("abcdefg"); 127 ValidateNoChange("abcdefg");
126 ValidateNoChange("abcdefghijklmnopqrstuvwxyz"); 128 ValidateNoChange("abcdefghijklmnopqrstuvwxyz");
127 ValidateNoChange("ZYXWVUT"); 129 ValidateNoChange("ZYXWVUT");
128 ValidateNoChange("ZYXWVUTSRQPONMLKJIHGFEDCBA"); 130 ValidateNoChange("ZYXWVUTSRQPONMLKJIHGFEDCBA");
129 ValidateNoChange("01234567689"); 131 ValidateNoChange("01234567689");
130 ValidateNoChange("_.=+-"); 132 ValidateNoChange("_.=+-");
131 ValidateNoChange("abcdefghijklmnopqrstuvwxyzZYXWVUTSRQPONMLKJIHGFEDCBA" 133 ValidateNoChange("abcdefghijklmnopqrstuvwxyzZYXWVUTSRQPONMLKJIHGFEDCBA"
132 "01234567689_.=+-"); 134 "01234567689_.=+-");
133 ValidateNoChange("index.html"); 135 ValidateNoChange("index.html");
134 ValidateNoChange("/"); 136 ValidateNoChange("/");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 "www.google.com" + dir_sep_ + "x" + dir_sep_ + "search" + 188 "www.google.com" + dir_sep_ + "x" + dir_sep_ + "search" +
187 escape_ + "3Fhl=en" + escape_ + "26q=dogs" + escape_ + 189 escape_ + "3Fhl=en" + escape_ + "26q=dogs" + escape_ +
188 "26oq=" + escape_); 190 "26oq=" + escape_);
189 ValidateUrlOldNew("http://www.foo.com/a//", 191 ValidateUrlOldNew("http://www.foo.com/a//",
190 "www.foo.com" + dir_sep_ + "ax255Cx255Cindexx2Ehtml", 192 "www.foo.com" + dir_sep_ + "ax255Cx255Cindexx2Ehtml",
191 "www.foo.com" + dir_sep_ + "a" + dir_sep_ + escape_ + "2F" + 193 "www.foo.com" + dir_sep_ + "a" + dir_sep_ + escape_ + "2F" +
192 escape_); 194 escape_);
193 195
194 // From bug: Double slash preserved. 196 // From bug: Double slash preserved.
195 ValidateUrl("http://www.foo.com/u?site=http://www.google.com/index.html", 197 ValidateUrl("http://www.foo.com/u?site=http://www.google.com/index.html",
196 "", false, 198 std::string(),
199 false,
197 "www.foo.com" + dir_sep_ + "u" + escape_ + "3Fsite=http" + 200 "www.foo.com" + dir_sep_ + "u" + escape_ + "3Fsite=http" +
198 escape_ + "3A" + dir_sep_ + escape_ + "2Fwww.google.com" + 201 escape_ + "3A" + dir_sep_ + escape_ + "2Fwww.google.com" +
199 dir_sep_ + "index.html" + escape_); 202 dir_sep_ + "index.html" + escape_);
200 ValidateUrlOldNew( 203 ValidateUrlOldNew(
201 "http://blogutils.net/olct/online.php?" 204 "http://blogutils.net/olct/online.php?"
202 "site=http://thelwordfanfics.blogspot.&interval=600", 205 "site=http://thelwordfanfics.blogspot.&interval=600",
203 206
204 "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "onlinex2Ephpx3F" 207 "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "onlinex2Ephpx3F"
205 "sitex3Dhttpx3Ax255Cx255Cthelwordfanficsx2Eblogspotx2Ex26intervalx3D600", 208 "sitex3Dhttpx3Ax255Cx255Cthelwordfanficsx2Eblogspotx2Ex26intervalx3D600",
206 209
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 Validate("/a/b/c", "/a/b/c" + escape_); // c is leaf file "c," 322 Validate("/a/b/c", "/a/b/c" + escape_); // c is leaf file "c,"
320 Validate("/a/b/c/d", "/a/b/c/d" + escape_); // c is directory "c" 323 Validate("/a/b/c/d", "/a/b/c/d" + escape_); // c is directory "c"
321 Validate("/a/b/c/d/", "/a/b/c/d/" + escape_); 324 Validate("/a/b/c/d/", "/a/b/c/d/" + escape_);
322 } 325 }
323 326
324 327
325 TEST_F(UrlToFilenameEncoderTest, BackslashSeparator) { 328 TEST_F(UrlToFilenameEncoderTest, BackslashSeparator) {
326 string long_word; 329 string long_word;
327 string escaped_word; 330 string escaped_word;
328 long_word.append(UrlToFilenameEncoder::kMaximumSubdirectoryLength + 1, 'x'); 331 long_word.append(UrlToFilenameEncoder::kMaximumSubdirectoryLength + 1, 'x');
329 UrlToFilenameEncoder::EncodeSegment("", long_word, '\\', &escaped_word); 332 UrlToFilenameEncoder::EncodeSegment(
333 std::string(), long_word, '\\', &escaped_word);
330 334
331 // check that one backslash, plus the escape ",-", and the ending , got added. 335 // check that one backslash, plus the escape ",-", and the ending , got added.
332 EXPECT_EQ(long_word.size() + 4, escaped_word.size()); 336 EXPECT_EQ(long_word.size() + 4, escaped_word.size());
333 ASSERT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, 337 ASSERT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength,
334 escaped_word.size()); 338 escaped_word.size());
335 // Check that the backslash got inserted at the correct spot. 339 // Check that the backslash got inserted at the correct spot.
336 EXPECT_EQ('\\', escaped_word[ 340 EXPECT_EQ('\\', escaped_word[
337 UrlToFilenameEncoder::kMaximumSubdirectoryLength]); 341 UrlToFilenameEncoder::kMaximumSubdirectoryLength]);
338 } 342 }
339 343
340 } // namespace net 344 } // namespace net
341 345
OLDNEW
« no previous file with comments | « net/test/base_test_server.cc ('k') | net/tools/fetch/fetch_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698