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

Side by Side Diff: qunit/tests/io.js

Issue 29350042: Issue 4023 - Move storage of subscription lists to localStorage (Closed)
Patch Set: Add full stop after a comment and fix formatting Created Sept. 2, 2016, 4:10 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /* Copyright (C) 2006-2016 Eyeo GmbH
2 *
3 * Adblock Plus is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 3 as
5 * published by the Free Software Foundation.
6 *
7 * Adblock Plus is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
14 */
15
16
17 (function()
18 {
19 var IO = require("io").IO;
20 module("IO validation", {
21 afterEach: function()
22 {
23 if (typeof browser == "undefined")
24 ext.storage.remove("testfile");
25 else
26 window.localStorage.removeItem("testfile");
27 }
28 });
29
30 function DummyParser()
31 {
32 readData = [];
33 };
34
35 DummyParser.prototype =
36 {
37 readData: [],
38 process: function (line)
39 {
40 this.readData.push(line);
41 }
42 };
43
44 function testReadWrite(data, fileName, assert)
45 {
46 var fileWritten = assert.async();
47 for (var index = 0; index < data.length; index++)
48 data[index] = "test string " + index;
49 IO.writeToFile(IO.resolveFilePath(fileName), data, () => {});
50 setTimeout(function()
51 {
52 fileWritten();
53
54 var fileRead = assert.async();
55 var dummyParser = new DummyParser();
56 dummyParser.readData = [];
57 IO.readFromFile(
58 IO.resolveFilePath(fileName),
59 dummyParser,
60 function()
61 {
62 equal(
63 dummyParser.readData.length, data.length,
64 "Check if read entry is the same size as written"
65 );
66 equal(
67 dummyParser.readData[20000], data[20000],
68 "Check if read entry element is the same as written"
69 );
70 fileRead();
71 });
72 },
73 1000);
74 }
75
76 test("Test writing entry larger than 1Mb but smaller than 5Mb", assert =>
77 {
78 var testDataOver1Mb = new Array(30000);
79 testReadWrite(testDataOver1Mb, "testFile", assert);
80 expect(2);
81 });
82
83 test("Test writing entry larger than 5Mb", assert =>
84 {
85 var testDataOver5Mb = new Array(300000);
86 testReadWrite(testDataOver5Mb, "testFile", assert);
87 expect(2);
88 });
89 })();
OLDNEW
« lib/io.js ('K') | « metadata.common ('k') | safari/ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld