Index: qunit/tests/io.js |
diff --git a/qunit/tests/io.js b/qunit/tests/io.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6f5ceaf6eed1aca9b2827c72dd7c98684b527e9d |
--- /dev/null |
+++ b/qunit/tests/io.js |
@@ -0,0 +1,80 @@ |
+ /* Copyright (C) 2006-2016 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+ |
+(function() |
+{ |
+ var IO = require("io").IO; |
+ var io = require("io"); |
+ module("IO validation"); |
+ |
+ test("Test writing entry larger than 1Mb but smaller than 5Mb", function(assert) |
+ { |
+ var testDataOver1Mb = new Array(30000); |
+ testReadWrite(testDataOver1Mb, "testFile1Mb", assert); |
+ expect(2); |
+ }); |
+ |
+ test("Test writing entry larger than 5Mb", function(assert) |
+ { |
+ var testDataOver5Mb = new Array(300000); |
+ testReadWrite(testDataOver5Mb, "testFile5Mb", assert); |
+ expect(2); |
+ }); |
+ |
+ function DummyParser() |
+ { |
+ readData = new Array(); |
+ }; |
+ DummyParser.prototype = |
+ { |
+ readData: new Array(), |
+ process: function (line) { |
+ this.readData.push(line); |
+ } |
+ }; |
+ |
+ function testReadWrite(data, fileName, assert) |
+ { |
+ // For debugging purposes clear the storage |
+ chrome.storage.local.clear(); |
+ var fileWritten = assert.async(); |
+ for (var index = 0; index < data.length; index++) { |
+ data[index] = "test string " + index; |
+ } |
+ IO.writeToFile(IO.resolveFilePath(fileName), data, |
+ function() { }); |
+ setTimeout(function() |
+ { |
+ fileWritten(); |
+ |
+ var fileRead = assert.async(); |
+ var dummyParser = new DummyParser(); |
+ IO.readFromFile(IO.resolveFilePath(fileName), |
+ dummyParser, |
+ function() |
+ { |
+ equal(dummyParser.readData.length, data.length, |
+ "Check if read entry is the same size as written"); |
+ equal(dummyParser.readData[20000], data[20000], |
+ "Check if read entry element is the same as written"); |
+ fileRead(); |
+ }); |
+ |
+ }, |
+ 1000); |
+ |
+ } |
+})(); |