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

Side by Side Diff: net/ftp/ftp_directory_listing_parser_vms_unittest.cc

Issue 6670085: FTP: Detect the character encoding only after the entire listing is received. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update histograms for SERVER_UNKNOWN Created 9 years, 9 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ftp/ftp_directory_listing_parser_unittest.h" 5 #include "net/ftp/ftp_directory_listing_parser_unittest.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/string_split.h" 8 #include "base/string_split.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "net/ftp/ftp_directory_listing_parser_vms.h" 12 #include "net/ftp/ftp_directory_listing_parser_vms.h"
13 13
14 namespace net {
15
14 namespace { 16 namespace {
15 17
16 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserVmsTest; 18 typedef FtpDirectoryListingParserTest FtpDirectoryListingParserVmsTest;
17 19
18 TEST_F(FtpDirectoryListingParserVmsTest, Good) { 20 TEST_F(FtpDirectoryListingParserVmsTest, Good) {
19 const struct SingleLineTestData good_cases[] = { 21 const struct SingleLineTestData good_cases[] = {
20 { "README.TXT;4 2 18-APR-2000 10:40:39.90", 22 { "README.TXT;4 2 18-APR-2000 10:40:39.90",
21 net::FtpDirectoryListingEntry::FILE, "readme.txt", 1024, 23 FtpDirectoryListingEntry::FILE, "readme.txt", 1024,
22 2000, 4, 18, 10, 40 }, 24 2000, 4, 18, 10, 40 },
23 { ".WELCOME;1 2 13-FEB-2002 23:32:40.47", 25 { ".WELCOME;1 2 13-FEB-2002 23:32:40.47",
24 net::FtpDirectoryListingEntry::FILE, ".welcome", 1024, 26 FtpDirectoryListingEntry::FILE, ".welcome", 1024,
25 2002, 2, 13, 23, 32 }, 27 2002, 2, 13, 23, 32 },
26 { "FILE.;1 2 13-FEB-2002 23:32:40.47", 28 { "FILE.;1 2 13-FEB-2002 23:32:40.47",
27 net::FtpDirectoryListingEntry::FILE, "file.", 1024, 29 FtpDirectoryListingEntry::FILE, "file.", 1024,
28 2002, 2, 13, 23, 32 }, 30 2002, 2, 13, 23, 32 },
29 { "EXAMPLE.TXT;1 1 4-NOV-2009 06:02 [JOHNDOE] (RWED,RWED,,)", 31 { "EXAMPLE.TXT;1 1 4-NOV-2009 06:02 [JOHNDOE] (RWED,RWED,,)",
30 net::FtpDirectoryListingEntry::FILE, "example.txt", 512, 32 FtpDirectoryListingEntry::FILE, "example.txt", 512,
31 2009, 11, 4, 6, 2 }, 33 2009, 11, 4, 6, 2 },
32 { "ANNOUNCE.TXT;2 1/16 12-MAR-2005 08:44:57 [SYSTEM] (RWED,RWED,RE,RE)", 34 { "ANNOUNCE.TXT;2 1/16 12-MAR-2005 08:44:57 [SYSTEM] (RWED,RWED,RE,RE)",
33 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, 35 FtpDirectoryListingEntry::FILE, "announce.txt", 512,
34 2005, 3, 12, 8, 44 }, 36 2005, 3, 12, 8, 44 },
35 { "TEST.DIR;1 1 4-MAR-1999 22:14:34 [UCX$NOBO,ANONYMOUS] (RWE,RWE,RWE,RWE)", 37 { "TEST.DIR;1 1 4-MAR-1999 22:14:34 [UCX$NOBO,ANONYMOUS] (RWE,RWE,RWE,RWE)",
36 net::FtpDirectoryListingEntry::DIRECTORY, "test", -1, 38 FtpDirectoryListingEntry::DIRECTORY, "test", -1,
37 1999, 3, 4, 22, 14 }, 39 1999, 3, 4, 22, 14 },
38 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (,,,)", 40 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (,,,)",
39 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, 41 FtpDirectoryListingEntry::FILE, "announce.txt", 512,
40 2005, 3, 12, 8, 44 }, 42 2005, 3, 12, 8, 44 },
41 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (R,RW,RWD,RE)", 43 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (R,RW,RWD,RE)",
42 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, 44 FtpDirectoryListingEntry::FILE, "announce.txt", 512,
43 2005, 3, 12, 8, 44 }, 45 2005, 3, 12, 8, 44 },
44 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)", 46 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)",
45 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, 47 FtpDirectoryListingEntry::FILE, "announce.txt", 512,
46 2005, 3, 12, 8, 44 }, 48 2005, 3, 12, 8, 44 },
47 }; 49 };
48 for (size_t i = 0; i < arraysize(good_cases); i++) { 50 for (size_t i = 0; i < arraysize(good_cases); i++) {
49 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, 51 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
50 good_cases[i].input)); 52 good_cases[i].input));
51 53
52 net::FtpDirectoryListingParserVms parser; 54 std::vector<string16> lines(GetSingleLineTestCase(good_cases[i].input));
53 ASSERT_TRUE( 55
54 parser.ConsumeLine(ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"))); 56 // The parser requires a directory header before accepting regular input.
55 RunSingleLineTestCase(&parser, good_cases[i]); 57 lines.insert(lines.begin(),
58 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"));
59
60 // A valid listing must also have a "Total" line at the end.
61 lines.insert(lines.end(),
62 ASCIIToUTF16("Total of 1 file, 2 blocks."));
63
64 std::vector<FtpDirectoryListingEntry> entries;
65 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines,
66 &entries));
67 VerifySingleLineTestCase(good_cases[i], entries);
56 } 68 }
57 } 69 }
58 70
59 TEST_F(FtpDirectoryListingParserVmsTest, Bad) { 71 TEST_F(FtpDirectoryListingParserVmsTest, Bad) {
60 const char* bad_cases[] = { 72 const char* bad_cases[] = {
61 "Directory ROOT|garbage", 73 "garbage",
62 74
63 // Missing file version number. 75 // Missing file version number.
64 "Directory ROOT|README.TXT 2 18-APR-2000 10:40:39", 76 "README.TXT 2 18-APR-2000 10:40:39",
65 77
66 // Missing extension. 78 // Missing extension.
67 "Directory ROOT|README;1 2 18-APR-2000 10:40:39", 79 "README;1 2 18-APR-2000 10:40:39",
68 80
69 // Malformed file size. 81 // Malformed file size.
70 "Directory ROOT|README.TXT;1 garbage 18-APR-2000 10:40:39", 82 "README.TXT;1 garbage 18-APR-2000 10:40:39",
71 "Directory ROOT|README.TXT;1 -2 18-APR-2000 10:40:39", 83 "README.TXT;1 -2 18-APR-2000 10:40:39",
72 84
73 // Malformed date. 85 // Malformed date.
74 "Directory ROOT|README.TXT;1 2 APR-2000 10:40:39", 86 "README.TXT;1 2 APR-2000 10:40:39",
eroman 2011/03/24 23:09:35 how come the test data has changed?
Paweł Hajdan Jr. 2011/03/26 09:47:50 I refactored the tests slightly, and removed some
75 "Directory ROOT|README.TXT;1 2 -18-APR-2000 10:40:39", 87 "README.TXT;1 2 -18-APR-2000 10:40:39",
76 "Directory ROOT|README.TXT;1 2 18-APR 10:40:39", 88 "README.TXT;1 2 18-APR 10:40:39",
77 "Directory ROOT|README.TXT;1 2 18-APR-2000 10", 89 "README.TXT;1 2 18-APR-2000 10",
78 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40.25", 90 "README.TXT;1 2 18-APR-2000 10:40.25",
79 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40.25.25", 91 "README.TXT;1 2 18-APR-2000 10:40.25.25",
80
81 // Empty line inside the listing.
82 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40:42"
83 "||README.TXT;1 2 18-APR-2000 10:40:42",
84
85 // Data after footer.
86 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39"
87 "||Total of 1 file|",
88 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39"
89 "||Total of 1 file|garbage",
90 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39"
91 "||Total of 1 file|Total of 1 file",
92 92
93 // Malformed security information. 93 // Malformed security information.
94 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)", 94 "X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)",
95 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM]", 95 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM]",
96 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)", 96 "X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)",
97 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]", 97 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]",
98 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)", 98 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)",
99 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)", 99 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)",
100 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)", 100 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)",
101 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)", 101 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)",
102 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)", 102 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)",
103 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)", 103 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)",
104 }; 104 };
105 for (size_t i = 0; i < arraysize(bad_cases); i++) { 105 for (size_t i = 0; i < arraysize(bad_cases); i++) {
106 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i])); 106 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i]));
107 107
108 std::vector<std::string> lines; 108 std::vector<string16> lines(GetSingleLineTestCase(bad_cases[i]));
109 base::SplitString(bad_cases[i], '|', &lines); 109
110 net::FtpDirectoryListingParserVms parser; 110 // The parser requires a directory header before accepting regular input.
111 bool failed = false; 111 lines.insert(lines.begin(),
112 for (std::vector<std::string>::const_iterator i = lines.begin(); 112 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"));
113 i != lines.end(); ++i) { 113
114 if (!parser.ConsumeLine(UTF8ToUTF16(*i))) { 114 // A valid listing must also have a "Total" line at the end.
115 failed = true; 115 lines.insert(lines.end(),
116 break; 116 ASCIIToUTF16("Total of 1 file, 2 blocks."));
117 } 117
118 } 118 std::vector<FtpDirectoryListingEntry> entries;
119 EXPECT_TRUE(failed); 119 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines,
120 &entries));
120 } 121 }
121 } 122 }
122 123
123 } // namespace 124 } // namespace
125
126 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698