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

Unified Diff: chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js

Issue 762593006: Prototype implementation of MediaImportHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to master. Created 6 years 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/file_manager/unit_tests/mocks/mock_entry.js
diff --git a/chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js b/chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js
index c8f68848ad94a453e76f5dacddafe82b19c580e5..ef358bd1e336c0b255980a128e01c60a35876942 100644
--- a/chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js
+++ b/chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js
@@ -16,13 +16,20 @@ function joinPath(a, b) {
* Mock class for DOMFileSystem.
*
* @param {string} volumeId Volume ID.
- * @param {string} rootURL URL string of root which is used in MockEntry.toURL.
+ * @param {string=} opt_rootURL URL string of root which is used in
+ * MockEntry.toURL.
* @constructor
*/
-function MockFileSystem(volumeId, rootURL) {
+function MockFileSystem(volumeId, opt_rootURL) {
+ /** @type {string} */
this.name = volumeId;
+
+ /** @type {!Object<string, !Entry>} */
this.entries = {};
- this.rootURL = rootURL;
+ this.entries['/'] = new MockDirectoryEntry(this, '/');
+
+ /** @type {string} */
+ this.rootURL = opt_rootURL || 'filesystem:' + volumeId;
}
MockFileSystem.prototype = {
@@ -30,6 +37,28 @@ MockFileSystem.prototype = {
};
/**
+ * Creates file and directory entries for all the given paths. Paths ending in
+ * slashes are interpreted as directories. All intermediate directories leading
+ * up to the files/directories to be created, are also created.
+ * @param {!Array<string>} paths An array of file paths to populate in this file
+ * system.
+ */
+MockFileSystem.prototype.populate = function(paths) {
+ paths.forEach(function(path) {
+ var pathElements = path.split('/');
+ pathElements.forEach(function(_, i) {
+ var subpath = pathElements.slice(0, i).join('/');
+ if (subpath && !(subpath in this.entries))
+ this.entries[subpath] = new MockDirectoryEntry(this, subpath);
+ }.bind(this));
+
+ // If the path doesn't end in a slash, create a file.
+ if (!/\/$/.test(path))
+ this.entries[path] = new MockFileEntry(this, path, {size: 0});
+ }.bind(this));
+};
+
+/**
* Base class of mock entries.
*
* @param {TestFileSystem} filesystem File system where the entry is localed.
@@ -207,12 +236,23 @@ MockDirectoryEntry.prototype.getFile = function(
MockDirectoryEntry.prototype.getDirectory =
function(path, option, onSuccess, onError) {
var fullPath = path[0] === '/' ? path : joinPath(this.fullPath, path);
- if (!this.filesystem.entries[fullPath])
- onError({name: util.FileError.NOT_FOUND_ERR});
- else if (!(this.filesystem.entries[fullPath] instanceof MockDirectoryEntry))
- onError({name: util.FileError.TYPE_MISMATCH_ERR});
- else
- onSuccess(this.filesystem.entries[fullPath]);
+ var result = this.filesystem.entries[fullPath];
+ if (result) {
+ if (!(result instanceof MockDirectoryEntry))
+ onError({name: util.FileError.TYPE_MISMATCH_ERR});
+ else if (option['create'] && option['exclusive'])
+ onError({name: util.FileError.PATH_EXISTS_ERR});
+ else
+ onSuccess(result);
+ } else {
+ if (!option['create']) {
+ onError({name: util.FileError.NOT_FOUND_ERR});
+ } else {
+ var newEntry = new MockDirectoryEntry(this.filesystem, fullPath);
+ this.filesystem.entries[fullPath] = newEntry;
+ onSuccess(newEntry);
+ }
+ }
};
/**

Powered by Google App Engine
This is Rietveld 408576698