Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: qunit/tests/io.js

Issue 29350042: Issue 4023 - Move storage of subscription lists to localStorage (Closed)
Patch Set: Make sure entry["compressed"] is truthful Created Sept. 8, 2016, 11:40 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « metadata.common ('k') | safari/ext/background.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: qunit/tests/io.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/qunit/tests/io.js
@@ -0,0 +1,89 @@
+ /* 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;
+ module("IO validation", {
+ afterEach: function()
+ {
+ if (typeof browser == "undefined")
+ ext.storage.remove("testfile");
+ else
+ window.localStorage.removeItem("testfile");
+ }
+ });
+
+ function DummyParser()
+ {
+ readData = [];
+ };
+
+ DummyParser.prototype =
+ {
+ readData: [],
+ process: function (line)
+ {
+ this.readData.push(line);
+ }
+ };
+
+ function testReadWrite(data, fileName, assert)
+ {
+ var fileWritten = assert.async();
+ for (var index = 0; index < data.length; index++)
+ data[index] = "test string " + index;
+ IO.writeToFile(IO.resolveFilePath(fileName), data, () => {});
+ setTimeout(function()
+ {
+ fileWritten();
+
+ var fileRead = assert.async();
+ var dummyParser = new DummyParser();
+ dummyParser.readData = [];
+ 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);
+ }
+
+ test("Test writing entry larger than 1Mb but smaller than 5Mb", assert =>
+ {
+ var testDataOver1Mb = new Array(30000);
+ testReadWrite(testDataOver1Mb, "testFile", assert);
+ expect(2);
+ });
+
+ test("Test writing entry larger than 5Mb", assert =>
+ {
+ var testDataOver5Mb = new Array(300000);
+ testReadWrite(testDataOver5Mb, "testFile", assert);
+ expect(2);
+ });
+})();
« no previous file with comments | « metadata.common ('k') | safari/ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld