Commit dec3452b authored by Chris Mumford's avatar Chris Mumford

Added file reading to File API browsertest.

Modified FileSystemBrowserTest.CreateTest so that in addition to
simply creating a file entry it also writes to, and reads from
that entry.

Additionally moved error constants (in tests) from FileError to
DOMException because FileError is undefined.

Bug: none
Change-Id: Id0a5072dce0fe089e887e982700b850d74b68623
Reviewed-on: https://chromium-review.googlesource.com/1142460Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577244}
parent 8ff84a88
......@@ -32,18 +32,18 @@ function getLog()
function fileErrorToString(e)
{
switch (e.code) {
case FileError.QUOTA_EXCEEDED_ERR:
case DOMException.QUOTA_EXCEEDED_ERR:
return 'QUOTA_EXCEEDED_ERR';
case FileError.NOT_FOUND_ERR:
case DOMException.NOT_FOUND_ERR:
return 'NOT_FOUND_ERR';
case FileError.SECURITY_ERR:
case DOMException.SECURITY_ERR:
return 'SECURITY_ERR';
case FileError.INVALID_MODIFICATION_ERR:
case DOMException.INVALID_MODIFICATION_ERR:
return 'INVALID_MODIFICATION_ERR';
case FileError.INVALID_STATE_ERR:
case DOMException.INVALID_STATE_ERR:
return 'INVALID_STATE_ERR';
default:
return 'Unknown Error';
return 'Unknown Error (' + e + ')';
}
}
......
......@@ -2,10 +2,68 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var filename = 'test.exe';
function readFile(fs)
{
debug('Reading file.');
fs.root.getFile(filename, {create:false},
function(fileEntry) {
fileEntry.file(
function(blob) {
var reader = new FileReader();
reader.onloadend = function(e) {
if (e.loaded == 4) {
done();
} else {
fail('Incorrect read size: ' + e.loaded);
}
};
reader.onerror = function(e) {
fail('Read error:' + fileErrorToString(e));
};
reader.readAsArrayBuffer(blob);
},
function(e) { fail('read:' + fileErrorToString(e)); });
},
function(e) { fail('getFile:' + fileErrorToString(e)); });
}
function writeFile(fs)
{
debug('Creating file.');
fs.root.getFile(filename, {create:true, exclusive:true},
function(fileEntry) {
fileEntry.createWriter(
function(writer) {
writer.onwriteend = function(e) {
readFile(fs);
}
writer.onerror = function(e) {
fail('Write:' + fileErrorToString(e));
};
var blob = new Blob([new Uint8Array([1, 2, 3, 4])],
{type:'application/octet-stream'});
writer.write(blob);
},
function(e) { fail('createWriter:' + fileErrorToString(e)); });
},
function(e) { fail('getFile:' + fileErrorToString(e)); });
}
function requestFileSystemSuccess(fs)
{
fs.root.getFile('foo', {create: true, exclusive: false}, done,
function(e) { fail('Open:' + fileErrorToString(e)); } );
var fileDeleted = function() {
writeFile(fs);
};
fs.root.getFile( filename, {create:false},
function(fileEntry) {
fileEntry.remove(fileDeleted, function(e) {
fail('getFile:' + fileErrorToString(e));
});
},
fileDeleted);
}
function test()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment