netwerk/test/unit/test_bug654926_test_seek.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 function gen_1MiB()
     2 {
     3   var i;
     4   var data="x";
     5   for (i=0 ; i < 20 ; i++)
     6     data+=data;
     7   return data;
     8 }
    10 function write_and_check(str, data, len)
    11 {
    12   var written = str.write(data, len);
    13   if (written != len) {
    14     do_throw("str.write has not written all data!\n" +
    15              "  Expected: " + len  + "\n" +
    16              "  Actual: " + written + "\n");
    17   }
    18 }
    20 function write_datafile(status, entry)
    21 {
    22   do_check_eq(status, Cr.NS_OK);
    23   var os = entry.openOutputStream(0);
    24   var data = gen_1MiB();
    26   write_and_check(os, data, data.length);
    28   os.close();
    29   entry.close();
    31   // try to open the entry for appending
    32   asyncOpenCacheEntry("http://data/",
    33                       "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
    34                       open_for_readwrite);
    35 }
    37 function open_for_readwrite(status, entry)
    38 {
    39   do_check_eq(status, Cr.NS_OK);
    40   var os = entry.openOutputStream(entry.dataSize);
    42   // Opening the entry for appending data calls nsDiskCacheStreamIO::Seek()
    43   // which initializes mFD. If no data is written then mBufDirty is false and
    44   // mFD won't be closed in nsDiskCacheStreamIO::Flush().
    46   os.close();
    47   entry.close();
    49   do_test_finished();
    50 }
    52 function run_test() {
    53   do_get_profile();
    55   // clear the cache
    56   evict_cache_entries();
    58   asyncOpenCacheEntry("http://data/",
    59                       "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
    60                       write_datafile);
    62   do_test_pending();
    63 }

mercurial