OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 chrome.test.runTests([ |
| 6 function openFile() { |
| 7 chrome.fileSystem.chooseFile(chrome.test.callbackPass(function(entry) { |
| 8 chrome.test.assertEq('open_existing.txt', entry.name); |
| 9 // Test that the file can be read. |
| 10 entry.file(chrome.test.callback(function(file) { |
| 11 var reader = new FileReader(); |
| 12 reader.onloadend = chrome.test.callback(function(e) { |
| 13 chrome.test.assertEq(reader.result.indexOf("Can you see me?"), 0); |
| 14 // Test that we cannot write to the file. |
| 15 entry.createWriter(chrome.test.callback(function(fileWriter) { |
| 16 fileWriter.onwriteend = chrome.test.callback(function(e) { |
| 17 if (fileWriter.error) |
| 18 chrome.test.succeed(); |
| 19 else |
| 20 chrome.test.fail("No error while writing without write access"); |
| 21 }); |
| 22 var blob = new Blob(['HoHoHo!'], {type: 'text/plain'}); |
| 23 fileWriter.write(blob); |
| 24 })); |
| 25 }); |
| 26 reader.onerror = chrome.test.callback(function(e) { |
| 27 chrome.test.fail("Error reading file contents."); |
| 28 }); |
| 29 reader.readAsText(file); |
| 30 })); |
| 31 })); |
| 32 } |
| 33 ]); |
OLD | NEW |