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: Cleanup Created Aug. 25, 2016, 1:57 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",
kzar 2016/08/30 14:13:03 Nit: We would normally have the opening bracket on
Oleksandr 2016/08/31 21:54:38 Done.
21 {
22 afterEach: function()
23 {
24 if (typeof browser != "undefined")
kzar 2016/08/30 14:13:03 Nit: Mind checking for `== "undefined"` and switch
Oleksandr 2016/08/31 21:54:38 Done.
25 window.localStorage.removeItem("testfile");
26 else
27 ext.storage.remove("testfile");
28 }
29 });
30
31 function DummyParser()
32 {
33 readData = [];
34 };
35
36 DummyParser.prototype =
37 {
38 readData: [],
39 process: function (line)
40 {
41 this.readData.push(line);
42 }
43 };
44
45 function testReadWrite(data, fileName, assert)
46 {
47 var fileWritten = assert.async();
48 for (var index = 0; index < data.length; index++)
49 {
kzar 2016/08/30 14:13:03 Nit: No braces required here.
Oleksandr 2016/08/31 21:54:37 Done.
50 data[index] = "test string " + index;
51 }
52 IO.writeToFile(IO.resolveFilePath(fileName), data, () => {});
53 setTimeout(function()
54 {
55 fileWritten();
56
57 var fileRead = assert.async();
58 var dummyParser = new DummyParser();
59 dummyParser.readData = [];
60 IO.readFromFile(
61 IO.resolveFilePath(fileName),
62 dummyParser,
63 function()
64 {
65 equal(dummyParser.readData.length, data.length,
kzar 2016/08/30 14:13:03 Nit: This is indented incorrectly. Please could yo
Oleksandr 2016/08/31 21:54:37 Done.
66 "Check if read entry is the same size as written");
67 equal(dummyParser.readData[20000], data[20000],
68 "Check if read entry element is the same as written");
69 fileRead();
70 });
71 },
72 1000);
73 }
74
75 test("Test writing entry larger than 1Mb but smaller than 5Mb", (assert) =>
kzar 2016/08/30 14:13:03 Nit: The functions with one arguments using this s
Oleksandr 2016/08/31 21:54:37 Done.
76 {
77 var testDataOver1Mb = new Array(30000);
78 testReadWrite(testDataOver1Mb, "testFile", assert);
79 expect(2);
80 });
81
82 test("Test writing entry larger than 5Mb", (assert) =>
83 {
84 var testDataOver5Mb = new Array(300000);
85 testReadWrite(testDataOver5Mb, "testFile", assert);
86 expect(2);
87 });
88 })();
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