netwerk/test/unit/test_bug365133.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_bug365133.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +const URL = "ftp://localhost/bug365133/";
     1.5 +
     1.6 +const tests = [
     1.7 +  [ /* Unix style listing, space at the end of filename */
     1.8 +    "drwxrwxr-x    2 500      500          4096 Jan 01  2000 a \r\n"
     1.9 +  ,
    1.10 +    "300: " + URL + "\n" +
    1.11 +    "200: filename content-length last-modified file-type\n" +
    1.12 +    "201: \"a%20\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 DIRECTORY \n"
    1.13 +  ],
    1.14 +  [ /* Unix style listing, space at the end of link name */
    1.15 +    "lrwxrwxrwx    1 500      500             2 Jan 01  2000 l  -> a \r\n"
    1.16 +  ,
    1.17 +    "300: " + URL + "\n" +
    1.18 +    "200: filename content-length last-modified file-type\n" +
    1.19 +    "201: \"l%20\" 2 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 SYMBOLIC-LINK \n"
    1.20 +  ],
    1.21 +  [ /* Unix style listing, regular file with " -> " in name */
    1.22 +    "-rw-rw-r--    1 500      500             0 Jan 01  2000 arrow -> in name \r\n"
    1.23 +  ,
    1.24 +    "300: " + URL + "\n" +
    1.25 +    "200: filename content-length last-modified file-type\n" +
    1.26 +    "201: \"arrow%20-%3E%20in%20name%20\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 FILE \n"
    1.27 +  ],
    1.28 +  [ /* Unix style listing, tab at the end of filename */
    1.29 +    "drwxrwxrwx    2 500      500          4096 Jan 01  2000 t	\r\n"
    1.30 +  ,
    1.31 +    "300: " + URL + "\n" +
    1.32 +    "200: filename content-length last-modified file-type\n" +
    1.33 +    "201: \"t%09\" 0 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 DIRECTORY \n"
    1.34 +  ],
    1.35 +  [ /* Unix style listing, multiple " -> " in filename */
    1.36 +    "lrwxrwxrwx    1 500      500            26 Jan 01  2000 symlink with arrow -> in name -> file with arrow -> in name\r\n"
    1.37 +  ,
    1.38 +    "300: " + URL + "\n" +
    1.39 +    "200: filename content-length last-modified file-type\n" +
    1.40 +    "201: \"symlink%20with%20arrow%20-%3E%20in%20name\" 26 Sun%2C%2001%20Jan%202000%2000%3A00%3A00 SYMBOLIC-LINK \n"
    1.41 +  ],
    1.42 +  [ /* Unix style listing, multiple " -> " in filename, incorrect filesize */
    1.43 +    "lrwxrwxrwx    1 500      500             0 Jan 01  2000 symlink with arrow -> in name -> file with arrow -> in name\r\n"
    1.44 +  ,
    1.45 +    "300: " + URL + "\n" +
    1.46 +    "200: filename content-length last-modified file-type\n" +
    1.47 +    "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"
    1.48 +  ],
    1.49 +  [ /* DOS style listing, space at the end of filename, year 1999 */
    1.50 +    "01-01-99  01:00AM                 1024 file \r\n"
    1.51 +  ,
    1.52 +    "300: " + URL + "\n" +
    1.53 +    "200: filename content-length last-modified file-type\n" +
    1.54 +    "201: \"file%20\" 1024 Sun%2C%2001%20Jan%201999%2001%3A00%3A00 FILE \n"
    1.55 +  ],
    1.56 +  [ /* DOS style listing, tab at the end of filename, year 2000 */
    1.57 +    "01-01-00  01:00AM                 1024 file	\r\n"
    1.58 +  ,
    1.59 +    "300: " + URL + "\n" +
    1.60 +    "200: filename content-length last-modified file-type\n" +
    1.61 +    "201: \"file%09\" 1024 Sun%2C%2001%20Jan%202000%2001%3A00%3A00 FILE \n"
    1.62 +  ]
    1.63 +]
    1.64 +
    1.65 +function checkData(request, data, ctx) {
    1.66 +  do_check_eq(tests[0][1], data);
    1.67 +  tests.shift();
    1.68 +  next_test();
    1.69 +}
    1.70 +
    1.71 +function storeData(status, entry) {
    1.72 +  do_check_eq(status, Components.results.NS_OK);
    1.73 +  entry.setMetaDataElement("servertype", "0");
    1.74 +  var os = entry.openOutputStream(0);
    1.75 +
    1.76 +  var written = os.write(tests[0][0], tests[0][0].length);
    1.77 +  if (written != tests[0][0].length) {
    1.78 +    do_throw("os.write has not written all data!\n" +
    1.79 +             "  Expected: " + written  + "\n" +
    1.80 +             "  Actual: " + tests[0][0].length + "\n");
    1.81 +  }
    1.82 +  os.close();
    1.83 +  entry.close();
    1.84 +
    1.85 +  var ios = Components.classes["@mozilla.org/network/io-service;1"].
    1.86 +            getService(Components.interfaces.nsIIOService);
    1.87 +  var channel = ios.newChannel(URL, "", null);
    1.88 +  channel.asyncOpen(new ChannelListener(checkData, null, CL_ALLOW_UNKNOWN_CL), null);
    1.89 +}
    1.90 +
    1.91 +function next_test() {
    1.92 +  if (tests.length == 0)
    1.93 +    do_test_finished();
    1.94 +  else {
    1.95 +    asyncOpenCacheEntry(URL,
    1.96 +                        "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
    1.97 +                        storeData);
    1.98 +  }
    1.99 +}
   1.100 +
   1.101 +function run_test() {
   1.102 +  do_execute_soon(next_test);
   1.103 +  do_test_pending();
   1.104 +}

mercurial