OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 VolumeManager. |
| 7 * @constructor |
| 8 */ |
| 9 function MockVolumeManager() { |
| 10 this.volumeInfoList = new cr.ui.ArrayDataModel([]); |
| 11 |
| 12 this.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo( |
| 13 util.VolumeType.DRIVE, '/drive')); |
| 14 this.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo( |
| 15 util.VolumeType.DOWNLOADS, '/Downloads')); |
| 16 } |
| 17 |
| 18 /** |
| 19 * Returns the corresponding VolumeInfo. |
| 20 * @param {string} mountPath Path to be looking for with. |
| 21 * @return {VolumeInfo} Corresponding VolumeInfo. |
| 22 */ |
| 23 MockVolumeManager.prototype.getVolumeInfo = function(mountPath) { |
| 24 for (var i = 0; i < this.volumeInfoList.length; i++) { |
| 25 if (this.volumeInfoList.item(i).mountPath === mountPath) |
| 26 return this.volumeInfoList.item(i); |
| 27 } |
| 28 return null; |
| 29 }; |
| 30 |
| 31 /** |
| 32 * Resolve FileEntry. |
| 33 * @param {string} path |
| 34 * @param {function(FileEntry)} successCallback Callback on success. |
| 35 * @param {function()} errorCallback Callback on error. |
| 36 */ |
| 37 MockVolumeManager.prototype.resolvePath = function( |
| 38 path, successCallback, errorCallback) { |
| 39 var mockFileEntry = new MockFileEntry(); |
| 40 mockFileEntry.fullPath = path; |
| 41 successCallback(mockFileEntry); |
| 42 }; |
| 43 |
| 44 /** |
| 45 * Utility function to create a mock VolumeInfo. |
| 46 * @param {VolumeType} type Volume type. |
| 47 * @param {string} path Volume path. |
| 48 * @return {VolumeInfo} Created mock VolumeInfo. |
| 49 */ |
| 50 MockVolumeManager.createMockVolumeInfo = function(type, path) { |
| 51 var entry = new MockFileEntry(); |
| 52 entry.fullPath = path; |
| 53 |
| 54 var volumeInfo = new VolumeInfo( |
| 55 type, |
| 56 path, |
| 57 entry, // Directory entry. |
| 58 '', // error |
| 59 '', // deviceType |
| 60 false); // readonly |
| 61 |
| 62 return volumeInfo; |
| 63 }; |
OLD | NEW |