| Index: net/tools/dump_cache/url_to_filename_encoder_unittest.cc
|
| diff --git a/net/tools/dump_cache/url_to_filename_encoder_unittest.cc b/net/tools/dump_cache/url_to_filename_encoder_unittest.cc
|
| index a1a96651da3986eaea6c4ff4d77d575946e7d80f..3c4159c0bb7f694874a4426d376a0ec9dea38829 100644
|
| --- a/net/tools/dump_cache/url_to_filename_encoder_unittest.cc
|
| +++ b/net/tools/dump_cache/url_to_filename_encoder_unittest.cc
|
| @@ -27,9 +27,9 @@ char kOtherDirSeparator = '\\';
|
|
|
| class UrlToFilenameEncoderTest : public ::testing::Test {
|
| protected:
|
| - UrlToFilenameEncoderTest() : escape_(1, UrlToFilenameEncoder::kEscapeChar),
|
| - dir_sep_(1, kDirSeparator) {
|
| - }
|
| + UrlToFilenameEncoderTest()
|
| + : escape_(1, UrlToFilenameEncoder::kEscapeChar),
|
| + dir_sep_(1, kDirSeparator) {}
|
|
|
| void CheckSegmentLength(const StringPiece& escaped_word) {
|
| std::vector<StringPiece> components;
|
| @@ -89,24 +89,27 @@ class UrlToFilenameEncoderTest : public ::testing::Test {
|
| Validate(string(1, ch), escaped);
|
| }
|
|
|
| - void ValidateUrl(const string& url, const string& base_path,
|
| - bool legacy_escape, const string& gold_filename) {
|
| - string encoded_filename = UrlToFilenameEncoder::Encode(
|
| - url, base_path, legacy_escape);
|
| + void ValidateUrl(const string& url,
|
| + const string& base_path,
|
| + bool legacy_escape,
|
| + const string& gold_filename) {
|
| + string encoded_filename =
|
| + UrlToFilenameEncoder::Encode(url, base_path, legacy_escape);
|
| EXPECT_EQ(gold_filename, encoded_filename);
|
| if (!legacy_escape) {
|
| CheckSegmentLength(encoded_filename);
|
| CheckValidChars(encoded_filename, kOtherDirSeparator);
|
| string decoded_url;
|
| - UrlToFilenameEncoder::Decode(encoded_filename, kDirSeparator,
|
| - &decoded_url);
|
| + UrlToFilenameEncoder::Decode(
|
| + encoded_filename, kDirSeparator, &decoded_url);
|
| if (url != decoded_url) {
|
| EXPECT_EQ(url, "http://" + decoded_url);
|
| }
|
| }
|
| }
|
|
|
| - void ValidateUrlOldNew(const string& url, const string& gold_old_filename,
|
| + void ValidateUrlOldNew(const string& url,
|
| + const string& gold_old_filename,
|
| const string& gold_new_filename) {
|
| ValidateUrl(url, std::string(), true, gold_old_filename);
|
| ValidateUrl(url, std::string(), false, gold_new_filename);
|
| @@ -130,8 +133,9 @@ TEST_F(UrlToFilenameEncoderTest, DoesNotEscape) {
|
| ValidateNoChange("ZYXWVUTSRQPONMLKJIHGFEDCBA");
|
| ValidateNoChange("01234567689");
|
| ValidateNoChange("_.=+-");
|
| - ValidateNoChange("abcdefghijklmnopqrstuvwxyzZYXWVUTSRQPONMLKJIHGFEDCBA"
|
| - "01234567689_.=+-");
|
| + ValidateNoChange(
|
| + "abcdefghijklmnopqrstuvwxyzZYXWVUTSRQPONMLKJIHGFEDCBA"
|
| + "01234567689_.=+-");
|
| ValidateNoChange("index.html");
|
| ValidateNoChange("/");
|
| ValidateNoChange("/.");
|
| @@ -166,15 +170,15 @@ TEST_F(UrlToFilenameEncoderTest, DoesEscapeCorrectly) {
|
| Validate("/./leaf", "/" + escape_ + "./leaf" + escape_);
|
| Validate("/../leaf", "/" + escape_ + "../leaf" + escape_);
|
| Validate("//leaf", "/" + escape_ + "2Fleaf" + escape_);
|
| - Validate("mysite/u?param1=x¶m2=y",
|
| - "mysite/u" + escape_ + "3Fparam1=x" + escape_ + "26param2=y" +
|
| - escape_);
|
| + Validate(
|
| + "mysite/u?param1=x¶m2=y",
|
| + "mysite/u" + escape_ + "3Fparam1=x" + escape_ + "26param2=y" + escape_);
|
| Validate("search?q=dogs&go=&form=QBLH&qs=n", // from Latency Labs bing test.
|
| "search" + escape_ + "3Fq=dogs" + escape_ + "26go=" + escape_ +
|
| - "26form=QBLH" + escape_ + "26qs=n" + escape_);
|
| + "26form=QBLH" + escape_ + "26qs=n" + escape_);
|
| Validate("~joebob/my_neeto-website+with_stuff.asp?id=138&content=true",
|
| "" + escape_ + "7Ejoebob/my_neeto-website+with_stuff.asp" + escape_ +
|
| - "3Fid=138" + escape_ + "26content=true" + escape_);
|
| + "3Fid=138" + escape_ + "26content=true" + escape_);
|
| }
|
|
|
| TEST_F(UrlToFilenameEncoderTest, EncodeUrlCorrectly) {
|
| @@ -183,33 +187,32 @@ TEST_F(UrlToFilenameEncoderTest, EncodeUrlCorrectly) {
|
| "www.google.com" + dir_sep_ + "index.html" + escape_);
|
| ValidateUrlOldNew("http://www.google.com/x/search?hl=en&q=dogs&oq=",
|
| "www.google.com" + dir_sep_ + "x" + dir_sep_ +
|
| - "searchx3Fhlx3Denx26qx3Ddogsx26oqx3D",
|
| -
|
| + "searchx3Fhlx3Denx26qx3Ddogsx26oqx3D",
|
| "www.google.com" + dir_sep_ + "x" + dir_sep_ + "search" +
|
| - escape_ + "3Fhl=en" + escape_ + "26q=dogs" + escape_ +
|
| - "26oq=" + escape_);
|
| - ValidateUrlOldNew("http://www.foo.com/a//",
|
| - "www.foo.com" + dir_sep_ + "ax255Cx255Cindexx2Ehtml",
|
| - "www.foo.com" + dir_sep_ + "a" + dir_sep_ + escape_ + "2F" +
|
| - escape_);
|
| + escape_ + "3Fhl=en" + escape_ + "26q=dogs" + escape_ +
|
| + "26oq=" + escape_);
|
| + ValidateUrlOldNew(
|
| + "http://www.foo.com/a//",
|
| + "www.foo.com" + dir_sep_ + "ax255Cx255Cindexx2Ehtml",
|
| + "www.foo.com" + dir_sep_ + "a" + dir_sep_ + escape_ + "2F" + escape_);
|
|
|
| // From bug: Double slash preserved.
|
| ValidateUrl("http://www.foo.com/u?site=http://www.google.com/index.html",
|
| std::string(),
|
| false,
|
| "www.foo.com" + dir_sep_ + "u" + escape_ + "3Fsite=http" +
|
| - escape_ + "3A" + dir_sep_ + escape_ + "2Fwww.google.com" +
|
| - dir_sep_ + "index.html" + escape_);
|
| + escape_ + "3A" + dir_sep_ + escape_ + "2Fwww.google.com" +
|
| + dir_sep_ + "index.html" + escape_);
|
| ValidateUrlOldNew(
|
| "http://blogutils.net/olct/online.php?"
|
| "site=http://thelwordfanfics.blogspot.&interval=600",
|
| -
|
| - "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "onlinex2Ephpx3F"
|
| - "sitex3Dhttpx3Ax255Cx255Cthelwordfanficsx2Eblogspotx2Ex26intervalx3D600",
|
| -
|
| + "blogutils.net" + dir_sep_ + "olct" + dir_sep_ +
|
| + "onlinex2Ephpx3F"
|
| + "sitex3Dhttpx3Ax255Cx255Cthelwordfanficsx2Eblogspotx2Ex26intervalx3D6"
|
| + "00",
|
| "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "online.php" + escape_ +
|
| - "3Fsite=http" + escape_ + "3A" + dir_sep_ + escape_ +
|
| - "2Fthelwordfanfics.blogspot." + escape_ + "26interval=600" + escape_);
|
| + "3Fsite=http" + escape_ + "3A" + dir_sep_ + escape_ +
|
| + "2Fthelwordfanfics.blogspot." + escape_ + "26interval=600" + escape_);
|
| }
|
|
|
| // From bug: Escapes treated the same as normal char.
|
| @@ -223,7 +226,6 @@ TEST_F(UrlToFilenameEncoderTest, UnescapeUrlsBeforeEncode) {
|
| ValidateEncodeSame(
|
| "http://www.blogger.com/navbar.g?bName=God!&Mode=FOO&searchRoot"
|
| "=http%3A%2F%2Fsurvivorscanthrive.blogspot.com%2Fsearch",
|
| -
|
| "http://www.blogger.com/navbar.g?bName=God%21&Mode=FOO&searchRoot"
|
| "=http%3A%2F%2Fsurvivorscanthrive.blogspot.com%2Fsearch");
|
| }
|
| @@ -247,17 +249,22 @@ TEST_F(UrlToFilenameEncoderTest, LongTail) {
|
| // the long lines in the string below are 64 characters, so we can see
|
| // the slashes every 128.
|
| string gold_long_word =
|
| - escape_ + "7Ejoebob/briggs/"
|
| + escape_ +
|
| + "7Ejoebob/briggs/"
|
| "1234567890123456789012345678901234567890123456789012345678901234"
|
| "56789012345678901234567890123456789012345678901234567890123456" +
|
| - escape_ + "-/"
|
| + escape_ +
|
| + "-/"
|
| "7890123456789012345678901234567890123456789012345678901234567890"
|
| "12345678901234567890123456789012345678901234567890123456789012" +
|
| - escape_ + "-/"
|
| + escape_ +
|
| + "-/"
|
| "3456789012345678901234567890123456789012345678901234567890123456"
|
| "78901234567890123456789012345678901234567890123456789012345678" +
|
| - escape_ + "-/"
|
| - "9012345678901234567890" + escape_;
|
| + escape_ +
|
| + "-/"
|
| + "9012345678901234567890" +
|
| + escape_;
|
| EXPECT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength,
|
| sizeof(long_word));
|
| Validate(long_word, gold_long_word);
|
| @@ -279,19 +286,23 @@ TEST_F(UrlToFilenameEncoderTest, LongTailQuestion) {
|
| // only 127 characters.
|
| string pattern = "1234567" + escape_ + "3F"; // 10 characters
|
| string gold_long_word =
|
| - escape_ + "7Ejoebob/briggs/" +
|
| - pattern + pattern + pattern + pattern + pattern + pattern + "1234"
|
| - "567" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
|
| - "123456" + escape_ + "-/"
|
| - "7" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
|
| + escape_ + "7Ejoebob/briggs/" + pattern + pattern + pattern + pattern +
|
| + pattern + pattern +
|
| + "1234"
|
| + "567" +
|
| + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
|
| + "123456" + escape_ +
|
| + "-/"
|
| + "7" +
|
| + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
|
| pattern + pattern + pattern + pattern + pattern + pattern + pattern +
|
| - "12" +
|
| - escape_ + "-/"
|
| - "34567" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern
|
| - + "1234567" + escape_ + "3F" + pattern + pattern + pattern + pattern
|
| - + pattern + "1234567" +
|
| - escape_ + "-/" +
|
| - escape_ + "3F" + pattern + pattern + escape_;
|
| + "12" + escape_ +
|
| + "-/"
|
| + "34567" +
|
| + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
|
| + "1234567" + escape_ + "3F" + pattern + pattern + pattern + pattern +
|
| + pattern + "1234567" + escape_ + "-/" + escape_ + "3F" + pattern +
|
| + pattern + escape_;
|
| EXPECT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength,
|
| sizeof(long_word));
|
| Validate(long_word, gold_long_word);
|
| @@ -319,12 +330,11 @@ TEST_F(UrlToFilenameEncoderTest, CornerCasesNearMaxLenWithEscape) {
|
| }
|
|
|
| TEST_F(UrlToFilenameEncoderTest, LeafBranchAlias) {
|
| - Validate("/a/b/c", "/a/b/c" + escape_); // c is leaf file "c,"
|
| - Validate("/a/b/c/d", "/a/b/c/d" + escape_); // c is directory "c"
|
| + Validate("/a/b/c", "/a/b/c" + escape_); // c is leaf file "c,"
|
| + Validate("/a/b/c/d", "/a/b/c/d" + escape_); // c is directory "c"
|
| Validate("/a/b/c/d/", "/a/b/c/d/" + escape_);
|
| }
|
|
|
| -
|
| TEST_F(UrlToFilenameEncoderTest, BackslashSeparator) {
|
| string long_word;
|
| string escaped_word;
|
| @@ -337,9 +347,8 @@ TEST_F(UrlToFilenameEncoderTest, BackslashSeparator) {
|
| ASSERT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength,
|
| escaped_word.size());
|
| // Check that the backslash got inserted at the correct spot.
|
| - EXPECT_EQ('\\', escaped_word[
|
| - UrlToFilenameEncoder::kMaximumSubdirectoryLength]);
|
| + EXPECT_EQ('\\',
|
| + escaped_word[UrlToFilenameEncoder::kMaximumSubdirectoryLength]);
|
| }
|
|
|
| } // namespace net
|
| -
|
|
|