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.
5 #include "net/base/net_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h"
13 #include "testing/gtest/include/gtest/gtest.h"
20 struct GetDirectoryListingEntryCase
{
22 const char* const raw_bytes
;
26 const char* const expected
;
29 TEST(NetUtilTest
, GetDirectoryListingEntry
) {
30 const GetDirectoryListingEntryCase test_cases
[] = {
36 "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"},
42 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>"
49 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>"
51 // U+D55C0 U+AE00. raw_bytes is empty (either a local file with
52 // UTF-8/UTF-16 encoding or a remote file on an ftp server using UTF-8
58 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\","
59 "\"%ED%95%9C%EA%B8%80.txt\",0,\"9.8 kB\",\"\");</script>\n"},
60 // U+D55C0 U+AE00. raw_bytes is the corresponding EUC-KR sequence:
61 // a local or remote file in EUC-KR.
63 "\xC7\xD1\xB1\xDB.txt",
67 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\",\"%C7%D1%B1%DB.txt\""
68 ",0,\"9.8 kB\",\"\");</script>\n"},
71 for (size_t i
= 0; i
< arraysize(test_cases
); ++i
) {
72 const std::string results
= GetDirectoryListingEntry(
73 base::WideToUTF16(test_cases
[i
].name
), test_cases
[i
].raw_bytes
,
74 test_cases
[i
].is_dir
, test_cases
[i
].filesize
, test_cases
[i
].time
);
75 EXPECT_EQ(test_cases
[i
].expected
, results
);