diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-25 20:37:59 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-25 20:37:59 +0000 |
commit | 55d9bed8de248d583bd5770a42c8520e1225162b (patch) | |
tree | 6be27d9ee263e9a475385120a933bcb29fe75a74 /chrome/test | |
parent | e69b903ec57dc0f511598b03d4aae148a56e33bc (diff) | |
download | chromium_src-55d9bed8de248d583bd5770a42c8520e1225162b.zip chromium_src-55d9bed8de248d583bd5770a42c8520e1225162b.tar.gz chromium_src-55d9bed8de248d583bd5770a42c8520e1225162b.tar.bz2 |
Wired local file system support for File API. The local file system provider currently exists for ChromeOS builds only.
This CL exposes new extension permission 'fileSystem' that controls access to individual local file system elements from 3rd party extensions. Another new permission 'fileBrowserPrivate' controls access to following API call that retrieves root DOMFileSystem instance for locally exposed folders:
chrome.fileBrowserPrivate.requestLocalFileSystem(callback)
BUG=chromium-os:11983
TEST=ExtensionApiTest.LocalFileSystem
Review URL: http://codereview.chromium.org/6519040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79451 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
3 files changed, 157 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/api_test/local_filesystem/background.html b/chrome/test/data/extensions/api_test/local_filesystem/background.html new file mode 100644 index 0000000..68d0dec --- /dev/null +++ b/chrome/test/data/extensions/api_test/local_filesystem/background.html @@ -0,0 +1,63 @@ +<script> + var fileSystem = null; + var testDirName = "tmp/test_dir_" + Math.floor(Math.random()*10000); + var testFileName = "test_file_" + Math.floor(Math.random()*10000); + + // Get local FS, create dir with a file in it. + console.log("Requesting local file system..."); + chrome.fileBrowserPrivate.requestLocalFileSystem(getFileSystem); + + function getFileSystem(fs, error) { + if (!fs) { + errorCallback(error); + return; + } + fileSystem = fs; + console.log("DONE requesting local filesystem: " + fileSystem.name); + console.log("Creating directory : " + testDirName); + fileSystem.root.getDirectory(testDirName, {create:true}, + directoryCallback, errorCallback); + } + + function directoryCallback(directory) { + console.log("DONE creating directory: " + directory.fullPath); + directory.getFile(testFileName, {create:true}, fileCallback, errorCallback); + } + + function fileCallback(file) { + console.log("DONE creating file: " + file.fullPath); + + // See if we can access this filesystem and its elements in the tab. + console.log("Opening tab..."); + chrome.tabs.create({ + url: "tab.html#" + escape(testDirName + "/" + testFileName) + }); + } + +function errorCallback(e) { + var msg = ''; + switch (e.code) { + case FileError.QUOTA_EXCEEDED_ERR: + msg = 'QUOTA_EXCEEDED_ERR'; + break; + case FileError.NOT_FOUND_ERR: + msg = 'NOT_FOUND_ERR'; + break; + case FileError.SECURITY_ERR: + msg = 'SECURITY_ERR'; + break; + case FileError.INVALID_MODIFICATION_ERR: + msg = 'INVALID_MODIFICATION_ERR'; + break; + case FileError.INVALID_STATE_ERR: + msg = 'INVALID_STATE_ERR'; + break; + default: + msg = 'Unknown Error'; + break; + }; + chrome.test.fail("Got unexpected error: " + msg); + console.log('Error: ' + msg); + alert('Error: ' + msg); +} +</script> diff --git a/chrome/test/data/extensions/api_test/local_filesystem/manifest.json b/chrome/test/data/extensions/api_test/local_filesystem/manifest.json new file mode 100644 index 0000000..367a97a --- /dev/null +++ b/chrome/test/data/extensions/api_test/local_filesystem/manifest.json @@ -0,0 +1,14 @@ +{ + "key": "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDJ5+2VmV02HP3jkMhxbp2yuyzf4K4JsffgCf8zsPljLVV2A+JXGj0TbvzvDP3RDCKC5qPMprQkoYlKVW2b6H0kQ8dNmZsjxMqEz/ZDx4Z6/VvbMaz8pP+dENs5Io5XlG5Op2nsJF+y+LqbX6qbff9D/s4fTWyqKillpJN+48qs0wIBIw==", + "name": "chromeos.local filesystem", + "version": "0.1", + "description": "Local filesystem access sanity test", + "background_page": "background.html", + "permissions": [ + "tabs", + "unlimitedStorage", + "fileSystem", + "fileBrowserPrivate" + ] +} + diff --git a/chrome/test/data/extensions/api_test/local_filesystem/tab.html b/chrome/test/data/extensions/api_test/local_filesystem/tab.html new file mode 100644 index 0000000..0caad48 --- /dev/null +++ b/chrome/test/data/extensions/api_test/local_filesystem/tab.html @@ -0,0 +1,80 @@ +<script> +var fileSystem = null; +var testDirName = null; +var testFileName = null; + +function errorCallback(e) { + var msg = ''; + switch (e.code) { + case FileError.QUOTA_EXCEEDED_ERR: + msg = 'QUOTA_EXCEEDED_ERR'; + break; + case FileError.NOT_FOUND_ERR: + msg = 'NOT_FOUND_ERR'; + break; + case FileError.SECURITY_ERR: + msg = 'SECURITY_ERR'; + break; + case FileError.INVALID_MODIFICATION_ERR: + msg = 'INVALID_MODIFICATION_ERR'; + break; + case FileError.INVALID_STATE_ERR: + msg = 'INVALID_STATE_ERR'; + break; + default: + msg = 'Unknown Error'; + break; + }; + chrome.test.fail("Got unexpected error: " + msg); + console.log('Error: ' + msg); + alert('Error: ' + msg); +} + +function successCallback(entry) { + chrome.test.succeed(); +} + +function successEntryCallback(entry) { + console.log("Deleting dir : " + testDirName); + fileSystem.root.getDirectory(testDirName, {create:false}, + function(directory) { + // Do clean-up. (Assume the tab won't be reloaded in testing.) + directory.removeRecursively(successCallback, errorCallback); + }, errorCallback); +} + +chrome.test.runTests([function tab() { + // Get dir, file name. + var loc = window.location.href; + console.log("Opening tab " + loc); + if (loc.indexOf("#") == -1 ) { + chrome.test.fail("Missing params"); + return; + } + loc = unescape(loc.substr(loc.indexOf("#") + 1)); + if (loc.lastIndexOf("/") == -1 ) { + chrome.test.fail("Bad params"); + return; + } + testDirName = loc.substr(0, loc.lastIndexOf("/")); + testFileName = loc.substr(loc.lastIndexOf("/") + 1); + + console.log("Requesting local file system..."); + chrome.fileBrowserPrivate.requestLocalFileSystem(function(fs, error) { + if (!fs) { + errorCallback(error); + return; + } + fileSystem = fs; + console.log("DONE requesting filesystem: " + fileSystem.name); + // Read directory content. + console.log("Opening file : " + testDirName+'/'+testFileName); + fileSystem.root.getDirectory(testDirName, {create: false}, + function(dirEntry) { + console.log('DONE opening directory: ' + dirEntry.fullPath); + fileSystem.root.getFile(testDirName+'/'+testFileName, {create:false}, + successEntryCallback, errorCallback); + }, errorCallback); + }); +}]); +</script> |