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

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

Issue 762593006: Prototype implementation of MediaImportHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to master. Created 6 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 VolumeManager. 6 * Mock class for VolumeManager.
7 * @constructor 7 * @constructor
8 */ 8 */
9 function MockVolumeManager() { 9 function MockVolumeManager() {
10 this.volumeInfoList = new cr.ui.ArrayDataModel([]); 10 this.volumeInfoList = new cr.ui.ArrayDataModel([]);
11 11
12 this.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo( 12 this.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo(
13 VolumeManagerCommon.VolumeType.DRIVE, 'drive', 13 VolumeManagerCommon.VolumeType.DRIVE, 'drive',
14 str('DRIVE_DIRECTORY_LABEL'))); 14 str('DRIVE_DIRECTORY_LABEL')));
15 this.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo( 15 this.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo(
16 VolumeManagerCommon.VolumeType.DOWNLOADS, 'downloads', 16 VolumeManagerCommon.VolumeType.DOWNLOADS, 'downloads',
17 str('DOWNLOADS_DIRECTORY_LABEL'))); 17 str('DOWNLOADS_DIRECTORY_LABEL')));
18 } 18 }
19 19
20 /** 20 /**
21 * @private {?VolumeManager}
22 */
23 MockVolumeManager.instance_ = null;
24
25 /**
26 * Replaces the VolumeManager singleton with a MockVolumeManager.
27 * @param {!MockVolumeManager=} opt_singleton
28 */
29 MockVolumeManager.installMockSingleton = function(opt_singleton) {
30 MockVolumeManager.instance_ = opt_singleton || new MockVolumeManager();
31
32 VolumeManager.getInstance = function() {
33 return Promise.resolve(MockVolumeManager.instance_);
34 };
35 };
36
37 /**
21 * Returns the corresponding VolumeInfo. 38 * Returns the corresponding VolumeInfo.
22 * 39 *
23 * @param {MockFileEntry} entry MockFileEntry pointing anywhere on a volume. 40 * @param {MockFileEntry} entry MockFileEntry pointing anywhere on a volume.
24 * @return {VolumeInfo} Corresponding VolumeInfo. 41 * @return {VolumeInfo} Corresponding VolumeInfo.
25 */ 42 */
26 MockVolumeManager.prototype.getVolumeInfo = function(entry) { 43 MockVolumeManager.prototype.getVolumeInfo = function(entry) {
27 for (var i = 0; i < this.volumeInfoList.length; i++) { 44 for (var i = 0; i < this.volumeInfoList.length; i++) {
28 if (this.volumeInfoList.item(i).volumeId === entry.volumeId) 45 if (this.volumeInfoList.item(i).volumeId === entry.volumeId)
29 return this.volumeInfoList.item(i); 46 return this.volumeInfoList.item(i);
30 } 47 }
(...skipping 17 matching lines...) Expand all
48 var volumeInfo = this.volumeInfoList.item(0); 65 var volumeInfo = this.volumeInfoList.item(0);
49 var isRootEntry = entry.fullPath === '/root'; 66 var isRootEntry = entry.fullPath === '/root';
50 return new EntryLocation(volumeInfo, VolumeManagerCommon.RootType.DRIVE, 67 return new EntryLocation(volumeInfo, VolumeManagerCommon.RootType.DRIVE,
51 isRootEntry, true); 68 isRootEntry, true);
52 } 69 }
53 70
54 throw new Error('Not implemented exception.'); 71 throw new Error('Not implemented exception.');
55 }; 72 };
56 73
57 /** 74 /**
75 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
76 * @return {VolumeInfo} Volume info.
77 */
78 MockVolumeManager.prototype.getCurrentProfileVolumeInfo = function(volumeType) {
79 return VolumeManager.prototype.getCurrentProfileVolumeInfo.call(
80 this, volumeType);
81 };
82
83 /**
58 * Utility function to create a mock VolumeInfo. 84 * Utility function to create a mock VolumeInfo.
59 * @param {VolumeType} type Volume type. 85 * @param {VolumeType} type Volume type.
60 * @param {string} volumeId Volume id. 86 * @param {string} volumeId Volume id.
61 * @param {string} label Label. 87 * @param {string} label Label.
62 * @return {VolumeInfo} Created mock VolumeInfo. 88 * @return {VolumeInfo} Created mock VolumeInfo.
63 */ 89 */
64 MockVolumeManager.createMockVolumeInfo = function(type, volumeId, label) { 90 MockVolumeManager.createMockVolumeInfo = function(type, volumeId, label) {
65 var fileSystem = new MockFileSystem(volumeId, 'filesystem:' + volumeId); 91 var fileSystem = new MockFileSystem(volumeId, 'filesystem:' + volumeId);
66 fileSystem.entries['/'] = new MockDirectoryEntry(fileSystem, ''); 92 fileSystem.entries['/'] = new MockDirectoryEntry(fileSystem, '');
67 93
68 var volumeInfo = new VolumeInfo( 94 var volumeInfo = new VolumeInfo(
69 type, 95 type,
70 volumeId, 96 volumeId,
71 fileSystem, 97 fileSystem,
72 '', // error 98 '', // error
73 '', // deviceType 99 '', // deviceType
74 '', // devicePath 100 '', // devicePath
75 false, // isReadonly 101 false, // isReadonly
76 {isCurrentProfile: true, displayName: ''}, // profile 102 {isCurrentProfile: true, displayName: ''}, // profile
77 label, // label 103 label, // label
78 '', // extensionId 104 '', // extensionId
79 false); // hasMedia 105 false); // hasMedia
80 106
81 return volumeInfo; 107 return volumeInfo;
82 }; 108 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698