|
1 const URL = "ftp://localhost/bug365133/"; |
|
2 |
|
3 const tests = [ |
|
4 [ /* Unix style listing, space at the end of filename */ |
|
5 "drwxrwxr-x 2 500 500 4096 Jan 01 2000 a \r\n" |
|
6 , |
|
7 "300: " + URL + "\n" + |
|
8 "200: filename content-length last-modified file-type\n" + |
|
9 "201: \"a%20\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 DIRECTORY \n" |
|
10 ], |
|
11 [ /* Unix style listing, space at the end of link name */ |
|
12 "lrwxrwxrwx 1 500 500 2 Jan 01 2000 l -> a \r\n" |
|
13 , |
|
14 "300: " + URL + "\n" + |
|
15 "200: filename content-length last-modified file-type\n" + |
|
16 "201: \"l%20\" 2 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 SYMBOLIC-LINK \n" |
|
17 ], |
|
18 [ /* Unix style listing, regular file with " -> " in name */ |
|
19 "-rw-rw-r-- 1 500 500 0 Jan 01 2000 arrow -> in name \r\n" |
|
20 , |
|
21 "300: " + URL + "\n" + |
|
22 "200: filename content-length last-modified file-type\n" + |
|
23 "201: \"arrow%20-%3E%20in%20name%20\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 FILE \n" |
|
24 ], |
|
25 [ /* Unix style listing, tab at the end of filename */ |
|
26 "drwxrwxrwx 2 500 500 4096 Jan 01 2000 t \r\n" |
|
27 , |
|
28 "300: " + URL + "\n" + |
|
29 "200: filename content-length last-modified file-type\n" + |
|
30 "201: \"t%09\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 DIRECTORY \n" |
|
31 ], |
|
32 [ /* Unix style listing, multiple " -> " in filename */ |
|
33 "lrwxrwxrwx 1 500 500 26 Jan 01 2000 symlink with arrow -> in name -> file with arrow -> in name\r\n" |
|
34 , |
|
35 "300: " + URL + "\n" + |
|
36 "200: filename content-length last-modified file-type\n" + |
|
37 "201: \"symlink%20with%20arrow%20-%3E%20in%20name\" 26 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 SYMBOLIC-LINK \n" |
|
38 ], |
|
39 [ /* Unix style listing, multiple " -> " in filename, incorrect filesize */ |
|
40 "lrwxrwxrwx 1 500 500 0 Jan 01 2000 symlink with arrow -> in name -> file with arrow -> in name\r\n" |
|
41 , |
|
42 "300: " + URL + "\n" + |
|
43 "200: filename content-length last-modified file-type\n" + |
|
44 "201: \"symlink%20with%20arrow%20-%3E%20in%20name%20-%3E%20file%20with%20arrow\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 SYMBOLIC-LINK \n" |
|
45 ], |
|
46 [ /* DOS style listing, space at the end of filename, year 1999 */ |
|
47 "01-01-99 01:00AM 1024 file \r\n" |
|
48 , |
|
49 "300: " + URL + "\n" + |
|
50 "200: filename content-length last-modified file-type\n" + |
|
51 "201: \"file%20\" 1024 Sun%2C%2001%20Jan%201999%2001%3A00%3A00 FILE \n" |
|
52 ], |
|
53 [ /* DOS style listing, tab at the end of filename, year 2000 */ |
|
54 "01-01-00 01:00AM 1024 file \r\n" |
|
55 , |
|
56 "300: " + URL + "\n" + |
|
57 "200: filename content-length last-modified file-type\n" + |
|
58 "201: \"file%09\" 1024 Sun%2C%2001%20Jan%202000%2001%3A00%3A00 FILE \n" |
|
59 ] |
|
60 ] |
|
61 |
|
62 function checkData(request, data, ctx) { |
|
63 do_check_eq(tests[0][1], data); |
|
64 tests.shift(); |
|
65 next_test(); |
|
66 } |
|
67 |
|
68 function storeData(status, entry) { |
|
69 do_check_eq(status, Components.results.NS_OK); |
|
70 entry.setMetaDataElement("servertype", "0"); |
|
71 var os = entry.openOutputStream(0); |
|
72 |
|
73 var written = os.write(tests[0][0], tests[0][0].length); |
|
74 if (written != tests[0][0].length) { |
|
75 do_throw("os.write has not written all data!\n" + |
|
76 " Expected: " + written + "\n" + |
|
77 " Actual: " + tests[0][0].length + "\n"); |
|
78 } |
|
79 os.close(); |
|
80 entry.close(); |
|
81 |
|
82 var ios = Components.classes["@mozilla.org/network/io-service;1"]. |
|
83 getService(Components.interfaces.nsIIOService); |
|
84 var channel = ios.newChannel(URL, "", null); |
|
85 channel.asyncOpen(new ChannelListener(checkData, null, CL_ALLOW_UNKNOWN_CL), null); |
|
86 } |
|
87 |
|
88 function next_test() { |
|
89 if (tests.length == 0) |
|
90 do_test_finished(); |
|
91 else { |
|
92 asyncOpenCacheEntry(URL, |
|
93 "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null, |
|
94 storeData); |
|
95 } |
|
96 } |
|
97 |
|
98 function run_test() { |
|
99 do_execute_soon(next_test); |
|
100 do_test_pending(); |
|
101 } |