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

Unified Diff: chrome/test/data/extensions/api_test/filesystem_handler/tab.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/filesystem_handler/tab.html
===================================================================
--- chrome/test/data/extensions/api_test/filesystem_handler/tab.html (revision 0)
+++ chrome/test/data/extensions/api_test/filesystem_handler/tab.html (revision 0)
@@ -0,0 +1,92 @@
+<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);
+ 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);
+}
+
+function onFileURLResolved(entry) {
+ if (!entry) {
+ errorCallback(chrome.extensions.lastError);
+ return;
+ }
+ 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},
+ function(response) {
+ console.log('File content sent to :' + fileBrowserExtensionId);
+ });
+ }
+ reader.onerror = errorCallback;
+ entry.file(function(file) {
+ reader.readAsText(file);
+ });
+}
+
+chrome.test.runTests([function tab() {
+ // Get dir, file name.
+ var fileUrl = window.location.hash.substring(1);
+ if (!fileUrl) {
+ chrome.test.fail("No file?");
+ return;
+ }
+ chrome.fileSystem.resolveLocalFileSystemURL(fileUrl, onFileURLResolved);
+}]);
+</script>
+<html><body><div id="content"></div></body></html>
Property changes on: chrome/test/data/extensions/api_test/filesystem_handler/tab.html
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698