2fa8abd2a7adc06dbecff83f068330944048a7a5
[WebKit-https.git] / LayoutTests / fast / filesystem / resources / file-writer-truncate-extend.js
1 if (this.importScripts) {
2     importScripts('fs-worker-common.js');
3     importScripts('file-writer-utils.js');
4 }
5
6 description("Test of extending a file using truncate().");
7
8 function onTestSucceeded()
9 {
10     testPassed("Truncate extension verified.");
11     cleanUp();
12 }
13
14 function truncateToExtend(fileEntry, fileWriter, contents, onSuccess)
15 {
16     var extension = 5;
17     var lengthChecker = function() {
18         verifyFileLength(fileEntry, contents.length + extension, onSuccess);
19     };
20     var extensionChecker = function() {
21         verifyByteRangeIsZeroes(fileEntry, contents.length, extension, lengthChecker);
22     };
23     fileWriter.onwrite = function() {
24         verifyByteRangeAsString(fileEntry, 0, contents, extensionChecker);
25     };
26     fileWriter.truncate(contents.length + extension);
27 }
28
29 function runTest(fileEntry, fileWriter) {
30     var contents = "Lorem ipsum";
31     writeString(fileEntry, fileWriter, 0, contents,
32                 function() {
33                     truncateToExtend(fileEntry, fileWriter, contents, onTestSucceeded);
34                 });
35 }
36
37 var jsTestIsAsync = true;
38 setupAndRunTest(1024, 'file-writer-truncate-extend', runTest);