Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / filesystem / file-metadata-after-write.html
blob7191813362589d6a11aafbb8dd74c9b61b1cd682
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
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>
9 <script>
11 if (window.testRunner) {
12 testRunner.dumpAsText();
13 testRunner.waitUntilDone();
16 var fileEntryForCleanup;
17 var testFile;
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);
28 });
29 }, onError);
30 }, onError);
32 function onWrittenFile(entry, file) {
33 testFile = 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');
41 cleanup();
42 }, onError);
43 });
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;
54 });
57 function log(text)
59 var console = document.getElementById('console');
60 console.appendChild(document.createTextNode(text));
61 console.appendChild(document.createElement('br'));
64 function onError(e)
66 log('ERROR: ' + e.name);
67 console.log(e);
68 cleanup();
71 function cleanup()
73 if (fileEntryForCleanup) {
74 fileEntryForCleanup.remove(endTest, endTest);
75 return;
77 endTest();
80 function endTest()
82 if (testRunner)
83 testRunner.notifyDone();
86 </script>
87 </body>
88 </html>