mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
tfarina | 43a416b | 2016-01-06 21:48:07 | [diff] [blame] | 5 | #include "net/base/directory_listing.h" |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 6 | |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 7 | #include "base/strings/utf_string_conversions.h" |
| 8 | #include "base/time/time.h" |
| 9 | #include "testing/gtest/include/gtest/gtest.h" |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 10 | |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 11 | namespace net { |
| 12 | |
| 13 | namespace { |
| 14 | |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 15 | struct GetDirectoryListingEntryCase { |
| 16 | const wchar_t* name; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 17 | const char* const raw_bytes; |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 18 | bool is_dir; |
wtc | 69f8ea8 | 2015-06-04 00:08:13 | [diff] [blame] | 19 | int64_t filesize; |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 20 | base::Time time; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 21 | const char* const expected; |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 22 | }; |
| 23 | |
tfarina | 43a416b | 2016-01-06 21:48:07 | [diff] [blame] | 24 | TEST(DirectoryListingTest, GetDirectoryListingEntry) { |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 25 | const GetDirectoryListingEntryCase test_cases[] = { |
qaz | 6edbc28 | 2016-02-26 19:29:02 | [diff] [blame] | 26 | {L"Foo", "", false, 10000, base::Time(), |
| 27 | "<script>addRow(\"Foo\",\"Foo\",0,10000,\"9.8 kB\",0,\"\");</script>\n"}, |
| 28 | {L"quo\"tes", "", false, 10000, base::Time(), |
| 29 | "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,10000,\"9.8 kB\",0,\"\"" |
| 30 | ");</script>\n"}, |
| 31 | {L"quo\"tes", "quo\"tes", false, 10000, base::Time(), |
| 32 | "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,10000,\"9.8 kB\",0,\"\"" |
| 33 | ");</script>\n"}, |
| 34 | // U+D55C0 U+AE00. raw_bytes is empty (either a local file with |
| 35 | // UTF-8/UTF-16 encoding or a remote file on an ftp server using UTF-8 |
| 36 | {L"\xD55C\xAE00.txt", "", false, 10000, base::Time(), |
| 37 | "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\"," |
| 38 | "\"%ED%95%9C%EA%B8%80.txt\",0,10000,\"9.8 kB\",0,\"\");</script>\n"}, |
| 39 | // U+D55C0 U+AE00. raw_bytes is the corresponding EUC-KR sequence: |
| 40 | // a local or remote file in EUC-KR. |
| 41 | {L"\xD55C\xAE00.txt", "\xC7\xD1\xB1\xDB.txt", false, 10000, base::Time(), |
| 42 | "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\",\"%C7%D1%B1%DB.txt\"" |
| 43 | ",0,10000,\"9.8 kB\",0,\"\");</script>\n"}, |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 44 | }; |
| 45 | |
Ryan Sleevi | 4625214fa | 2018-05-10 16:42:45 | [diff] [blame] | 46 | for (const auto& test_case : test_cases) { |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 47 | const std::string results = GetDirectoryListingEntry( |
Ryan Sleevi | 4625214fa | 2018-05-10 16:42:45 | [diff] [blame] | 48 | base::WideToUTF16(test_case.name), test_case.raw_bytes, |
| 49 | test_case.is_dir, test_case.filesize, test_case.time); |
| 50 | EXPECT_EQ(test_case.expected, results); |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 54 | } // namespace |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 55 | |
mmenke@chromium.org | 5ecf7cb28 | 2014-05-11 01:49:55 | [diff] [blame] | 56 | } // namespace net |