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

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

Issue 442393003: Files.app: Add units test of FileOperationManager#paste. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
yoshiki 2014/08/07 09:35:30 jsdoc
hirono 2014/08/08 03:37:41 Done.
5 function MockEntry(volumeId, fullPath) {
6 this.volumeId = volumeId;
7 this.fullPath = fullPath;
8 }
9
10 /**
11 * Returns fake URL.
12 *
13 * @return {string} Fake URL.
14 */
15 MockEntry.prototype.toURL = function() {
16 return 'filesystem:' + this.volumeId + this.fullPath;
17 };
18
5 /** 19 /**
6 * Mock class for FileEntry. 20 * Mock class for FileEntry.
7 * 21 *
8 * @param {string} volumeId Id of the volume containing the entry. 22 * @param {string} volumeId Id of the volume containing the entry.
9 * @param {string} fullPath Full path for the entry. 23 * @param {string} fullPath Full path for the entry.
10 * @constructor 24 * @constructor
11 */ 25 */
12 function MockFileEntry(volumeId, fullPath) { 26 function MockFileEntry(volumeId, fullPath, metadata) {
27 MockEntry.call(this, volumeId, fullPath);
13 this.volumeId = volumeId; 28 this.volumeId = volumeId;
14 this.fullPath = fullPath; 29 this.fullPath = fullPath;
30 this.metadata_ = metadata;
15 } 31 }
16 32
17 /** 33 MockFileEntry.prototype = {
18 * Returns fake URL. 34 __proto__: MockEntry.prototype
19 *
20 * @return {string} Fake URL.
21 */
22 MockFileEntry.prototype.toURL = function() {
23 return 'filesystem:' + this.volumeId + this.fullPath;
24 }; 35 };
25 36
26 /** 37 /**
38 * Obtains metadata of the entry.
39 * @param {function(Object)} callback Function to take the metadata.
40 */
41 MockFileEntry.prototype.getMetadata = function(callback) {
42 Promise.resolve(this.metadata_).then(callback).catch(function(error) {
43 console.log(error);
yoshiki 2014/08/07 09:35:30 Please use 'console.error' if it's an error.
hirono 2014/08/08 03:37:41 Done.
44 window.onerror();
45 });
46 };
47
48 /**
27 * Mock class for DirectoryEntry. 49 * Mock class for DirectoryEntry.
28 * 50 *
29 * @param {string} volumeId Id of the volume containing the entry. 51 * @param {string} volumeId Id of the volume containing the entry.
30 * @param {string} fullPath Full path for the entry. 52 * @param {string} fullPath Full path for the entry.
31 * @param {Object.<String, MockFileEntry|MockDirectoryEntry>} contents Map of 53 * @param {Object.<String, MockFileEntry|MockDirectoryEntry>} contents Map of
32 * path and MockEntry contained in the directory. 54 * path and MockEntry contained in the directory.
yoshiki 2014/08/07 09:35:30 nit: @extends {MockEntry}
hirono 2014/08/08 03:37:41 Done.
33 * @constructor 55 * @constructor
34 */ 56 */
35 function MockDirectoryEntry(volumeId, fullPath, contents) { 57 function MockDirectoryEntry(volumeId, fullPath, contents) {
58 MockEntry.call(this, volumeId, fullPath);
36 this.contents_ = contents; 59 this.contents_ = contents;
37 } 60 }
38 61
62 MockDirectoryEntry.prototype = {
63 __proto__: MockEntry.prototype
64 };
65
39 /** 66 /**
40 * Returns a file under the directory. 67 * Returns a file under the directory.
41 * 68 *
42 * @param {string} path Path. 69 * @param {string} path Path.
43 * @param {Object} option Option. 70 * @param {Object} option Option.
44 * @param {callback(MockFileEntry)} successCallback Success callback. 71 * @param {callback(MockFileEntry)} successCallback Success callback.
45 * @param {callback(Object)} failureCallback Failure callback; 72 * @param {callback(Object)} failureCallback Failure callback;
46 */ 73 */
47 MockDirectoryEntry.prototype.getFile = function( 74 MockDirectoryEntry.prototype.getFile = function(
48 path, option, successCallback, failureCallback) { 75 path, option, successCallback, failureCallback) {
(...skipping 15 matching lines...) Expand all
64 */ 91 */
65 MockDirectoryEntry.prototype.getDirectory = 92 MockDirectoryEntry.prototype.getDirectory =
66 function(path, option, successCallback, failureCallback) { 93 function(path, option, successCallback, failureCallback) {
67 if (!this.contents_[path]) 94 if (!this.contents_[path])
68 failureCallback({name: util.FileError.NOT_FOUND_ERR}); 95 failureCallback({name: util.FileError.NOT_FOUND_ERR});
69 else if (!(this.contents_[path] instanceof MockDirectoryEntry)) 96 else if (!(this.contents_[path] instanceof MockDirectoryEntry))
70 failureCallback({name: util.FileError.TYPE_MISMATCH_ERR}); 97 failureCallback({name: util.FileError.TYPE_MISMATCH_ERR});
71 else 98 else
72 successCallback(this.contents_[path]); 99 successCallback(this.contents_[path]);
73 }; 100 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698