tor-browser

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

test_bug654926.js (1621B)


      1 "use strict";
      2 
      3 function gen_1MiB() {
      4  var i;
      5  var data = "x";
      6  for (i = 0; i < 20; i++) {
      7    data += data;
      8  }
      9  return data;
     10 }
     11 
     12 function write_and_check(str, data, len) {
     13  var written = str.write(data, len);
     14  if (written != len) {
     15    do_throw(
     16      "str.write has not written all data!\n" +
     17        "  Expected: " +
     18        len +
     19        "\n" +
     20        "  Actual: " +
     21        written +
     22        "\n"
     23    );
     24  }
     25 }
     26 
     27 function write_datafile(status, entry) {
     28  Assert.equal(status, Cr.NS_OK);
     29  var data = gen_1MiB();
     30  var os = entry.openOutputStream(0, data.length);
     31 
     32  // write 2MiB
     33  var i;
     34  for (i = 0; i < 2; i++) {
     35    write_and_check(os, data, data.length);
     36  }
     37 
     38  os.close();
     39 
     40  // now change max_entry_size so that the existing entry is too big
     41  Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 1024);
     42 
     43  // append to entry
     44  asyncOpenCacheEntry(
     45    "http://data/",
     46    "disk",
     47    Ci.nsICacheStorage.OPEN_NORMALLY,
     48    null,
     49    append_datafile
     50  );
     51 }
     52 
     53 function append_datafile(status, entry) {
     54  Assert.equal(status, Cr.NS_OK);
     55  var os = entry.openOutputStream(entry.dataSize, -1);
     56  var data = gen_1MiB();
     57 
     58  // append 1MiB
     59  try {
     60    write_and_check(os, data, data.length);
     61    do_throw();
     62  } catch (ex) {}
     63 
     64  // closing the ostream should fail in this case
     65  try {
     66    os.close();
     67    do_throw();
     68  } catch (ex) {}
     69 
     70  do_test_finished();
     71 }
     72 
     73 function run_test() {
     74  do_get_profile();
     75 
     76  // clear the cache
     77  evict_cache_entries();
     78 
     79  asyncOpenCacheEntry(
     80    "http://data/",
     81    "disk",
     82    Ci.nsICacheStorage.OPEN_NORMALLY,
     83    null,
     84    write_datafile
     85  );
     86 
     87  do_test_pending();
     88 }