[go: nahoru, domu]

blob: 2fcbb0e6fc9df3df35afaed20d98655db64b72d3 [file] [log] [blame]
mmenke@chromium.org5ecf7cb282014-05-11 01:49:551// 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
tfarina43a416b2016-01-06 21:48:075#include "net/base/directory_listing.h"
mmenke@chromium.org5ecf7cb282014-05-11 01:49:556
mmenke@chromium.org5ecf7cb282014-05-11 01:49:557#include "base/strings/utf_string_conversions.h"
8#include "base/time/time.h"
9#include "testing/gtest/include/gtest/gtest.h"
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5510
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5511namespace net {
12
13namespace {
14
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5515struct GetDirectoryListingEntryCase {
16 const wchar_t* name;
thestig9d3bb0c2015-01-24 00:49:5117 const char* const raw_bytes;
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5518 bool is_dir;
wtc69f8ea82015-06-04 00:08:1319 int64_t filesize;
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5520 base::Time time;
thestig9d3bb0c2015-01-24 00:49:5121 const char* const expected;
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5522};
23
tfarina43a416b2016-01-06 21:48:0724TEST(DirectoryListingTest, GetDirectoryListingEntry) {
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5525 const GetDirectoryListingEntryCase test_cases[] = {
qaz6edbc282016-02-26 19:29:0226 {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.org5ecf7cb282014-05-11 01:49:5544 };
45
Ryan Sleevi4625214fa2018-05-10 16:42:4546 for (const auto& test_case : test_cases) {
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5547 const std::string results = GetDirectoryListingEntry(
Ryan Sleevi4625214fa2018-05-10 16:42:4548 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.org5ecf7cb282014-05-11 01:49:5551 }
52}
53
rsleevi24f64dc22015-08-07 21:39:2154} // namespace
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5555
mmenke@chromium.org5ecf7cb282014-05-11 01:49:5556} // namespace net