netwerk/test/unit/test_doomentry.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 /**
     2  * Test for nsICacheStorage.asyncDoomURI().
     3  * It tests dooming
     4  *   - an existent inactive entry
     5  *   - a non-existent inactive entry
     6  *   - an existent active entry
     7  */
     9 function doom(url, callback)
    10 {
    11   get_cache_service()
    12       .diskCacheStorage(LoadContextInfo.default, false)
    13       .asyncDoomURI(createURI(url), "", {
    14         onCacheEntryDoomed: function(result) {
    15           callback(result);
    16         }
    17       });
    18 }
    20 function write_and_check(str, data, len)
    21 {
    22   var written = str.write(data, len);
    23   if (written != len) {
    24     do_throw("str.write has not written all data!\n" +
    25              "  Expected: " + len  + "\n" +
    26              "  Actual: " + written + "\n");
    27   }
    28 }
    30 function write_entry()
    31 {
    32   asyncOpenCacheEntry("http://testentry/", "disk", Ci.nsICacheStorage.OPEN_TRUNCATE, null, function(status, entry) {
    33     write_entry_cont(entry, entry.openOutputStream(0));
    34   });
    35 }
    37 function write_entry_cont(entry, ostream)
    38 {
    39   var data = "testdata";
    40   write_and_check(ostream, data, data.length);
    41   ostream.close();
    42   entry.close();
    43   doom("http://testentry/", check_doom1);
    44 }
    46 function check_doom1(status)
    47 {
    48   do_check_eq(status, Cr.NS_OK);
    49   doom("http://nonexistententry/", check_doom2);
    50 }
    52 function check_doom2(status)
    53 {
    54   do_check_eq(status, Cr.NS_ERROR_NOT_AVAILABLE);
    55   asyncOpenCacheEntry("http://testentry/", "disk", Ci.nsICacheStorage.OPEN_TRUNCATE, null, function(status, entry) {
    56     write_entry2(entry, entry.openOutputStream(0));
    57   });
    58 }
    60 var gEntry;
    61 var gOstream;
    62 function write_entry2(entry, ostream)
    63 {
    64   // write some data and doom the entry while it is active
    65   var data = "testdata";
    66   write_and_check(ostream, data, data.length);
    67   gEntry = entry;
    68   gOstream = ostream;
    69   doom("http://testentry/", check_doom3);
    70 }
    72 function check_doom3(status)
    73 {
    74   do_check_eq(status, Cr.NS_OK);
    75   // entry was doomed but writing should still succeed
    76   var data = "testdata";
    77   write_and_check(gOstream, data, data.length);
    78   gOstream.close();
    79   gEntry.close();
    80   // dooming the same entry again should fail
    81   doom("http://testentry/", check_doom4);
    82 }
    84 function check_doom4(status)
    85 {
    86   do_check_eq(status, Cr.NS_ERROR_NOT_AVAILABLE);
    87   do_test_finished();
    88 }
    90 function run_test() {
    91   do_get_profile();
    93   // clear the cache
    94   evict_cache_entries();
    95   write_entry();
    96   do_test_pending();
    97 }

mercurial