netwerk/test/unit/test_bug654926.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.

     1 var _PSvc;
     2 function get_pref_service() {
     3   if (_PSvc)
     4     return _PSvc;
     6   return _PSvc = Cc["@mozilla.org/preferences-service;1"].
     7                  getService(Ci.nsIPrefBranch);
     8 }
    10 function gen_1MiB()
    11 {
    12   var i;
    13   var data="x";
    14   for (i=0 ; i < 20 ; i++)
    15     data+=data;
    16   return data;
    17 }
    19 function write_and_check(str, data, len)
    20 {
    21   var written = str.write(data, len);
    22   if (written != len) {
    23     do_throw("str.write has not written all data!\n" +
    24              "  Expected: " + len  + "\n" +
    25              "  Actual: " + written + "\n");
    26   }
    27 }
    29 function write_datafile(status, entry)
    30 {
    31   do_check_eq(status, Cr.NS_OK);
    32   var os = entry.openOutputStream(0);
    33   var data = gen_1MiB();
    35   // write 2MiB
    36   var i;
    37   for (i=0 ; i<2 ; i++)
    38     write_and_check(os, data, data.length);
    40   os.close();
    41   entry.close();
    43   // now change max_entry_size so that the existing entry is too big
    44   get_pref_service().setIntPref("browser.cache.disk.max_entry_size", 1024);
    46   // append to entry
    47   asyncOpenCacheEntry("http://data/",
    48                       "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
    49                       append_datafile);
    50 }
    52 function append_datafile(status, entry)
    53 {
    54   do_check_eq(status, Cr.NS_OK);
    55   var os = entry.openOutputStream(entry.dataSize);
    56   var data = gen_1MiB();
    58   // append 1MiB
    59   try {
    60     write_and_check(os, data, data.length);
    61     do_throw();
    62   }
    63   catch (ex) { }
    65   // closing the ostream should fail in this case
    66   try {
    67     os.close();
    68     do_throw();
    69   }
    70   catch (ex) { }
    72   entry.close();
    74   do_test_finished();
    75 }
    77 function run_test() {
    78   if (newCacheBackEndUsed()) {
    79     // Needs limit preferences
    80     do_check_true(true, "This test doesn't run with the new cache backend, the test or the cache needs to be fixed");
    81     return;
    82   }
    84   do_get_profile();
    86   // clear the cache
    87   evict_cache_entries();
    89   asyncOpenCacheEntry("http://data/",
    90                       "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
    91                       write_datafile);
    93   do_test_pending();
    94 }

mercurial