1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug654926.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +var _PSvc; 1.5 +function get_pref_service() { 1.6 + if (_PSvc) 1.7 + return _PSvc; 1.8 + 1.9 + return _PSvc = Cc["@mozilla.org/preferences-service;1"]. 1.10 + getService(Ci.nsIPrefBranch); 1.11 +} 1.12 + 1.13 +function gen_1MiB() 1.14 +{ 1.15 + var i; 1.16 + var data="x"; 1.17 + for (i=0 ; i < 20 ; i++) 1.18 + data+=data; 1.19 + return data; 1.20 +} 1.21 + 1.22 +function write_and_check(str, data, len) 1.23 +{ 1.24 + var written = str.write(data, len); 1.25 + if (written != len) { 1.26 + do_throw("str.write has not written all data!\n" + 1.27 + " Expected: " + len + "\n" + 1.28 + " Actual: " + written + "\n"); 1.29 + } 1.30 +} 1.31 + 1.32 +function write_datafile(status, entry) 1.33 +{ 1.34 + do_check_eq(status, Cr.NS_OK); 1.35 + var os = entry.openOutputStream(0); 1.36 + var data = gen_1MiB(); 1.37 + 1.38 + // write 2MiB 1.39 + var i; 1.40 + for (i=0 ; i<2 ; i++) 1.41 + write_and_check(os, data, data.length); 1.42 + 1.43 + os.close(); 1.44 + entry.close(); 1.45 + 1.46 + // now change max_entry_size so that the existing entry is too big 1.47 + get_pref_service().setIntPref("browser.cache.disk.max_entry_size", 1024); 1.48 + 1.49 + // append to entry 1.50 + asyncOpenCacheEntry("http://data/", 1.51 + "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null, 1.52 + append_datafile); 1.53 +} 1.54 + 1.55 +function append_datafile(status, entry) 1.56 +{ 1.57 + do_check_eq(status, Cr.NS_OK); 1.58 + var os = entry.openOutputStream(entry.dataSize); 1.59 + var data = gen_1MiB(); 1.60 + 1.61 + // append 1MiB 1.62 + try { 1.63 + write_and_check(os, data, data.length); 1.64 + do_throw(); 1.65 + } 1.66 + catch (ex) { } 1.67 + 1.68 + // closing the ostream should fail in this case 1.69 + try { 1.70 + os.close(); 1.71 + do_throw(); 1.72 + } 1.73 + catch (ex) { } 1.74 + 1.75 + entry.close(); 1.76 + 1.77 + do_test_finished(); 1.78 +} 1.79 + 1.80 +function run_test() { 1.81 + if (newCacheBackEndUsed()) { 1.82 + // Needs limit preferences 1.83 + do_check_true(true, "This test doesn't run with the new cache backend, the test or the cache needs to be fixed"); 1.84 + return; 1.85 + } 1.86 + 1.87 + do_get_profile(); 1.88 + 1.89 + // clear the cache 1.90 + evict_cache_entries(); 1.91 + 1.92 + asyncOpenCacheEntry("http://data/", 1.93 + "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null, 1.94 + write_datafile); 1.95 + 1.96 + do_test_pending(); 1.97 +}