4 <script src=
"../../resources/js-test.js"></script>
7 <div>This verifies File.size (for a file from FileSystem API) always returns the fresh size even after the file is modified.
</div>
8 <div id='console'
></div>
11 if (window
.testRunner
) {
12 testRunner
.dumpAsText();
13 testRunner
.waitUntilDone();
16 var fileEntryForCleanup
;
18 var testText1
= '1234567890';
19 var testText2
= 'abcdefghijklmnopqrstuvwxyz';
21 webkitRequestFileSystem(
22 window
.TEMPORARY
, 100, function(fs
) {
23 fs
.root
.getFile('test', {create
:true}, function(entry
) {
24 fileEntryForCleanup
= entry
;
25 writeTextToFile(entry
, testText1
, function() {
26 log('Write succeeded.');
27 entry
.file(onWrittenFile
.bind(this, entry
), onError
);
32 function onWrittenFile(entry
, file
) {
34 shouldBe('testFile.size', 'testText1.length');
35 // Write into this file again.
36 writeTextToFile(entry
, testText2
, function() {
37 log('Write succeeded.');
38 entry
.file(function() {
39 // The file size should be updated.
40 shouldBe('testFile.size', 'testText2.length');
46 function writeTextToFile(entry
, contents
, successCallback
)
48 log('Writing ' + contents
+ ' to the file...');
49 entry
.createWriter(function(writer
) {
50 log('Created a writer.');
51 writer
.write(new Blob([contents
], {type
:'text/plain'}));
52 writer
.onwriteend
= successCallback
;
53 writer
.onerror
= onError
;
59 var console
= document
.getElementById('console');
60 console
.appendChild(document
.createTextNode(text
));
61 console
.appendChild(document
.createElement('br'));
66 log('ERROR: ' + e
.name
);
73 if (fileEntryForCleanup
) {
74 fileEntryForCleanup
.remove(endTest
, endTest
);
83 testRunner
.notifyDone();