f3634b311897057d9f0b27a5df0da53139ea115e
[platform/framework/web/crosswalk.git] / src / chrome / test / data / file_manager / unit_tests / mocks / mock_volume_manager.js
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       VolumeManagerCommon.VolumeType.DRIVE, 'drive'));
14   this.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo(
15       VolumeManagerCommon.VolumeType.DOWNLOADS, 'downloads'));
16 }
17
18 /**
19  * Returns the corresponding VolumeInfo.
20  *
21  * @param {MockFileEntry} entry MockFileEntry pointing anywhere on a volume.
22  * @return {VolumeInfo} Corresponding VolumeInfo.
23  */
24 MockVolumeManager.prototype.getVolumeInfo = function(entry) {
25   for (var i = 0; i < this.volumeInfoList.length; i++) {
26     if (this.volumeInfoList.item(i).volumeId === entry.volumeId)
27       return this.volumeInfoList.item(i);
28   }
29   return null;
30 };
31
32 /**
33  * Utility function to create a mock VolumeInfo.
34  * @param {VolumeType} type Volume type.
35  * @param {string} path Volume path.
36  * @return {VolumeInfo} Created mock VolumeInfo.
37  */
38 MockVolumeManager.createMockVolumeInfo = function(type, volumeId) {
39   var fileSystem = new MockFileSystem(volumeId);
40
41   var volumeInfo = new VolumeInfo(
42       type,
43       volumeId,
44       fileSystem,
45       '',     // error
46       '',     // deviceType
47       false,  // isReadonly
48       {isCurrentProfile: true, displayName: ''},  // profile
49       '');    // label
50
51   return volumeInfo;
52 };