summaryrefslogtreecommitdiffstats
path: root/chrome/test/data
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-16 09:24:14 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-16 09:24:14 +0000
commitb6b805e9a9116fe454e11e652e5e8b3caac08c6b (patch)
tree0d71d800e2682649249b864796a157754fb6222d /chrome/test/data
parentfad613288e2dd25496cb7d8be90566bdbb76f8ec (diff)
downloadchromium_src-b6b805e9a9116fe454e11e652e5e8b3caac08c6b.zip
chromium_src-b6b805e9a9116fe454e11e652e5e8b3caac08c6b.tar.gz
chromium_src-b6b805e9a9116fe454e11e652e5e8b3caac08c6b.tar.bz2
New fileBrowserPrivate and fileHandler APIs added + plus magic needed to safely hand over access to local file system elements from content extension to 3rd party extension.
As agreed with aa@ and asargent@, this new API defines following event: chrome.fileHandler.onExecute.addListener(function(id, file_entries) { } This event is invoked when user selects files in ChromeOS file browser. The extension needs to register itself as file content hanlder with following manifest changes: ... "file_browser_actions": [ { "id" : "ActionIdentifier", "default_title" : "Action title", "default_icon" : "icon.png", "file_filters" : [ "filesystem:*.jpeg", ... ] } ... ], ... BUG=chromium-os:11996 TEST=ExtensionApiTest.FileBrowserTest, ExtensionManifestTest.FileBrowserActions Review URL: http://codereview.chromium.org/6749021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data')
-rw-r--r--chrome/test/data/extensions/api_test/filebrowser_component/background.html5
-rw-r--r--chrome/test/data/extensions/api_test/filebrowser_component/main.html136
-rw-r--r--chrome/test/data/extensions/api_test/filebrowser_component/manifest.json14
-rw-r--r--chrome/test/data/extensions/api_test/filesystem_handler/background.html27
-rw-r--r--chrome/test/data/extensions/api_test/filesystem_handler/manifest.json21
-rw-r--r--chrome/test/data/extensions/api_test/filesystem_handler/tab.html69
-rw-r--r--chrome/test/data/extensions/api_test/local_filesystem/manifest.json2
-rw-r--r--chrome/test/data/extensions/manifest_tests/filebrowser_invalid_action_id.json13
-rw-r--r--chrome/test/data/extensions/manifest_tests/filebrowser_invalid_action_title.json13
-rw-r--r--chrome/test/data/extensions/manifest_tests/filebrowser_invalid_actions_1.json6
-rw-r--r--chrome/test/data/extensions/manifest_tests/filebrowser_invalid_actions_2.json7
-rw-r--r--chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_1.json12
-rw-r--r--chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_2.json14
-rw-r--r--chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_url.json14
-rw-r--r--chrome/test/data/extensions/manifest_tests/filebrowser_valid.json14
15 files changed, 366 insertions, 1 deletions
diff --git a/chrome/test/data/extensions/api_test/filebrowser_component/background.html b/chrome/test/data/extensions/api_test/filebrowser_component/background.html
new file mode 100644
index 0000000..882f342
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/filebrowser_component/background.html
@@ -0,0 +1,5 @@
+<script>
+chrome.tabs.create({
+ url: "main.html"
+});
+</script>
diff --git a/chrome/test/data/extensions/api_test/filebrowser_component/main.html b/chrome/test/data/extensions/api_test/filebrowser_component/main.html
new file mode 100644
index 0000000..762f3a2
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/filebrowser_component/main.html
@@ -0,0 +1,136 @@
+<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 +
+ "/external/" + testDirName + "/" + testFileName;
+var testDirectory = null;
+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) {
+ testDirectory = 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 WebKitBlobBuilder();
+ 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);
+}
+
+function onCleanupFinished(entry) {
+ chrome.test.succeed();
+}
+
+// For simple requests:
+chrome.extension.onRequestExternal.addListener(
+ function(request, sender, sendResponse) {
+ if (request.fileContent && request.fileContent == randomText) {
+ sendResponse({success: true});
+ testDirectory.removeRecursively(onCleanupFinished, errorCallback);
+ } else {
+ sendResponse({success: false});
+ console.log('Error message received');
+ console.log(request);
+ chrome.test.fail("Got error: " + request.error);
+ }
+ });
+
+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>
diff --git a/chrome/test/data/extensions/api_test/filebrowser_component/manifest.json b/chrome/test/data/extensions/api_test/filebrowser_component/manifest.json
new file mode 100644
index 0000000..b246386
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/filebrowser_component/manifest.json
@@ -0,0 +1,14 @@
+{
+ "key": "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDOuXEIuoK1kAkBe0SKiJn/N9oNn3oUxGa4dwj40MnJqPn+w0aR2vuyocm0R4Drp67aYwtLjOVPF4CICRq6ICP6eU07gGwQxGdZ7HJASXV8hm0tab5I70oJmRLfFJyVAMCeWlFaOGq05v2i6EbifZM0qO5xALKNGQt+yjXi5INM5wIBIw==",
+ "name": "chrome.fileBrowserPrivate tests",
+ "version": "0.1",
+ "description": "Tests of chrome.fileBrowserPrivate.* component extension methods",
+ "background_page": "background.html",
+ "permissions": [
+ "tabs",
+ "unlimitedStorage",
+ "fileBrowserHandler",
+ "fileBrowserPrivate"
+ ]
+}
+
diff --git a/chrome/test/data/extensions/api_test/filesystem_handler/background.html b/chrome/test/data/extensions/api_test/filesystem_handler/background.html
new file mode 100644
index 0000000..0da7763
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/filesystem_handler/background.html
@@ -0,0 +1,27 @@
+<script>
+var last_file_entries = null;
+
+function getLastFileEntries() {
+ return last_file_entries;
+}
+
+chrome.fileBrowserHandler.onExecute.addListener(
+ function(id, file_entries) {
+ if (id != "TestAction") {
+ chrome.test.fail("Unexpected action id: " + id);
+ return;
+ }
+ if (!file_entries || file_entries.length != 1) {
+ chrome.test.fail("Unexpected file url list");
+ return;
+ }
+ last_file_entries = file_entries;
+ // Create a new tab
+ chrome.tabs.create({
+ url: "tab.html"
+ });
+ });
+
+chrome.test.succeed();
+
+</script>
diff --git a/chrome/test/data/extensions/api_test/filesystem_handler/manifest.json b/chrome/test/data/extensions/api_test/filesystem_handler/manifest.json
new file mode 100644
index 0000000..8cba77f
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/filesystem_handler/manifest.json
@@ -0,0 +1,21 @@
+{
+ "key": "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQChptAQ0n4R56N03nWQ1ogR7DVRBjGo80Vw6G9KLjzZv44D8rq5Q5IkeQrtKgWyZfXevlsCe3LaLo18rcz8iZx6lK2xhLdUR+ORjsjuBfdEL5a5cWeRTSxf75AcqndQsmpwMBdrMTCZ8jQNusUI+XlrihLNNJuI5TM4vNINI5bYFQIBIw==",
+ "name": "ChromeOS file system intent hanlder extension",
+ "version": "0.1",
+ "description": "Tests of chrome.fileSystem.* methods",
+ "background_page": "background.html",
+ "file_browser_handlers": [
+ {
+ "id" : "TestAction",
+ "default_title" : "Default title",
+ "default_icon" : "icon.png",
+ "file_filters" : [ "filesystem:*.txt" ]
+ }
+ ],
+ "permissions": [
+ "fileBrowserHandler",
+ "tabs",
+ "unlimitedStorage"
+ ]
+}
+
diff --git a/chrome/test/data/extensions/api_test/filesystem_handler/tab.html b/chrome/test/data/extensions/api_test/filesystem_handler/tab.html
new file mode 100644
index 0000000..110146d
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/filesystem_handler/tab.html
@@ -0,0 +1,69 @@
+<script>
+/*
+This extension is a file intent handler and does the following during the test:
+
+1. Its background page first registers content hander.
+2. When content handler callback is invokek, opens tab.html page and passes
+ file url via hash ref.
+3. Tries to resolve target file url and reads its content.
+4. Send file content to file browser extension.
+*/
+
+// The ID of the extension we want to talk to.
+var fileBrowserExtensionId = "ddammdhioacbehjngdmkjcjbnfginlla";
+
+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);
+}
+
+chrome.test.runTests([function tab() {
+ var entries = chrome.extension.getBackgroundPage().getLastFileEntries();
+ if (!entries || entries.length != 1 || !entries[0]) {
+ chrome.extension.sendRequest(fileBrowserExtensionId,
+ {fileContent: null,
+ error: "Invalid file entries."},
+ function(response) {});
+ return;
+ }
+ var entry = entries[0];
+ var reader = new FileReader();
+ reader.onloadend = function(e) {
+ var content = document.getElementById('content');
+ content.innerHTML = reader.result;
+ // Send data back to the file browser extension
+ chrome.extension.sendRequest(fileBrowserExtensionId,
+ {fileContent: reader.result, error: null},
+ function(response) {});
+ }
+ reader.onerror = errorCallback;
+ entry.file(function(file) {
+ reader.readAsText(file);
+ });
+}]);
+</script>
+<html><body><div id="content"></div></body></html>
diff --git a/chrome/test/data/extensions/api_test/local_filesystem/manifest.json b/chrome/test/data/extensions/api_test/local_filesystem/manifest.json
index 367a97a..a17c5f0 100644
--- a/chrome/test/data/extensions/api_test/local_filesystem/manifest.json
+++ b/chrome/test/data/extensions/api_test/local_filesystem/manifest.json
@@ -7,7 +7,7 @@
"permissions": [
"tabs",
"unlimitedStorage",
- "fileSystem",
+ "fileBrowserHandler",
"fileBrowserPrivate"
]
}
diff --git a/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_action_id.json b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_action_id.json
new file mode 100644
index 0000000..8dbe069
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_action_id.json
@@ -0,0 +1,13 @@
+{
+ "name": "test",
+ "version": "1",
+ "file_browser_handlers": [
+ {
+ "default_title" : "Test",
+ "default_icon" : "icon.png",
+ "file_filters" : [
+ "filesystem:*.txt"
+ ]
+ }
+ ]
+}
diff --git a/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_action_title.json b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_action_title.json
new file mode 100644
index 0000000..d0cf287
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_action_title.json
@@ -0,0 +1,13 @@
+{
+ "name": "test",
+ "version": "1",
+ "file_browser_handlers": [
+ {
+ "id" : "ID",
+ "default_icon" : "icon.png",
+ "file_filters" : [
+ "filesystem:*.txt"
+ ]
+ }
+ ]
+}
diff --git a/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_actions_1.json b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_actions_1.json
new file mode 100644
index 0000000..4138cfd
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_actions_1.json
@@ -0,0 +1,6 @@
+{
+ "name": "test",
+ "version": "1",
+ "file_browser_handlers": {
+ }
+}
diff --git a/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_actions_2.json b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_actions_2.json
new file mode 100644
index 0000000..c5c50b1
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_actions_2.json
@@ -0,0 +1,7 @@
+{
+ "name": "test",
+ "version": "1",
+ "file_browser_handlers": [
+ "bad"
+ ]
+}
diff --git a/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_1.json b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_1.json
new file mode 100644
index 0000000..fd63a02
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_1.json
@@ -0,0 +1,12 @@
+{
+ "name": "test",
+ "version": "1",
+ "file_browser_handlers": [
+ {
+ "id" : "ID",
+ "default_title" : "Test",
+ "default_icon" : "icon.png",
+ "file_filters" : "bad"
+ }
+ ]
+}
diff --git a/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_2.json b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_2.json
new file mode 100644
index 0000000..a2b3bde
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_2.json
@@ -0,0 +1,14 @@
+{
+ "name": "test",
+ "version": "1",
+ "file_browser_handlers": [
+ {
+ "id" : "ID",
+ "default_title" : "Test",
+ "default_icon" : "icon.png",
+ "file_filters" : [
+ false
+ ]
+ }
+ ]
+}
diff --git a/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_url.json b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_url.json
new file mode 100644
index 0000000..9c876db
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/filebrowser_invalid_file_filters_url.json
@@ -0,0 +1,14 @@
+{
+ "name": "test",
+ "version": "1",
+ "file_browser_handlers": [
+ {
+ "id" : "ID",
+ "default_title" : "Test",
+ "default_icon" : "icon.png",
+ "file_filters" : [
+ "http:*.html"
+ ]
+ }
+ ]
+}
diff --git a/chrome/test/data/extensions/manifest_tests/filebrowser_valid.json b/chrome/test/data/extensions/manifest_tests/filebrowser_valid.json
new file mode 100644
index 0000000..c7d32a3
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/filebrowser_valid.json
@@ -0,0 +1,14 @@
+{
+ "name": "test",
+ "version": "1",
+ "file_browser_handlers": [
+ {
+ "id" : "ID",
+ "default_title" : "Default title",
+ "default_icon" : "icon.png",
+ "file_filters" : [
+ "filesystem:*.txt"
+ ]
+ }
+ ]
+}