netwerk/test/unit/test_bug543805.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 const URL = "ftp://localhost/bug543805/";
michael@0 2
michael@0 3 var year = new Date().getFullYear().toString();
michael@0 4
michael@0 5 const tests = [
michael@0 6 // AIX ls format
michael@0 7 ["-rw-r--r-- 1 0 11 Jan 1 20:19 nodup.file\r\n" +
michael@0 8 "-rw-r--r-- 1 0 22 Jan 1 20:19 test.blankfile\r\n" +
michael@0 9 "-rw-r--r-- 1 0 33 Apr 1 2008 test2.blankfile\r\n" +
michael@0 10 "-rw-r--r-- 1 0 44 Jan 1 20:19 nodup.file\r\n" +
michael@0 11 "-rw-r--r-- 1 0 55 Jan 1 20:19 test.file\r\n" +
michael@0 12 "-rw-r--r-- 1 0 66 Apr 1 2008 test2.file\r\n",
michael@0 13
michael@0 14 "300: " + URL + "\n" +
michael@0 15 "200: filename content-length last-modified file-type\n" +
michael@0 16 "201: \"%20nodup.file\" 11 Sun%2C%2001%20Jan%20" + year + "%2020%3A19%3A00 FILE \n" +
michael@0 17 "201: \"%20test.blankfile\" 22 Sun%2C%2001%20Jan%20" + year + "%2020%3A19%3A00 FILE \n" +
michael@0 18 "201: \"%20test2.blankfile\" 33 Sun%2C%2001%20Apr%202008%2000%3A00%3A00 FILE \n" +
michael@0 19 "201: \"nodup.file\" 44 Sun%2C%2001%20Jan%20" + year + "%2020%3A19%3A00 FILE \n" +
michael@0 20 "201: \"test.file\" 55 Sun%2C%2001%20Jan%20" + year + "%2020%3A19%3A00 FILE \n" +
michael@0 21 "201: \"test2.file\" 66 Sun%2C%2001%20Apr%202008%2000%3A00%3A00 FILE \n"],
michael@0 22
michael@0 23 // standard ls format
michael@0 24 [
michael@0 25 "-rw-r--r-- 1 500 500 11 Jan 1 20:19 nodup.file\r\n" +
michael@0 26 "-rw-r--r-- 1 500 500 22 Jan 1 20:19 test.blankfile\r\n" +
michael@0 27 "-rw-r--r-- 1 500 500 33 Apr 1 2008 test2.blankfile\r\n" +
michael@0 28 "-rw-r--r-- 1 500 500 44 Jan 1 20:19 nodup.file\r\n" +
michael@0 29 "-rw-r--r-- 1 500 500 55 Jan 1 20:19 test.file\r\n" +
michael@0 30 "-rw-r--r-- 1 500 500 66 Apr 1 2008 test2.file\r\n",
michael@0 31
michael@0 32 "300: " + URL + "\n" +
michael@0 33 "200: filename content-length last-modified file-type\n" +
michael@0 34 "201: \"%20nodup.file\" 11 Sun%2C%2001%20Jan%20" + year + "%2020%3A19%3A00 FILE \n" +
michael@0 35 "201: \"%20test.blankfile\" 22 Sun%2C%2001%20Jan%20" + year + "%2020%3A19%3A00 FILE \n" +
michael@0 36 "201: \"%20test2.blankfile\" 33 Sun%2C%2001%20Apr%202008%2000%3A00%3A00 FILE \n" +
michael@0 37 "201: \"nodup.file\" 44 Sun%2C%2001%20Jan%20" + year + "%2020%3A19%3A00 FILE \n" +
michael@0 38 "201: \"test.file\" 55 Sun%2C%2001%20Jan%20" + year + "%2020%3A19%3A00 FILE \n" +
michael@0 39 "201: \"test2.file\" 66 Sun%2C%2001%20Apr%202008%2000%3A00%3A00 FILE \n"]
michael@0 40 ]
michael@0 41
michael@0 42 function checkData(request, data, ctx) {
michael@0 43 do_check_eq(tests[0][1], data);
michael@0 44 tests.shift();
michael@0 45 next_test();
michael@0 46 }
michael@0 47
michael@0 48 function storeData(status, entry) {
michael@0 49 do_check_eq(status, Components.results.NS_OK);
michael@0 50 entry.setMetaDataElement("servertype", "0");
michael@0 51 var os = entry.openOutputStream(0);
michael@0 52
michael@0 53 var written = os.write(tests[0][0], tests[0][0].length);
michael@0 54 if (written != tests[0][0].length) {
michael@0 55 do_throw("os.write has not written all data!\n" +
michael@0 56 " Expected: " + written + "\n" +
michael@0 57 " Actual: " + tests[0][0].length + "\n");
michael@0 58 }
michael@0 59 os.close();
michael@0 60 entry.close();
michael@0 61
michael@0 62 var ios = Components.classes["@mozilla.org/network/io-service;1"].
michael@0 63 getService(Components.interfaces.nsIIOService);
michael@0 64 var channel = ios.newChannel(URL, "", null);
michael@0 65 channel.asyncOpen(new ChannelListener(checkData, null, CL_ALLOW_UNKNOWN_CL), null);
michael@0 66 }
michael@0 67
michael@0 68 function next_test() {
michael@0 69 if (tests.length == 0)
michael@0 70 do_test_finished();
michael@0 71 else {
michael@0 72 asyncOpenCacheEntry(URL,
michael@0 73 "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
michael@0 74 storeData);
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78 function run_test() {
michael@0 79 do_execute_soon(next_test);
michael@0 80 do_test_pending();
michael@0 81 }

mercurial