OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var kHundredChars = ''; |
| 6 var kTestFileName = 'test.txt'; |
| 7 |
| 8 for (var i = 0; i < 10; i++) { |
| 9 kHundredChars += '0123456789'; |
| 10 } |
| 11 |
| 12 function FileSystemWriteError() { |
| 13 chrome.test.fail('Filesystem write error'); |
| 14 } |
| 15 |
| 16 // Appends 50 bytes of data to the file. |
| 17 function AppendDataToFile(fileEntry, numChars) { |
| 18 fileEntry.createWriter(function(fileWriter) { |
| 19 |
| 20 fileWriter.onwriteend = function(e) { |
| 21 chrome.test.sendMessage('write_complete', null); |
| 22 chrome.test.succeed(); |
| 23 chrome.app.window.current().close(); |
| 24 }; |
| 25 |
| 26 fileWriter.onerror = function(e) { |
| 27 FileSystemWriteError(); |
| 28 }; |
| 29 |
| 30 fileWriter.seek(fileWriter.length); |
| 31 var str = ''; |
| 32 |
| 33 // Avoid many loops for large data packets. |
| 34 var iterations = Math.floor(numChars / 100); |
| 35 for (var i = 0; i < iterations; ++i) { |
| 36 str += kHundredChars; |
| 37 } |
| 38 |
| 39 iterations = numChars % 100; |
| 40 for (var i = 0; i < iterations; ++i) { |
| 41 str += 'a'; |
| 42 } |
| 43 |
| 44 var blob = new Blob([str], {type: 'text/plain'}); |
| 45 fileWriter.write(blob); |
| 46 }); |
| 47 } |
| 48 |
| 49 function WriteData(numChars) { |
| 50 window.webkitRequestFileSystem( |
| 51 PERSISTENT, |
| 52 16384, |
| 53 function(fs) { |
| 54 fs.root.getFile( |
| 55 kTestFileName, |
| 56 {create: true}, |
| 57 function(fileEntry) { |
| 58 AppendDataToFile(fileEntry, numChars); |
| 59 }, |
| 60 FileSystemWriteError); |
| 61 }, FileSystemWriteError); |
| 62 } |
| 63 |
| 64 onload = function() { |
| 65 chrome.test.sendMessage('launched', function(reply) { |
| 66 var numChars = parseInt(reply); |
| 67 if (isNaN(numChars)) { |
| 68 chrome.test.fail('Expected number of chars from browser'); |
| 69 return; |
| 70 } |
| 71 |
| 72 WriteData(numChars); |
| 73 }); |
| 74 }; |
OLD | NEW |