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

Side by Side Diff: chrome/content/tests/io.js

Issue 5349448087502848: Issue 192 - Clean up from #153 (Closed)
Patch Set: Created April 14, 2014, 6:56 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 module("I/O"); 3 module("I/O");
4 4
5 let {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", null); 5 let {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", null);
6 let file = FileUtils.getFile("TmpD", ["adblockplustests-test1.txt"]); 6 let file = FileUtils.getFile("TmpD", ["adblockplustests-test1.txt"]);
7 let fileRenamed = FileUtils.getFile("TmpD", ["adblockplustests-test2.txt"]) 7 let fileRenamed = FileUtils.getFile("TmpD", ["adblockplustests-test2.txt"])
8 let currentTest = -1; 8 let currentTest = -1;
9 9
10 let tests = [ 10 let tests = [
(...skipping 21 matching lines...) Expand all
32 { 32 {
33 currentTest++; 33 currentTest++;
34 if (currentTest < tests.length) 34 if (currentTest < tests.length)
35 tests[currentTest](); 35 tests[currentTest]();
36 else 36 else
37 start(); 37 start();
38 } 38 }
39 39
40 function write(file) 40 function write(file)
41 { 41 {
42 IO.writeToFile(file, true, function dataGenerator() 42 IO.writeToFile(file, function dataGenerator()
43 { 43 {
44 for (let i = 0; i < 10000; i++) 44 for (let i = 0; i < 10000; i++)
45 yield "\u1234" + i + "\uffff\x00"; 45 yield "\u1234" + i + "\uffff\x00";
46 }(), function writeCallback(e) 46 }(), function writeCallback(e)
47 { 47 {
48 equal(e && e.toString(), null, "Write succeeded"); 48 equal(e && e.toString(), null, "Write succeeded");
49 runNextTest(); 49 runNextTest();
50 }, null); 50 }, null);
51 } 51 }
52 52
53 function read(file) 53 function read(file)
54 { 54 {
55 let eofReceived = false; 55 let eofReceived = false;
56 let i = 0; 56 let i = 0;
57 IO.readFromFile(file, true, { 57 IO.readFromFile(file, {
58 process: function(line) 58 process: function(line)
59 { 59 {
60 if (eofReceived) 60 if (eofReceived)
61 ok(false, "No lines received after EOF"); 61 ok(false, "No lines received after EOF");
62 62
63 if (line === null) 63 if (line === null)
64 { 64 {
65 eofReceived = true; 65 eofReceived = true;
66 equal(i, 10000, "10000 lines received before EOF"); 66 equal(i, 10000, "10000 lines received before EOF");
67 } 67 }
68 else 68 else
69 { 69 {
70 let expected = "\u1234" + i + "\uffff\x00"; 70 let expected = "\u1234" + i + "\uffff\x00";
71 if (line != expected) 71 if (line != expected)
72 equal(line, expected, "Line " + i + " contents"); 72 equal(line, expected, "Line " + i + " contents");
73 i++; 73 i++;
74 } 74 }
75 } 75 }
76 }, function readCallback(e) 76 }, function readCallback(e)
77 { 77 {
78 equal(e && e.toString(), null, "Read succeeded"); 78 equal(e && e.toString(), null, "Read succeeded");
79 ok(eofReceived, "File processor received EOF indicator before callback was called"); 79 ok(eofReceived, "File processor received EOF indicator before callback was called");
80 runNextTest(); 80 runNextTest();
81 }, null); 81 }, null);
82 } 82 }
83 83
84 function failedRead(file) 84 function failedRead(file)
85 { 85 {
86 IO.readFromFile(file, true, { 86 IO.readFromFile(file, {
87 process: function(line) 87 process: function(line)
88 { 88 {
89 ok(false, "Line received for non-existing file") 89 ok(false, "Line received for non-existing file")
90 } 90 }
91 }, function readCallback(e) 91 }, function readCallback(e)
92 { 92 {
93 ok(e, "Error received reading non-existing file"); 93 ok(e, "Error received reading non-existing file");
94 runNextTest(); 94 runNextTest();
95 }); 95 });
96 } 96 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 149 }
150 runNextTest(); 150 runNextTest();
151 }); 151 });
152 } 152 }
153 153
154 asyncTest("File operations", function() 154 asyncTest("File operations", function()
155 { 155 {
156 runNextTest(); 156 runNextTest();
157 }); 157 });
158 })(); 158 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld