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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Mock class for FileEntry.
7 *
8 * @param {string} volumeId Id of the volume containing the entry.
9 * @param {string} fullPath Full path for the entry.
10 * @constructor
11 */
12 function MockFileEntry(volumeId, fullPath) {
13 this.volumeId = volumeId;
14 this.fullPath = fullPath;
15 }
16
17 /**
18 * Returns fake URL.
19 *
20 * @return {string} Fake URL.
21 */
22 MockFileEntry.prototype.toURL = function() {
23 return 'filesystem:' + this.volumeId + this.fullPath;
24 };
25
26 /**
27 * Mock class for DirectoryEntry.
28 *
29 * @param {string} volumeId Id of the volume containing the entry.
30 * @param {string} fullPath Full path for the entry.
31 * @param {Object.<String, MockFileEntry|MockDirectoryEntry>} contents Map of
32 * path and MockEntry contained in the directory.
33 * @constructor
34 */
35 function MockDirectoryEntry(volumeId, fullPath, contents) {
36 this.contents_ = contents;
37 }
38
39 /**
40 * Returns a file under the directory.
41 *
42 * @param {string} path Path.
43 * @param {Object} option Option.
44 * @param {callback(MockFileEntry)} successCallback Success callback.
45 * @param {callback(Object)} failureCallback Failure callback;
46 */
47 MockDirectoryEntry.prototype.getFile = function(
48 path, option, successCallback, failureCallback) {
49 if (!this.contents_[path])
50 failureCallback({name: util.FileError.NOT_FOUND_ERR});
51 else if (!(this.contents_[path] instanceof MockFileEntry))
52 failureCallback({name: util.FileError.TYPE_MISMATCH_ERR});
53 else
54 successCallback(this.contents_[path]);
55 };
56
57 /**
58 * Returns a directory under the directory.
59 *
60 * @param {string} path Path.
61 * @param {Object} option Option.
62 * @param {callback(MockDirectoryEntry)} successCallback Success callback.
63 * @param {callback(Object)} failureCallback Failure callback;
64 */
65 MockDirectoryEntry.prototype.getDirectory =
66 function(path, option, successCallback, failureCallback) {
67 if (!this.contents_[path])
68 failureCallback({name: util.FileError.NOT_FOUND_ERR});
69 else if (!(this.contents_[path] instanceof MockDirectoryEntry))
70 failureCallback({name: util.FileError.TYPE_MISMATCH_ERR});
71 else
72 successCallback(this.contents_[path]);
73 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698