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