1 function getURLContent(aURL
) {
2 var ios
= Components
.classes
["@mozilla.org/network/io-service;1"].
3 getService(Components
.interfaces
.nsIIOService
);
5 var uri
= ios
.newURI(aURL
, null, null);
6 var chan
= ios
.newChannelFromURI(uri
);
8 var scinp
= Components
.classes
["@mozilla.org/scriptableinputstream;1"].
9 createInstance(Components
.interfaces
.nsIScriptableInputStream
);
12 var avail
= scinp
.available();
14 result
+= scinp
.read(avail
);
15 avail
= scinp
.available();
20 function storeCache(aURL
, aContent
) {
21 const nsICache
= Components
.interfaces
.nsICache
;
23 var cache
= Components
.classes
["@mozilla.org/network/cache-service;1"].
24 getService(Components
.interfaces
.nsICacheService
);
26 var session
= cache
.createSession("FTP", nsICache
.STORE_ANYWHERE
, nsICache
.STREAM_BASED
);
28 var cacheEntry
= session
.openCacheEntry(aURL
, nsICache
.ACCESS_READ_WRITE
, false);
30 cacheEntry
.setMetaDataElement("servertype", "0");
31 var oStream
= cacheEntry
.openOutputStream(0);
33 var written
= oStream
.write(aContent
, aContent
.length
);
34 if (written
!= aContent
.length
) {
35 do_throw("oStream.write have not written all data!\n" +
36 " Expected: " + written
+ "\n" +
37 " Actual: " + aContent
.length
+ "\n");
44 /* Unix style listing, space at the end of filename */
45 var rawData
= "drwxrwxr-x 2 500 500 4096 Jan 01 2000 a \r\n";
46 storeCache("ftp://localhost/bug365133/", rawData
);
47 var parsedData
= getURLContent("ftp://localhost/bug365133/");
48 do_check_eq(parsedData
,
49 "300: ftp://localhost/bug365133/\n" +
50 "200: filename content-length last-modified file-type\n" +
51 "201: \"a%20\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 DIRECTORY \n");
53 /* Unix style listing, space at the end of link name */
54 rawData
= "lrwxrwxrwx 1 500 500 2 Jan 01 2000 l -> a \r\n";
55 storeCache("ftp://localhost/bug365133/", rawData
);
56 parsedData
= getURLContent("ftp://localhost/bug365133/");
57 do_check_eq(parsedData
,
58 "300: ftp://localhost/bug365133/\n" +
59 "200: filename content-length last-modified file-type\n" +
60 "201: \"l%20\" 2 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 SYMBOLIC-LINK \n");
62 /* Unix style listing, regular file with " -> " in name */
63 rawData
= "-rw-rw-r-- 1 500 500 0 Jan 01 2000 arrow -> in name \r\n";
64 storeCache("ftp://localhost/bug365133/", rawData
);
65 parsedData
= getURLContent("ftp://localhost/bug365133/");
66 do_check_eq(parsedData
,
67 "300: ftp://localhost/bug365133/\n" +
68 "200: filename content-length last-modified file-type\n" +
69 "201: \"arrow%20-%3E%20in%20name%20\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 FILE \n");
71 /* Unix style listing, tab at the end of filename */
72 rawData
= "drwxrwxrwx 2 500 500 4096 Jan 01 2000 t \r\n";
73 storeCache("ftp://localhost/bug365133/", rawData
);
74 parsedData
= getURLContent("ftp://localhost/bug365133/");
75 do_check_eq(parsedData
,
76 "300: ftp://localhost/bug365133/\n" +
77 "200: filename content-length last-modified file-type\n" +
78 "201: \"t%09\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 DIRECTORY \n");
80 /* Unix style listing, multiple " -> " in filename */
81 rawData
= "lrwxrwxrwx 1 500 500 26 Jan 01 2000 symlink with arrow -> in name -> file with arrow -> in name\r\n";
82 storeCache("ftp://localhost/bug365133/", rawData
);
83 parsedData
= getURLContent("ftp://localhost/bug365133/");
84 do_check_eq(parsedData
,
85 "300: ftp://localhost/bug365133/\n" +
86 "200: filename content-length last-modified file-type\n" +
87 "201: \"symlink%20with%20arrow%20-%3E%20in%20name\" 26 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 SYMBOLIC-LINK \n");
89 /* Unix style listing, multiple " -> " in filename, incorrect filesize */
90 rawData
= "lrwxrwxrwx 1 500 500 0 Jan 01 2000 symlink with arrow -> in name -> file with arrow -> in name\r\n";
91 storeCache("ftp://localhost/bug365133/", rawData
);
92 parsedData
= getURLContent("ftp://localhost/bug365133/");
93 do_check_eq(parsedData
,
94 "300: ftp://localhost/bug365133/\n" +
95 "200: filename content-length last-modified file-type\n" +
96 "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");
98 /* DOS style listing, space at the end of filename, year 1999 */
99 rawData
= "01-01-99 01:00AM 1024 file \r\n";
100 storeCache("ftp://localhost/bug365133/", rawData
);
101 parsedData
= getURLContent("ftp://localhost/bug365133/");
102 do_check_eq(parsedData
,
103 "300: ftp://localhost/bug365133/\n" +
104 "200: filename content-length last-modified file-type\n" +
105 "201: \"file%20\" 1024 Sun%2C%2001%20Jan%201999%2001%3A00%3A00 FILE \n");
107 /* DOS style listing, tab at the end of filename, year 2000 */
108 rawData
= "01-01-00 01:00AM 1024 file \r\n";
109 storeCache("ftp://localhost/bug365133/", rawData
);
110 parsedData
= getURLContent("ftp://localhost/bug365133/");
111 do_check_eq(parsedData
,
112 "300: ftp://localhost/bug365133/\n" +
113 "200: filename content-length last-modified file-type\n" +
114 "201: \"file%09\" 1024 Sun%2C%2001%20Jan%202000%2001%3A00%3A00 FILE \n");