netwerk/test/unit/test_compressappend.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 //
     2 // Test that data can be appended to a cache entry even when the data is 
     3 // compressed by the cache compression feature - bug 648429.
     4 //
     6 function write_and_check(str, data, len)
     7 {
     8   var written = str.write(data, len);
     9   if (written != len) {
    10     do_throw("str.write has not written all data!\n" +
    11              "  Expected: " + len  + "\n" +
    12              "  Actual: " + written + "\n");
    13   }
    14 }
    16 function TestAppend(compress, callback)
    17 {
    18   this._compress = compress;
    19   this._callback = callback;
    20   this.run();
    21 }
    23 TestAppend.prototype = {
    24   _compress: false,
    25   _callback: null,
    27   run: function() {
    28     evict_cache_entries();
    29     asyncOpenCacheEntry("http://data/",
    30                         "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
    31                         this.writeData.bind(this));
    32   },
    34   writeData: function(status, entry) {
    35     do_check_eq(status, Cr.NS_OK);
    36     if (this._compress)
    37       entry.setMetaDataElement("uncompressed-len", "0");
    38     var os = entry.openOutputStream(0);
    39     write_and_check(os, "12345", 5);
    40     os.close();
    41     entry.close();
    42     asyncOpenCacheEntry("http://data/",
    43                         "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
    44                         this.appendData.bind(this));
    45   },
    47   appendData: function(status, entry) {
    48     do_check_eq(status, Cr.NS_OK);
    49     var os = entry.openOutputStream(entry.storageDataSize);
    50     write_and_check(os, "abcde", 5);
    51     os.close();
    52     entry.close();
    54     asyncOpenCacheEntry("http://data/",
    55                         "disk", Ci.nsICacheStorage.OPEN_READONLY, null,
    56                         this.checkData.bind(this));
    57   },
    59   checkData: function(status, entry) {
    60     do_check_eq(status, Cr.NS_OK);
    61     var self = this;
    62     pumpReadStream(entry.openInputStream(0), function(str) {
    63       do_check_eq(str.length, 10);
    64       do_check_eq(str, "12345abcde");
    65       entry.close();
    67       do_execute_soon(self._callback);
    68     });
    69   }
    70 };
    72 function run_test() {
    73   do_get_profile();
    74   new TestAppend(false, run_test2);
    75   do_test_pending();
    76 }
    78 function run_test2() {
    79   new TestAppend(true, do_test_finished);
    80 }

mercurial