Commit 11370391 authored by Alexandra Rogova's avatar Alexandra Rogova

indexeddb getAttachment returns faulty string for huge attachments

parent 38b83a9a
This diff is collapsed.
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/*global indexedDB, Blob, sinon, IDBDatabase, /*global indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange*/ IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange*/
(function (jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase, (function (jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange) { IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange, Rusha) {
"use strict"; "use strict";
var test = QUnit.test, var test = QUnit.test,
stop = QUnit.stop, stop = QUnit.stop,
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
equal = QUnit.equal, equal = QUnit.equal,
module = QUnit.module, module = QUnit.module,
big_string = "", big_string = "",
j; j,
rusha = new Rusha();
for (j = 0; j < 3000000; j += 1) { for (j = 0; j < 3000000; j += 1) {
big_string += "a"; big_string += "a";
...@@ -1303,9 +1304,11 @@ ...@@ -1303,9 +1304,11 @@
test("check result", function () { test("check result", function () {
var context = this, var context = this,
attachment = "attachment"; attachment = "attachment",
expected_hash,
received_blob;
stop(); stop();
expect(3); expect(4);
deleteIndexedDB(context.jio) deleteIndexedDB(context.jio)
.then(function () { .then(function () {
...@@ -1318,6 +1321,7 @@ ...@@ -1318,6 +1321,7 @@
return context.jio.getAttachment("foo", attachment); return context.jio.getAttachment("foo", attachment);
}) })
.then(function (result) { .then(function (result) {
received_blob = result;
ok(result instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
equal(result.type, "text/plain;charset=utf-8"); equal(result.type, "text/plain;charset=utf-8");
return jIO.util.readBlobAsText(result); return jIO.util.readBlobAsText(result);
...@@ -1326,6 +1330,54 @@ ...@@ -1326,6 +1330,54 @@
ok(result.target.result === big_string, ok(result.target.result === big_string,
"Attachment correctly fetched"); "Attachment correctly fetched");
}) })
.then(function () {
return jIO.util.readBlobAsArrayBuffer(new Blob([big_string]));
})
.then(function (result) {
expected_hash = rusha.digestFromArrayBuffer(result.target.result);
return jIO.util.readBlobAsArrayBuffer(received_blob);
})
.then(function (result) {
ok(rusha.digestFromArrayBuffer(result.target.result) === expected_hash, "Hash of string sent same as hash of string received");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("huge attachment", function(){
var context = this,
big_string,
big_string_as_array;
stop();
deleteIndexedDB(context.jio)
.then(function () {
return jIO.util.ajax({url : "big_test_map"});
})
.then(function (result) {
big_string = result.currentTarget.responseText;
return jIO.util.readBlobAsArrayBuffer(new Blob([big_string]));
})
.then(function (result) {
big_string_as_array = result.target.result;
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
return context.jio.putAttachment("foo", "attachment", big_string);
})
.then(function () {
return context.jio.getAttachment("foo", "attachment");
})
.then(function (result) {
return jIO.util.readBlobAsArrayBuffer(result);
})
.then(function (result) {
ok(rusha.digestFromArrayBuffer(result.target.result) === rusha.digestFromArrayBuffer(big_string_as_array), "Hash of string sent same as hash of string received");
})
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
}) })
...@@ -1724,4 +1776,4 @@ ...@@ -1724,4 +1776,4 @@
}); });
}(jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase, }(jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange)); IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange, Rusha));
...@@ -28,12 +28,13 @@ See https://www.nexedi.com/licensing for rationale and options. ...@@ -28,12 +28,13 @@ See https://www.nexedi.com/licensing for rationale and options.
<link rel="stylesheet" href="../external/qunit.css" type="text/css" media="screen"/> <link rel="stylesheet" href="../external/qunit.css" type="text/css" media="screen"/>
<script src="../external/qunit.js" type="text/javascript"></script> <script src="../external/qunit.js" type="text/javascript"></script>
<script src="../external/sinon.js" type="text/javascript"></script> <script src="../external/sinon.js" type="text/javascript"></script>
<script src="../external/rusha.js" type="text/javascript"></script>
<!--<script src ="./elasticlunr.js"></script> <!--<script src ="./elasticlunr.js"></script>
<script src="./elasticlunrstorage.js"></script>--> <script src="./elasticlunrstorage.js"></script>-->
<script> <script>
QUnit.config.testTimeout = 5000; QUnit.config.testTimeout = 50000;
</script> </script>
<!--script src="html5.js"></script--> <!--script src="html5.js"></script-->
<!--script src="jio/util.js"></script--> <!--script src="jio/util.js"></script-->
...@@ -80,7 +81,7 @@ See https://www.nexedi.com/licensing for rationale and options. ...@@ -80,7 +81,7 @@ See https://www.nexedi.com/licensing for rationale and options.
<!--script src="jio.storage/websqlstorage.tests.js"></script--> <!--script src="jio.storage/websqlstorage.tests.js"></script-->
<script src="jio.storage/fbstorage.tests.js"></script> <script src="jio.storage/fbstorage.tests.js"></script>
<script src="jio.storage/httpstorage.tests.js"></script> <script src="jio.storage/httpstorage.tests.js"></script>
<script src="jio.storage/elasticlunrstorage.tests.js"></script> <!--<script src="jio.storage/elasticlunrstorage.tests.js"></script>-->
<!--script src="../src/jio.storage/xwikistorage.js"></script> <!--script src="../src/jio.storage/xwikistorage.js"></script>
<script src="jio.storage/xwikistorage.tests.js"></script--> <script src="jio.storage/xwikistorage.tests.js"></script-->
......
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