2 "testReadingNonExistentFileAsArrayBuffer",
3 "testReadingNonExistentFileAsBinaryString",
4 "testReadingNonExistentFileAsText",
5 "testReadingNonExistentFileAsDataURL",
6 "testReadingEmptyFileAsArrayBuffer",
7 "testReadingEmptyFileAsBinaryString",
8 "testReadingEmptyFileAsText",
9 "testReadingEmptyFileAsDataURL",
10 "testReadingUTF8EncodedFileAsArrayBuffer",
11 "testReadingUTF8EncodedFileAsBinaryString",
12 "testReadingBinaryFileAsArrayBuffer",
13 "testReadingBinaryFileAsBinaryString",
14 "testReadingUTF8EncodedFileAsText",
15 "testReadingUTF16BEBOMEncodedFileAsText",
16 "testReadingUTF16LEBOMEncodedFileAsText",
17 "testReadingUTF8BOMEncodedFileAsText",
18 "testReadingUTF16BEEncodedFileAsTextWithUTF16Encoding",
19 "testReadingUTF16BEBOMEncodedFileAsTextWithUTF8Encoding",
20 "testReadingUTF16BEBOMEncodedFileAsTextWithInvalidEncoding",
21 "testReadingUTF8EncodedFileAsDataURL",
23 var asyncTestCases
= [
25 "testReadAgainAfterSuccessfulReadStep1",
26 "testReadAgainAfterSuccessfulReadStep2",
27 "testReadAgainAfterFailedReadStep1",
28 "testReadAgainAfterFailedReadStep2",
29 "testResultBeforeRead"
32 var initialized
= false;
34 function ensureInitialized()
40 testCases
= testCases
.concat(asyncTestCases
);
43 function runNextTest(testFiles
)
46 if (testIndex
< testCases
.length
) {
48 self
[testCases
[testIndex
- 1]](testFiles
);
54 function testReadingNonExistentFileAsArrayBuffer(testFiles
)
56 log("Test reading a non-existent file as array buffer");
57 readBlobAsArrayBuffer(testFiles
, testFiles
['non-existent']);
60 function testReadingNonExistentFileAsBinaryString(testFiles
)
62 log("Test reading a non-existent file as binary string");
63 readBlobAsBinaryString(testFiles
, testFiles
['non-existent']);
66 function testReadingNonExistentFileAsText(testFiles
)
68 log("Test reading a non-existent file as text");
69 readBlobAsText(testFiles
, testFiles
['non-existent']);
72 function testReadingNonExistentFileAsDataURL(testFiles
)
74 log("Test reading a non-existent file as data URL");
75 readBlobAsDataURL(testFiles
, testFiles
['non-existent']);
78 function testReadingEmptyFileAsArrayBuffer(testFiles
)
80 log("Test reading an empty file as array buffer");
81 readBlobAsArrayBuffer(testFiles
, testFiles
['empty-file']);
84 function testReadingEmptyFileAsBinaryString(testFiles
)
86 log("Test reading an empty file as binary string");
87 readBlobAsBinaryString(testFiles
, testFiles
['empty-file']);
90 function testReadingEmptyFileAsText(testFiles
)
92 log("Test reading an empty file as text");
93 readBlobAsText(testFiles
, testFiles
['empty-file']);
96 function testReadingEmptyFileAsDataURL(testFiles
)
98 log("Test reading an empty file as data URL");
99 readBlobAsDataURL(testFiles
, testFiles
['empty-file']);
102 function testReadingUTF8EncodedFileAsArrayBuffer(testFiles
)
104 log("Test reading a UTF-8 file as array buffer");
105 readBlobAsArrayBuffer(testFiles
, testFiles
['UTF8-file']);
108 function testReadingUTF8EncodedFileAsBinaryString(testFiles
)
110 log("Test reading a UTF-8 file as binary string");
111 readBlobAsBinaryString(testFiles
, testFiles
['UTF8-file']);
114 function testReadingBinaryFileAsArrayBuffer(testFiles
)
116 log("Test reading a binary file as array buffer");
117 readBlobAsArrayBuffer(testFiles
, testFiles
['binary-file']);
120 function testReadingBinaryFileAsBinaryString(testFiles
)
122 log("Test reading a binary file as binary string");
123 readBlobAsBinaryString(testFiles
, testFiles
['binary-file']);
126 function testReadingUTF8EncodedFileAsText(testFiles
)
128 log("Test reading a UTF-8 file as text");
129 readBlobAsText(testFiles
, testFiles
['UTF8-file']);
132 function testReadingUTF16BEBOMEncodedFileAsText(testFiles
)
134 log("Test reading a UTF-16BE BOM file as text");
135 readBlobAsText(testFiles
, testFiles
['UTF16BE-BOM-file']);
138 function testReadingUTF16LEBOMEncodedFileAsText(testFiles
)
140 log("Test reading a UTF-16LE BOM file as text");
141 readBlobAsText(testFiles
, testFiles
['UTF16LE-BOM-file']);
144 function testReadingUTF8BOMEncodedFileAsText(testFiles
)
146 log("Test reading a UTF-8 BOM file as text");
147 readBlobAsText(testFiles
, testFiles
['UTF8-BOM-file']);
150 function testReadingUTF16BEEncodedFileAsTextWithUTF16Encoding(testFiles
)
152 log("Test reading a UTF-16BE file as text with UTF-16BE encoding");
153 readBlobAsText(testFiles
, testFiles
['UTF16BE-file'], "UTF-16BE");
156 function testReadingUTF16BEBOMEncodedFileAsTextWithUTF8Encoding(testFiles
)
158 log("Test reading a UTF-16BE BOM file as text with UTF8 encoding");
159 readBlobAsText(testFiles
, testFiles
['UTF16BE-BOM-file'], "UTF-8");
162 function testReadingUTF16BEBOMEncodedFileAsTextWithInvalidEncoding(testFiles
)
164 log("Test reading a UTF-16BE BOM file as text with invalid encoding");
165 readBlobAsText(testFiles
, testFiles
['UTF16BE-BOM-file'], "AnyInvalidEncoding");
168 function testReadingUTF8EncodedFileAsDataURL(testFiles
)
170 log("Test reading a UTF-8 file as data URL");
171 readBlobAsDataURL(testFiles
, testFiles
['UTF8-file']);
174 function testMultipleReads(testFiles
)
176 log("Test calling multiple concurrent read methods");
177 var reader
= createReaderAsync(testFiles
);
178 reader
.readAsDataURL(testFiles
['UTF8-file']);
180 reader
.readAsArrayBuffer(testFiles
['UTF8-file']);
182 log("Received exception, code: " + error
.code
+ ", name: " + error
.name
+ ", message: " + error
.message
);
185 reader
.readAsBinaryString(testFiles
['UTF8-file']);
187 log("Received exception, code: " + error
.code
+ ", name: " + error
.name
+ ", message: " + error
.message
);
190 reader
.readAsText(testFiles
['UTF8-file']);
192 log("Received exception, code: " + error
.code
+ ", name: " + error
.name
+ ", message: " + error
.message
);
195 reader
.readAsDataURL(testFiles
['UTF8-file']);
197 log("Received exception, code: " + error
.code
+ ", name: " + error
.name
+ ", message: " + error
.message
);
201 var readerToTestReread
;
203 function testReadAgainAfterSuccessfulReadStep1(testFiles
)
205 log("Test reading again after successful read");
206 readerToTestReread
= createReaderAsync(testFiles
);
207 readerToTestReread
.readAsBinaryString(testFiles
['UTF8-file']);
210 function testReadAgainAfterSuccessfulReadStep2(testFiles
)
212 readerToTestReread
.readAsDataURL(testFiles
['UTF8-file']);
213 log("readyState after recalling read method: " + readerToTestReread
.readyState
);
214 log("result after recalling read method: " + readerToTestReread
.result
);
215 log("error after recalling read method: " + readerToTestReread
.error
);
218 function testReadAgainAfterFailedReadStep1(testFiles
)
220 log("Test reading again after failed read");
221 readerToTestReread
= createReaderAsync(testFiles
);
222 readerToTestReread
.readAsBinaryString(testFiles
['non-existent']);
225 function testReadAgainAfterFailedReadStep2(testFiles
)
227 readerToTestReread
.readAsDataURL(testFiles
['UTF8-file']);
228 log("readyState after recalling read method: " + readerToTestReread
.readyState
);
229 log("result after recalling read method: " + readerToTestReread
.result
);
230 log("error after recalling read method: " + readerToTestReread
.error
);
233 function testResultBeforeRead(testFiles
)
235 log("Test result before reading method");
236 var reader
= createReaderAsync(testFiles
);
237 log("result before reading method: " + reader
.result
);
238 reader
.readAsBinaryString(testFiles
['empty-file']);