OLD | NEW |
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 |
5 /** | 5 /** |
6 * Mock class for FileEntry. | 6 * Base class of mock entries. |
7 * | 7 * |
8 * @param {string} volumeId Id of the volume containing the entry. | 8 * @param {string} volumeId ID of the volume that contains the entry. |
9 * @param {string} fullPath Full path for the entry. | 9 * @param {string} fullpath Full path of the entry. |
10 * @constructor | 10 * @constructor |
11 */ | 11 */ |
12 function MockFileEntry(volumeId, fullPath) { | 12 function MockEntry(volumeId, fullPath) { |
13 this.volumeId = volumeId; | 13 this.volumeId = volumeId; |
14 this.fullPath = fullPath; | 14 this.fullPath = fullPath; |
15 } | 15 } |
16 | 16 |
17 /** | 17 /** |
18 * Returns fake URL. | 18 * Returns fake URL. |
19 * | 19 * |
20 * @return {string} Fake URL. | 20 * @return {string} Fake URL. |
21 */ | 21 */ |
22 MockFileEntry.prototype.toURL = function() { | 22 MockEntry.prototype.toURL = function() { |
23 return 'filesystem:' + this.volumeId + this.fullPath; | 23 return 'filesystem:' + this.volumeId + this.fullPath; |
24 }; | 24 }; |
25 | 25 |
26 /** | 26 /** |
| 27 * Mock class for FileEntry. |
| 28 * |
| 29 * @param {string} volumeId Id of the volume containing the entry. |
| 30 * @param {string} fullPath Full path for the entry. |
| 31 * @extends {MockEntry} |
| 32 * @constructor |
| 33 */ |
| 34 function MockFileEntry(volumeId, fullPath, metadata) { |
| 35 MockEntry.call(this, volumeId, fullPath); |
| 36 this.volumeId = volumeId; |
| 37 this.fullPath = fullPath; |
| 38 this.metadata_ = metadata; |
| 39 } |
| 40 |
| 41 MockFileEntry.prototype = { |
| 42 __proto__: MockEntry.prototype |
| 43 }; |
| 44 |
| 45 /** |
| 46 * Obtains metadata of the entry. |
| 47 * @param {function(Object)} callback Function to take the metadata. |
| 48 */ |
| 49 MockFileEntry.prototype.getMetadata = function(callback) { |
| 50 Promise.resolve(this.metadata_).then(callback).catch(function(error) { |
| 51 console.error(error.stack || error); |
| 52 window.onerror(); |
| 53 }); |
| 54 }; |
| 55 |
| 56 /** |
27 * Mock class for DirectoryEntry. | 57 * Mock class for DirectoryEntry. |
28 * | 58 * |
29 * @param {string} volumeId Id of the volume containing the entry. | 59 * @param {string} volumeId Id of the volume containing the entry. |
30 * @param {string} fullPath Full path for the entry. | 60 * @param {string} fullPath Full path for the entry. |
31 * @param {Object.<String, MockFileEntry|MockDirectoryEntry>} contents Map of | 61 * @param {Object.<String, MockFileEntry|MockDirectoryEntry>} contents Map of |
32 * path and MockEntry contained in the directory. | 62 * path and MockEntry contained in the directory. |
| 63 * @extends {MockEntry} |
33 * @constructor | 64 * @constructor |
34 */ | 65 */ |
35 function MockDirectoryEntry(volumeId, fullPath, contents) { | 66 function MockDirectoryEntry(volumeId, fullPath, contents) { |
| 67 MockEntry.call(this, volumeId, fullPath); |
36 this.contents_ = contents; | 68 this.contents_ = contents; |
37 } | 69 } |
38 | 70 |
| 71 MockDirectoryEntry.prototype = { |
| 72 __proto__: MockEntry.prototype |
| 73 }; |
| 74 |
39 /** | 75 /** |
40 * Returns a file under the directory. | 76 * Returns a file under the directory. |
41 * | 77 * |
42 * @param {string} path Path. | 78 * @param {string} path Path. |
43 * @param {Object} option Option. | 79 * @param {Object} option Option. |
44 * @param {callback(MockFileEntry)} successCallback Success callback. | 80 * @param {callback(MockFileEntry)} successCallback Success callback. |
45 * @param {callback(Object)} failureCallback Failure callback; | 81 * @param {callback(Object)} failureCallback Failure callback; |
46 */ | 82 */ |
47 MockDirectoryEntry.prototype.getFile = function( | 83 MockDirectoryEntry.prototype.getFile = function( |
48 path, option, successCallback, failureCallback) { | 84 path, option, successCallback, failureCallback) { |
(...skipping 15 matching lines...) Expand all Loading... |
64 */ | 100 */ |
65 MockDirectoryEntry.prototype.getDirectory = | 101 MockDirectoryEntry.prototype.getDirectory = |
66 function(path, option, successCallback, failureCallback) { | 102 function(path, option, successCallback, failureCallback) { |
67 if (!this.contents_[path]) | 103 if (!this.contents_[path]) |
68 failureCallback({name: util.FileError.NOT_FOUND_ERR}); | 104 failureCallback({name: util.FileError.NOT_FOUND_ERR}); |
69 else if (!(this.contents_[path] instanceof MockDirectoryEntry)) | 105 else if (!(this.contents_[path] instanceof MockDirectoryEntry)) |
70 failureCallback({name: util.FileError.TYPE_MISMATCH_ERR}); | 106 failureCallback({name: util.FileError.TYPE_MISMATCH_ERR}); |
71 else | 107 else |
72 successCallback(this.contents_[path]); | 108 successCallback(this.contents_[path]); |
73 }; | 109 }; |
OLD | NEW |