| 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; |
| 20 module("IO validation", | 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() | 21 afterEach: function() |
| 23 { | 22 { |
| 24 if (typeof browser != "undefined") | 23 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.
| |
| 24 ext.storage.remove("testfile"); | |
| 25 else | |
| 25 window.localStorage.removeItem("testfile"); | 26 window.localStorage.removeItem("testfile"); |
| 26 else | |
| 27 ext.storage.remove("testfile"); | |
| 28 } | 27 } |
| 29 }); | 28 }); |
| 30 | 29 |
| 31 function DummyParser() | 30 function DummyParser() |
| 32 { | 31 { |
| 33 readData = []; | 32 readData = []; |
| 34 }; | 33 }; |
| 35 | 34 |
| 36 DummyParser.prototype = | 35 DummyParser.prototype = |
| 37 { | 36 { |
| 38 readData: [], | 37 readData: [], |
| 39 process: function (line) | 38 process: function (line) |
| 40 { | 39 { |
| 41 this.readData.push(line); | 40 this.readData.push(line); |
| 42 } | 41 } |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 function testReadWrite(data, fileName, assert) | 44 function testReadWrite(data, fileName, assert) |
| 46 { | 45 { |
| 47 var fileWritten = assert.async(); | 46 var fileWritten = assert.async(); |
| 48 for (var index = 0; index < data.length; index++) | 47 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; | 48 data[index] = "test string " + index; |
| 51 } | |
| 52 IO.writeToFile(IO.resolveFilePath(fileName), data, () => {}); | 49 IO.writeToFile(IO.resolveFilePath(fileName), data, () => {}); |
| 53 setTimeout(function() | 50 setTimeout(function() |
| 54 { | 51 { |
| 55 fileWritten(); | 52 fileWritten(); |
| 56 | 53 |
| 57 var fileRead = assert.async(); | 54 var fileRead = assert.async(); |
| 58 var dummyParser = new DummyParser(); | 55 var dummyParser = new DummyParser(); |
| 59 dummyParser.readData = []; | 56 dummyParser.readData = []; |
| 60 IO.readFromFile( | 57 IO.readFromFile( |
| 61 IO.resolveFilePath(fileName), | 58 IO.resolveFilePath(fileName), |
| 62 dummyParser, | 59 dummyParser, |
| 63 function() | 60 function() |
| 64 { | 61 { |
| 65 equal(dummyParser.readData.length, data.length, | 62 equal( |
|
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"); | 63 dummyParser.readData.length, data.length, |
| 67 equal(dummyParser.readData[20000], data[20000], | 64 "Check if read entry is the same size as written" |
| 68 "Check if read entry element is the same as written"); | 65 ); |
| 66 equal( | |
| 67 dummyParser.readData[20000], data[20000], | |
| 68 "Check if read entry element is the same as written" | |
| 69 ); | |
| 69 fileRead(); | 70 fileRead(); |
| 70 }); | 71 }); |
| 71 }, | 72 }, |
| 72 1000); | 73 1000); |
| 73 } | 74 } |
| 74 | 75 |
| 75 test("Test writing entry larger than 1Mb but smaller than 5Mb", (assert) => | 76 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 { |
| 77 var testDataOver1Mb = new Array(30000); | 78 var testDataOver1Mb = new Array(30000); |
| 78 testReadWrite(testDataOver1Mb, "testFile", assert); | 79 testReadWrite(testDataOver1Mb, "testFile", assert); |
| 79 expect(2); | 80 expect(2); |
| 80 }); | 81 }); |
| 81 | 82 |
| 82 test("Test writing entry larger than 5Mb", (assert) => | 83 test("Test writing entry larger than 5Mb", assert => |
| 83 { | 84 { |
| 84 var testDataOver5Mb = new Array(300000); | 85 var testDataOver5Mb = new Array(300000); |
| 85 testReadWrite(testDataOver5Mb, "testFile", assert); | 86 testReadWrite(testDataOver5Mb, "testFile", assert); |
| 86 expect(2); | 87 expect(2); |
| 87 }); | 88 }); |
| 88 })(); | 89 })(); |
| LEFT | RIGHT |