tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_cache2-23-read-over-chunk.js (822B)


      1 "use strict";
      2 
      3 function run_test() {
      4  do_get_profile();
      5 
      6  const kChunkSize = 256 * 1024;
      7 
      8  var payload = "";
      9  for (var i = 0; i < kChunkSize + 10; ++i) {
     10    if (i < kChunkSize - 5) {
     11      payload += "0";
     12    } else {
     13      payload += String.fromCharCode(i + 65);
     14    }
     15  }
     16 
     17  asyncOpenCacheEntry(
     18    "http://read/",
     19    "disk",
     20    Ci.nsICacheStorage.OPEN_TRUNCATE,
     21    Services.loadContextInfo.default,
     22    new OpenCallback(NEW | WAITFORWRITE, "", payload, function (entry) {
     23      var is = entry.openInputStream(0);
     24      pumpReadStream(is, function (read) {
     25        Assert.equal(read.length, kChunkSize + 10);
     26        is.close();
     27        Assert.equal(read, payload); // not using do_check_eq since logger will fail for the 1/4MB string
     28        finish_cache2_test();
     29      });
     30    })
     31  );
     32 
     33  do_test_pending();
     34 }