1 // Copyright (c) 2012 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.
5 var textToWrite = 'def';
7 function truncateAndWriteToFile(writableEntry, callback) {
8 writableEntry.createWriter(function(fileWriter) {
9 fileWriter.onerror = function(e) {
10 console.error("Couldn't write file: " + e.toString());
12 fileWriter.onwriteend = function(e) {
13 fileWriter.onwriteend = function(e) {
16 var blob = new Blob([textToWrite], {type: 'text/plain'});
17 fileWriter.write(blob);
19 fileWriter.truncate(0);
23 chrome.app.runtime.onLaunched.addListener(function() {
24 chrome.app.window.create('index.html', {width: 100, height: 100},
26 var fs = win.contentWindow.chrome.fileSystem;
27 fs.chooseEntry({type: 'openFile'}, function(entry) {
28 chrome.fileSystem.retainEntry(entry);
29 fs.getWritableEntry(entry, function(writableEntry) {
30 chrome.fileSystem.retainEntry(writableEntry);
31 truncateAndWriteToFile(writableEntry, function() {
32 chrome.test.sendMessage('fileWritten');