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

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

Issue 439753002: Files.app: Add the MockDirectoryEntry class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 4 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/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
new file mode 100644
index 0000000000000000000000000000000000000000..5110334478a569e522d7be6c536783c47f3d8b84
--- /dev/null
+++ b/chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js
@@ -0,0 +1,73 @@
+// Copyright 2014 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.
+
+/**
+ * Mock class for FileEntry.
+ *
+ * @param {string} volumeId Id of the volume containing the entry.
+ * @param {string} fullPath Full path for the entry.
+ * @constructor
+ */
+function MockFileEntry(volumeId, fullPath) {
+ this.volumeId = volumeId;
+ this.fullPath = fullPath;
+}
+
+/**
+ * Returns fake URL.
+ *
+ * @return {string} Fake URL.
+ */
+MockFileEntry.prototype.toURL = function() {
+ return 'filesystem:' + this.volumeId + this.fullPath;
+};
+
+/**
+ * Mock class for DirectoryEntry.
+ *
+ * @param {string} volumeId Id of the volume containing the entry.
+ * @param {string} fullPath Full path for the entry.
+ * @param {Object.<String, MockFileEntry|MockDirectoryEntry>} contents Map of
+ * path and MockEntry contained in the directory.
+ * @constructor
+ */
+function MockDirectoryEntry(volumeId, fullPath, contents) {
+ this.contents_ = contents;
+}
+
+/**
+ * Returns a file under the directory.
+ *
+ * @param {string} path Path.
+ * @param {Object} option Option.
+ * @param {callback(MockFileEntry)} successCallback Success callback.
+ * @param {callback(Object)} failureCallback Failure callback;
+ */
+MockDirectoryEntry.prototype.getFile = function(
+ path, option, successCallback, failureCallback) {
+ if (!this.contents_[path])
+ failureCallback({name: util.FileError.NOT_FOUND_ERR});
+ else if (!(this.contents_[path] instanceof MockFileEntry))
+ failureCallback({name: util.FileError.TYPE_MISMATCH_ERR});
+ else
+ successCallback(this.contents_[path]);
+};
+
+/**
+ * Returns a directory under the directory.
+ *
+ * @param {string} path Path.
+ * @param {Object} option Option.
+ * @param {callback(MockDirectoryEntry)} successCallback Success callback.
+ * @param {callback(Object)} failureCallback Failure callback;
+ */
+MockDirectoryEntry.prototype.getDirectory =
+ function(path, option, successCallback, failureCallback) {
+ if (!this.contents_[path])
+ failureCallback({name: util.FileError.NOT_FOUND_ERR});
+ else if (!(this.contents_[path] instanceof MockDirectoryEntry))
+ failureCallback({name: util.FileError.TYPE_MISMATCH_ERR});
+ else
+ successCallback(this.contents_[path]);
+};

Powered by Google App Engine
This is Rietveld 408576698