Commit c6e858ae authored by Romain Courteaud's avatar Romain Courteaud

idb: test huge attachment

parent 0a4768d2
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
/*jslint nomen: true */ /*jslint nomen: true */
/*global indexedDB, Blob, sinon, IDBDatabase, /*global indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange, IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange,
DOMException*/ DOMException, Rusha*/
(function (jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase, (function (jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange, IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange,
DOMException) { DOMException, Rusha) {
"use strict"; "use strict";
var test = QUnit.test, var test = QUnit.test,
stop = QUnit.stop, stop = QUnit.stop,
...@@ -34,12 +34,9 @@ ...@@ -34,12 +34,9 @@
equal = QUnit.equal, equal = QUnit.equal,
module = QUnit.module, module = QUnit.module,
throws = QUnit.throws, throws = QUnit.throws,
big_string = "", big_string = "";
j;
for (j = 0; j < 3000000; j += 1) { big_string = new Array(3000000).fill('a').join('');
big_string += "a";
}
function deleteIndexedDB(storage) { function deleteIndexedDB(storage) {
return new RSVP.Promise(function resolver(resolve, reject) { return new RSVP.Promise(function resolver(resolve, reject) {
...@@ -1764,6 +1761,46 @@ ...@@ -1764,6 +1761,46 @@
}); });
}); });
test("get huge attachment", function () {
var context = this,
attachment = "attachment";
stop();
expect(4);
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
return context.jio.putAttachment(
"foo",
attachment,
new Blob([new Array(11 * 2000000).fill('a').join('')],
{type: 'text/fooplain'})
);
})
.then(function () {
return context.jio.getAttachment("foo", attachment);
})
.then(function (blob) {
ok(blob instanceof Blob, "Data is Blob");
equal(blob.type, 'text/fooplain');
equal(blob.size, 22000000);
return jIO.util.readBlobAsArrayBuffer(blob);
})
.then(function (result) {
equal((new Rusha()).digestFromArrayBuffer(result.target.result),
'6f510194afd8e436d00a543f49a7df09e86c2687');
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("retrieve empty blob", function () { test("retrieve empty blob", function () {
var context = this, var context = this,
attachment = "attachment", attachment = "attachment",
...@@ -2089,4 +2126,4 @@ ...@@ -2089,4 +2126,4 @@
}(jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase, }(jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange, IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange,
DOMException)); DOMException, Rusha));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment