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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <script>
2 /*
3 This extension is a file intent handler and does the following during the test:
4
5 1. Its background page first registers content hander.
6 2. When content handler callback is invokek, opens tab.html page and passes
7 file url via hash ref.
8 3. Tries to resolve target file url and reads its content.
9 4. Send file content to file browser extension.
10 */
11
12 // The ID of the extension we want to talk to.
13 var fileBrowserExtensionId = "ddammdhioacbehjngdmkjcjbnfginlla";
14
15 function errorCallback(e) {
16 var msg = '';
17 if (!e.code) {
18 msg = e.message;
19 } else {
20 switch (e.code) {
21 case FileError.QUOTA_EXCEEDED_ERR:
22 msg = 'QUOTA_EXCEEDED_ERR';
23 break;
24 case FileError.NOT_FOUND_ERR:
25 msg = 'NOT_FOUND_ERR';
26 break;
27 case FileError.SECURITY_ERR:
28 msg = 'SECURITY_ERR';
29 break;
30 case FileError.INVALID_MODIFICATION_ERR:
31 msg = 'INVALID_MODIFICATION_ERR';
32 break;
33 case FileError.INVALID_STATE_ERR:
34 msg = 'INVALID_STATE_ERR';
35 break;
36 default:
37 msg = 'Unknown Error';
38 break;
39 };
40 }
41 chrome.test.fail("Got unexpected error: " + msg);
42 console.log('Error: ' + msg);
43 alert('Error: ' + msg);
44 }
45
46
47 function successCallback(entry) {
48 chrome.test.succeed();
49 }
50
51 function successEntryCallback(entry) {
52 console.log("Deleting dir : " + testDirName);
53 fileSystem.root.getDirectory(testDirName, {create:false},
54 function(directory) {
55 // Do clean-up. (Assume the tab won't be reloaded in testing.)
56 directory.removeRecursively(successCallback, errorCallback);
57 }, errorCallback);
58 }
59
60 function onFileURLResolved(entry) {
61 if (!entry) {
62 errorCallback(chrome.extensions.lastError);
63 return;
64 }
65 var reader = new FileReader();
66 reader.onloadend = function(e) {
67 var content = document.getElementById('content');
68 content.innerHTML = reader.result;
69 // Send data back to the file browser extension
70 chrome.extension.sendRequest(fileBrowserExtensionId,
71 {fileContent: reader.result},
72 function(response) {
73 console.log('File content sent to :' + fileBrowserExtensionId);
74 });
75 }
76 reader.onerror = errorCallback;
77 entry.file(function(file) {
78 reader.readAsText(file);
79 });
80 }
81
82 chrome.test.runTests([function tab() {
83 // Get dir, file name.
84 var fileUrl = window.location.hash.substring(1);
85 if (!fileUrl) {
86 chrome.test.fail("No file?");
87 return;
88 }
89 chrome.fileSystem.resolveLocalFileSystemURL(fileUrl, onFileURLResolved);
90 }]);
91 </script>
92 <html><body><div id="content"></div></body></html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698