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 * Joins paths so that the two paths are connected by only 1 '/'. | 6 * Joins paths so that the two paths are connected by only 1 '/'. |
7 * @param {string} a Path. | 7 * @param {string} a Path. |
8 * @param {string} b Path. | 8 * @param {string} b Path. |
9 * @return {string} Joined path. | 9 * @return {string} Joined path. |
10 */ | 10 */ |
11 function joinPath(a, b) { | 11 function joinPath(a, b) { |
12 return a.replace(/\/+$/, '') + '/' + b.replace(/^\/+/, ''); | 12 return a.replace(/\/+$/, '') + '/' + b.replace(/^\/+/, ''); |
13 }; | 13 }; |
14 | 14 |
15 /** | 15 /** |
16 * Test file system. | 16 * Mock class for DOMFileSystem. |
17 * | 17 * |
18 * @param {string} fileSystemId File system ID. | 18 * @param {string} volumeId Volume ID. |
| 19 * @param {string} rootURL URL string of root which is used in MockEntry.toURL. |
19 * @constructor | 20 * @constructor |
20 */ | 21 */ |
21 function TestFileSystem(fileSystemId) { | 22 function MockFileSystem(volumeId, rootURL) { |
22 this.fileSystemId = fileSystemId; | 23 this.name = volumeId; |
23 this.entries = {}; | 24 this.entries = {}; |
| 25 this.rootURL = rootURL; |
24 }; | 26 }; |
25 | 27 |
26 TestFileSystem.prototype = { | 28 MockFileSystem.prototype = { |
27 get root() { return this.entries['/']; } | 29 get root() { return this.entries['/']; } |
28 }; | 30 }; |
29 | 31 |
30 /** | 32 /** |
31 * Base class of mock entries. | 33 * Base class of mock entries. |
32 * | 34 * |
33 * @param {TestFileSystem} filesystem File system where the entry is localed. | 35 * @param {TestFileSystem} filesystem File system where the entry is localed. |
34 * @param {string} fullpath Full path of the entry. | 36 * @param {string} fullpath Full path of the entry. |
35 * @constructor | 37 * @constructor |
36 */ | 38 */ |
(...skipping 10 matching lines...) Expand all Loading... |
47 return this.fullPath.replace(/^.*\//, ''); | 49 return this.fullPath.replace(/^.*\//, ''); |
48 } | 50 } |
49 }; | 51 }; |
50 | 52 |
51 /** | 53 /** |
52 * Returns fake URL. | 54 * Returns fake URL. |
53 * | 55 * |
54 * @return {string} Fake URL. | 56 * @return {string} Fake URL. |
55 */ | 57 */ |
56 MockEntry.prototype.toURL = function() { | 58 MockEntry.prototype.toURL = function() { |
57 return 'filesystem:' + this.filesystem.fileSystemId + this.fullPath; | 59 return this.filesystem.rootURL + this.fullPath; |
58 }; | 60 }; |
59 | 61 |
60 /** | 62 /** |
61 * Obtains parent directory. | 63 * Obtains parent directory. |
62 * | 64 * |
63 * @param {function(MockDirectoryEntry)} onSuccess Callback invoked with | 65 * @param {function(MockDirectoryEntry)} onSuccess Callback invoked with |
64 * the parent directory. | 66 * the parent directory. |
65 * @param {function(Object)} onError Callback invoked with an error | 67 * @param {function(Object)} onError Callback invoked with an error |
66 * object. | 68 * object. |
67 */ | 69 */ |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 MockDirectoryEntry.prototype.getDirectory = | 207 MockDirectoryEntry.prototype.getDirectory = |
206 function(path, option, onSuccess, onError) { | 208 function(path, option, onSuccess, onError) { |
207 var fullPath = path[0] === '/' ? path : joinPath(this.fullPath, path); | 209 var fullPath = path[0] === '/' ? path : joinPath(this.fullPath, path); |
208 if (!this.filesystem.entries[fullPath]) | 210 if (!this.filesystem.entries[fullPath]) |
209 onError({name: util.FileError.NOT_FOUND_ERR}); | 211 onError({name: util.FileError.NOT_FOUND_ERR}); |
210 else if (!(this.filesystem.entries[fullPath] instanceof MockDirectoryEntry)) | 212 else if (!(this.filesystem.entries[fullPath] instanceof MockDirectoryEntry)) |
211 onError({name: util.FileError.TYPE_MISMATCH_ERR}); | 213 onError({name: util.FileError.TYPE_MISMATCH_ERR}); |
212 else | 214 else |
213 onSuccess(this.filesystem.entries[fullPath]); | 215 onSuccess(this.filesystem.entries[fullPath]); |
214 }; | 216 }; |
| 217 |
| 218 /** |
| 219 * Creates a MockDirectoryReader for the entry. |
| 220 */ |
| 221 MockDirectoryEntry.prototype.createReader = function() { |
| 222 return new MockDirectoryReader(); |
| 223 } |
| 224 |
| 225 /** |
| 226 * Mock class for DirectoryReader. |
| 227 */ |
| 228 function MockDirectoryReader() {} |
| 229 |
| 230 /** |
| 231 * Reads entries. |
| 232 * Current implementation just calls success callback. |
| 233 */ |
| 234 MockDirectoryReader.prototype.readEntries = function(success, error) { |
| 235 success(); |
| 236 } |
OLD | NEW |