Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* Copyright (C) 2006-2016 Eyeo GmbH | 1 /* Copyright (C) 2006-2016 Eyeo GmbH |
2 * | 2 * |
3 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 4 * it under the terms of the GNU General Public License version 3 as |
5 * published by the Free Software Foundation. | 5 * published by the Free Software Foundation. |
6 * | 6 * |
7 * Adblock Plus is distributed in the hope that it will be useful, | 7 * Adblock Plus is distributed in the hope that it will be useful, |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 * GNU General Public License for more details. | 10 * GNU General Public License for more details. |
11 * | 11 * |
12 * You should have received a copy of the GNU General Public License | 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/>. | 13 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
14 */ | 14 */ |
15 | 15 |
16 | 16 |
17 (function() | 17 (function() |
18 { | 18 { |
19 var IO = require("io").IO; | 19 var IO = require("io").IO; |
kzar
2016/08/22 15:38:33
You're requiring the same module twice here, I don
Oleksandr
2016/08/31 21:54:36
Done.
| |
20 var io = require("io"); | 20 module("IO validation", { |
21 module("IO validation"); | 21 afterEach: function() |
22 | 22 { |
23 test("Test writing entry larger than 1Mb but smaller than 5Mb", function(asser t) | 23 if (typeof browser == "undefined") |
kzar
2016/08/22 15:38:33
Nit: If we're just supporting Edge anyway I guess
Oleksandr
2016/08/31 21:54:36
Done.
| |
24 { | 24 ext.storage.remove("testfile"); |
25 var testDataOver1Mb = new Array(30000); | 25 else |
26 testReadWrite(testDataOver1Mb, "testFile1Mb", assert); | 26 window.localStorage.removeItem("testfile"); |
27 expect(2); | 27 } |
28 }); | |
29 | |
30 test("Test writing entry larger than 5Mb", function(assert) | |
31 { | |
32 var testDataOver5Mb = new Array(300000); | |
kzar
2016/08/22 15:38:33
Indentation seems wrong, should be two spaces.
Oleksandr
2016/08/31 21:54:36
Done.
| |
33 testReadWrite(testDataOver5Mb, "testFile5Mb", assert); | |
34 expect(2); | |
35 }); | 28 }); |
36 | 29 |
37 function DummyParser() | 30 function DummyParser() |
38 { | 31 { |
39 readData = new Array(); | 32 readData = []; |
40 }; | 33 }; |
34 | |
41 DummyParser.prototype = | 35 DummyParser.prototype = |
42 { | 36 { |
43 readData: new Array(), | 37 readData: [], |
kzar
2016/08/22 15:38:33
Why not array literal? (Same elsewhere.)
Oleksandr
2016/08/31 21:54:36
Done.
| |
44 process: function (line) { | 38 process: function (line) |
45 this.readData.push(line); | 39 { |
46 } | 40 this.readData.push(line); |
41 } | |
47 }; | 42 }; |
48 | 43 |
49 function testReadWrite(data, fileName, assert) | 44 function testReadWrite(data, fileName, assert) |
kzar
2016/08/22 15:38:33
Please put the testReadWrite function above where
| |
50 { | 45 { |
51 // For debugging purposes clear the storage | 46 var fileWritten = assert.async(); |
kzar
2016/08/22 15:38:32
Will this trash the user's saved filters? Also thi
Oleksandr
2016/08/31 21:54:36
This was just a comment I forgot to remove. The co
| |
52 var fileWritten = assert.async(); | 47 for (var index = 0; index < data.length; index++) |
53 for (var index = 0; index < data.length; index++) { | 48 data[index] = "test string " + index; |
54 data[index] = "test string " + index; | 49 IO.writeToFile(IO.resolveFilePath(fileName), data, () => {}); |
55 } | 50 setTimeout(function() |
56 IO.writeToFile(IO.resolveFilePath(fileName), data, | 51 { |
57 function() { }); | 52 fileWritten(); |
58 setTimeout(function() | |
59 { | |
60 fileWritten(); | |
61 | 53 |
62 var fileRead = assert.async(); | 54 var fileRead = assert.async(); |
63 var dummyParser = new DummyParser(); | 55 var dummyParser = new DummyParser(); |
64 dummyParser.readData = []; | 56 dummyParser.readData = []; |
65 IO.readFromFile(IO.resolveFilePath(fileName), | 57 IO.readFromFile( |
kzar
2016/08/22 15:38:33
Nit: Mind indenting this like so?
IO.readFromFile
Oleksandr
2016/08/31 21:54:36
Done.
| |
66 dummyParser, | 58 IO.resolveFilePath(fileName), |
67 function() | 59 dummyParser, |
68 { | 60 function() |
69 equal(dummyParser.readData.length, data.length, | 61 { |
70 "Check if read entry is the same size as written"); | 62 equal( |
71 equal(dummyParser.readData[20000], data[20000], | 63 dummyParser.readData.length, data.length, |
72 "Check if read entry element is the same as written" ); | 64 "Check if read entry is the same size as written" |
73 fileRead(); | 65 ); |
74 }); | 66 equal( |
75 | 67 dummyParser.readData[20000], data[20000], |
76 }, | 68 "Check if read entry element is the same as written" |
77 1000); | 69 ); |
78 | 70 fileRead(); |
71 }); | |
72 }, | |
73 1000); | |
79 } | 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 }); | |
80 })(); | 89 })(); |
LEFT | RIGHT |