OLD | NEW |
| (Empty) |
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 | |
5 #include "net/base/net_util.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/strings/utf_string_conversions.h" | |
12 #include "base/time/time.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "url/gurl.h" | |
15 | |
16 namespace net { | |
17 | |
18 namespace { | |
19 | |
20 struct GetDirectoryListingEntryCase { | |
21 const wchar_t* name; | |
22 const char* const raw_bytes; | |
23 bool is_dir; | |
24 int64_t filesize; | |
25 base::Time time; | |
26 const char* const expected; | |
27 }; | |
28 | |
29 TEST(NetUtilTest, GetDirectoryListingEntry) { | |
30 const GetDirectoryListingEntryCase test_cases[] = { | |
31 {L"Foo", | |
32 "", | |
33 false, | |
34 10000, | |
35 base::Time(), | |
36 "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"}, | |
37 {L"quo\"tes", | |
38 "", | |
39 false, | |
40 10000, | |
41 base::Time(), | |
42 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>" | |
43 "\n"}, | |
44 {L"quo\"tes", | |
45 "quo\"tes", | |
46 false, | |
47 10000, | |
48 base::Time(), | |
49 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>" | |
50 "\n"}, | |
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 | |
53 {L"\xD55C\xAE00.txt", | |
54 "", | |
55 false, | |
56 10000, | |
57 base::Time(), | |
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. | |
62 {L"\xD55C\xAE00.txt", | |
63 "\xC7\xD1\xB1\xDB.txt", | |
64 false, | |
65 10000, | |
66 base::Time(), | |
67 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\",\"%C7%D1%B1%DB.txt\"" | |
68 ",0,\"9.8 kB\",\"\");</script>\n"}, | |
69 }; | |
70 | |
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); | |
76 } | |
77 } | |
78 | |
79 } // namespace | |
80 | |
81 } // namespace net | |
OLD | NEW |