Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4990)

Unified Diff: chrome/test/data/extensions/api_test/filebrowser_component/main.html

Issue 6749021: Added new fileBrowserPrivate and fileHandler extension APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/filebrowser_component/main.html
===================================================================
--- chrome/test/data/extensions/api_test/filebrowser_component/main.html (revision 0)
+++ chrome/test/data/extensions/api_test/filebrowser_component/main.html (revision 0)
@@ -0,0 +1,131 @@
+<script>
+
+/*
+This component extension test does the following:
+
+1. Creates a txt file on the local file system with some random text.
+2. Finds a registered task (file item context menu) and invokes it with url
+ of the test file.
+3. Listens for a message from context menu handler and makes sure its payload
+ matches the random text from the test file.
+*/
+
+// The ID of this extension.
+var fileBrowserExtensionId = "ddammdhioacbehjngdmkjcjbnfginlla";
+
+var fileSystem = null;
+var testDirName = "tmp/test_dir_" + Math.floor(Math.random()*10000);
+var testFileName = "test_file_" + Math.floor(Math.random()*10000)+".txt";
+var fileUrl = "filesystem:chrome-extension://" + fileBrowserExtensionId +
+ "/local/" + testDirName + "/" + testFileName;
+
+var randomText = "random file text " + Math.floor(Math.random()*10000);
+
+function onFileSystemFetched(fs) {
+ if (!fs) {
+ errorCallback(chrome.extensions.lastError);
+ return;
+ }
+ fileSystem = fs;
+ console.log("DONE requesting local filesystem: " + fileSystem.name);
+ console.log("Creating directory : " + testDirName);
+ fileSystem.root.getDirectory(testDirName, {create:true},
+ directoryCreateCallback, errorCallback);
+}
+
+function directoryCreateCallback(directory) {
+ console.log("DONE creating directory: " + directory.fullPath);
+ directory.getFile(testFileName, {create:true}, fileCreatedCallback,
+ errorCallback);
+}
+
+function fileCreatedCallback(fileEntry) {
+ console.log("DONE creating file: " + fileEntry.fullPath);
+ fileEntry.createWriter(onGetFileWriter);
+}
+
+function onGetFileWriter(writer) {
+ // Start
+ console.log("Got file writter");
+ writer.onerror = errorCallback;
+ writer.onwrite = onFileWriteCompleted;
+ var bb = new BlobBuilder();
+ bb.append(randomText);
+ writer.write(bb.getBlob('text/plain'));
+}
+
+function onFileWriteCompleted(e) {
+ // Start
+ console.log("DONE writing file content");
+ console.log("Get registered tasks now...");
+ chrome.fileBrowserPrivate.getFileTasks([fileUrl], onGetTasks);
+
+}
+
+function onGetTasks(tasks) {
+ console.log("Tasks: ");
+ console.log(tasks);
+ if (!tasks || !tasks.length) {
+ chrome.test.fail("No tasks registered");
+ return;
+ }
+ console.log("DONE fetching tasks: " + tasks[0].taskId);
+ chrome.fileBrowserPrivate.executeTask(tasks[0].taskId, [fileUrl]);
+}
+
+function errorCallback(e) {
+ var msg = '';
+ if (!e.code) {
+ msg = e.message;
+ } else {
+ 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);
+}
+
+// For simple requests:
+chrome.extension.onRequestExternal.addListener(
+ function(request, sender, sendResponse) {
+ if (request.fileContent && request.fileContent == randomText) {
+ sendResponse({success: true});
+ chrome.test.succeed();
+ } else {
+ sendResponse({success: false});
+ console.log('Unexpected message received');
+ console.log(request);
+ chrome.test.fail("Got unexpected message");
+ }
+ });
+
+chrome.test.runTests([function tab() {
+ // Get local FS, create dir with a file in it.
+ console.log("Requesting local file system...");
+ chrome.fileBrowserPrivate.requestLocalFileSystem(onFileSystemFetched);
+}]);
+
+
+</script>
+<html>
+<body><h2>chrome.fileBrowserPrivate.* tests</h2></body>
+</html>
Property changes on: chrome/test/data/extensions/api_test/filebrowser_component/main.html
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698