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

Unified Diff: chrome/test/data/extensions/api_test/extfs/file_system.js

Issue 16439016: extfs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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/extfs/file_system.js
diff --git a/chrome/test/data/extensions/api_test/extfs/file_system.js b/chrome/test/data/extensions/api_test/extfs/file_system.js
new file mode 100644
index 0000000000000000000000000000000000000000..e2e353f574ffc4f570fc5222332e89281fe7832c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/extfs/file_system.js
@@ -0,0 +1,114 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This file implements an in-memory read-only file system through the extfs
+// API.
+
+// The in-memory file system data.
+var theRoot = {
+ self: { isDirectory: true, name: '', size: 0 },
+ children: [
+ { self: { isDirectory: false, name: 'file1', size: 10 } },
+ { self: { isDirectory: true, name: 'dir1', size: 0 },
+ children: [
+ { self: { isDirectory: false, name: 'file2', size: 20 } },
+ { self: { isDirectory: false, name: 'file3', size: 30 } },
+ { self: { isDirectory: true, name: 'dir2', size: 0 },
+ children: [
+ { self: { isDirectory: false, name: 'file4', size: 40 } },
+ { self: { isDirectory: true, name: 'dir3', size: 0 } },
+ ]
+ },
+ ]},
+ ]
+};
+
+// Get an entry at |path| from the in-memory file system.
+function getEntry(path) {
+ console.log('@@@ getEntry: ' + path);
+ // Path should start with '/testfs'.
+ if (path.length < 1 || !path.match(/^\/testfs/))
+ return null; // Invalid path.
+ // Drop /testfs.
+ path = path.replace(/\/testfs/, '/');
+ // Normalize the path.
+ path = path.replace(/\/+/g, '/');
+ if (path != '/') {
+ path = path.replace(/\/$/, '');
+ }
+
+ // Return the root if that's what requested.
+ if (path == '/') {
+ return theRoot;
+ }
+
+ function getEntryInternal(pathComponents, entry) {
+ if (entry.self.name == pathComponents[0]) {
+ if (pathComponents.length == 1)
+ return entry;
+ if (entry.self.isDirectory && entry.children) {
+ for (var i = 0; i < entry.children.length; i++) {
+ var rest = pathComponents.slice();
+ rest.shift();
+ var found = getEntryInternal(rest, entry.children[i]);
+ if (found)
+ return found;
+ }
+ }
+ }
+ return null;
+ }
+
+ var pathComponents = path.split('/');
+ return getEntryInternal(pathComponents, theRoot);
+}
+
+chrome.extfs.onEntryRequested.addListener(
+ function(path, callback) {
+ console.log('@@@ onEntryRequested: ' + path);
+ var entry = getEntry(path);
+ if (entry)
+ callback("OK", entry.self);
+ else
+ callback("ERROR_NOT_FOUND", null);
+ });
+
+chrome.extfs.onDirectoryEntriesRequested.addListener(
+ function(path, callback) {
+ console.log('@@@ onDirectoryEntriesRequested: ' + path);
+ var entries = [];
+ var parentEntry = getEntry(path);
+ if (!parentEntry) {
+ callback("ERROR_NOT_FOUND", []);
+ return;
+ }
+ if (parentEntry.children) {
+ for (var i = 0; i < parentEntry.children.length; i++) {
+ entries.push(parentEntry.children[i].self);
+ }
+ }
+ callback("OK", entries);
+ });
+
+chrome.extfs.onSnapshotRequested.addListener(
+ function(path, callback) {
+ console.log('@@@ onSnapshotRequested: ' + path);
+ var entry = getEntry(path);
+ if (!entry) {
+ callback("ERROR_NOT_FOUND", null);
+ return;
+ }
+ var content = '';
+ for (var i = 0; i < entry.self.size; i++)
+ content += 'o';
+ var blob = new Blob([content], {type: "text/plain;charset=UTF-8"});
+ callback("OK", blob);
+ });
+
+chrome.extfs.addMountPoint(
+ 'testfs',
+ function(result) {
+ console.log("@@@ addMountPoint result: " + result);
+ }
+);
« no previous file with comments | « chrome/renderer/resources/renderer_resources.grd ('k') | chrome/test/data/extensions/api_test/extfs/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698