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

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..311203965733d94e71b07b03411c29018c85a373 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
@@ -30,6 +30,41 @@ MockFileSystem.prototype = {
};
/**
+ * Creates a new mock filesystem with a root dir and the given volume ID.
+ * @param {string} volumeId
+ * @return {!MockFileSystem}
+ */
+MockFileSystem.create = function(volumeId) {
hirono 2014/12/04 04:44:23 It looks convenient. Could you please move the lin
Ben Kwa 2014/12/04 19:53:01 Done.
+ var fileSystem = new MockFileSystem(volumeId, 'filesystem:' + volumeId);
+ fileSystem.entries['/'] = new MockDirectoryEntry(fileSystem, '/');
+ return fileSystem;
+};
+
+/**
+ * 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)) {
hirono 2014/12/04 04:44:24 nit: Please drop {}
Ben Kwa 2014/12/04 19:53:01 Done.
+ this.entries[subpath] = new MockDirectoryEntry(this, subpath);
+ }
+ }.bind(this));
+
+ // If the path doesn't end in a slash, create a file.
+ if (!/\/$/.test(path)) {
hirono 2014/12/04 04:44:24 nit: Please drop {}
Ben Kwa 2014/12/04 19:53:01 Done.
+ this.entries[path] = new MockFileEntry(this, path);
hirono 2014/12/04 04:44:23 Entry should take metadata.
Ben Kwa 2014/12/04 19:53:01 Done.
+ }
+ }.bind(this));
+};
+
+/**
* Base class of mock entries.
*
* @param {TestFileSystem} filesystem File system where the entry is localed.
@@ -207,12 +242,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];
hirono 2014/12/04 04:44:23 Thank you for implementing this!
Ben Kwa 2014/12/04 19:53:01 Acknowledged.
+ 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