2 * Test for handling too big alternative data
4 * - first we try to open an output stream for too big alt-data which must fail
5 * and leave original data intact
7 * - then we open the output stream without passing predicted data size which
8 * succeeds but writing must fail later at the size limit and the original
15 var altData = "alt-data";
20 // Expand both data to 1MB
21 for (let i = 0; i < 17; i++) {
26 // Set the limit so that the data fits but alt-data doesn't.
27 Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 1800);
34 function write_data() {
38 Ci.nsICacheStorage.OPEN_NORMALLY,
40 function (status, entry) {
41 Assert.equal(status, Cr.NS_OK);
43 var os = entry.openOutputStream(0, -1);
44 var written = os.write(data, data.length);
45 Assert.equal(written, data.length);
48 open_big_altdata_output(entry);
53 function open_big_altdata_output(entry) {
55 entry.openAlternativeOutputStream("text/binary", altData.length);
57 Assert.equal(e.result, Cr.NS_ERROR_FILE_TOO_BIG);
61 check_entry(write_big_altdata);
64 function write_big_altdata() {
68 Ci.nsICacheStorage.OPEN_NORMALLY,
70 function (status, entry) {
71 Assert.equal(status, Cr.NS_OK);
73 var os = entry.openAlternativeOutputStream("text/binary", -1);
75 os.write(altData, altData.length);
77 Assert.equal(e.result, Cr.NS_ERROR_FILE_TOO_BIG);
82 check_entry(do_test_finished);
87 function check_entry(cb) {
91 Ci.nsICacheStorage.OPEN_NORMALLY,
93 function (status, entry) {
94 Assert.equal(status, Cr.NS_OK);
98 is = entry.openAlternativeInputStream("text/binary");
100 Assert.equal(e.result, Cr.NS_ERROR_NOT_AVAILABLE);
103 is = entry.openInputStream(0);
104 pumpReadStream(is, function (read) {
105 Assert.equal(read.length, data.length);