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

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

mercurial