[email protected] | b9f22d1 | 2012-04-25 21:46:48 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4cbead4 | 2012-08-26 12:02:39 | [diff] [blame] | 5 | #ifndef CHROMEOS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_ |
| 6 | #define CHROMEOS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_ |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/observer_list.h" |
[email protected] | dee4c09 | 2012-11-15 02:53:21 | [diff] [blame] | 11 | #include "chromeos/dbus/cros_disks_client.h" |
[email protected] | 4cbead4 | 2012-08-26 12:02:39 | [diff] [blame] | 12 | #include "chromeos/disks/disk_mount_manager.h" |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 13 | #include "testing/gmock/include/gmock/gmock.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
| 16 | namespace chromeos { |
| 17 | namespace disks { |
| 18 | |
[email protected] | 6b091d97 | 2014-03-30 18:21:12 | [diff] [blame] | 19 | // TODO(tbarzic): Replace this mock with a fake implementation |
| 20 | // (http://crbug.com/355757) |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 21 | class MockDiskMountManager : public DiskMountManager { |
| 22 | public: |
| 23 | MockDiskMountManager(); |
| 24 | virtual ~MockDiskMountManager(); |
| 25 | |
| 26 | // DiskMountManager override. |
| 27 | MOCK_METHOD0(Init, void(void)); |
| 28 | MOCK_METHOD1(AddObserver, void(DiskMountManager::Observer*)); |
| 29 | MOCK_METHOD1(RemoveObserver, void(DiskMountManager::Observer*)); |
| 30 | MOCK_CONST_METHOD0(disks, const DiskMountManager::DiskMap&(void)); |
[email protected] | bcfa007 | 2012-08-07 01:08:57 | [diff] [blame] | 31 | MOCK_CONST_METHOD1(FindDiskBySourcePath, |
| 32 | const DiskMountManager::Disk*(const std::string&)); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 33 | MOCK_CONST_METHOD0(mount_points, |
| 34 | const DiskMountManager::MountPointMap&(void)); |
hirono | a4b675d | 2015-07-29 01:13:37 | [diff] [blame] | 35 | MOCK_METHOD2(EnsureMountInfoRefreshed, |
| 36 | void(const EnsureMountInfoRefreshedCallback&, bool)); |
[email protected] | dcad8fc | 2012-04-30 23:31:33 | [diff] [blame] | 37 | MOCK_METHOD4(MountPath, void(const std::string&, const std::string&, |
| 38 | const std::string&, MountType)); |
[email protected] | 8f919ee | 2013-03-14 19:53:29 | [diff] [blame] | 39 | MOCK_METHOD3(UnmountPath, void(const std::string&, |
| 40 | UnmountOptions, |
| 41 | const DiskMountManager::UnmountPathCallback&)); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 42 | MOCK_METHOD1(FormatMountedDevice, void(const std::string&)); |
[email protected] | e008d4fa | 2013-02-21 06:38:01 | [diff] [blame] | 43 | MOCK_METHOD2( |
| 44 | UnmountDeviceRecursively, |
| 45 | void(const std::string&, |
| 46 | const DiskMountManager::UnmountDeviceRecursivelyCallbackType&)); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 47 | |
| 48 | // Invokes fake device insert events. |
| 49 | void NotifyDeviceInsertEvents(); |
| 50 | |
| 51 | // Invokes fake device remove events. |
| 52 | void NotifyDeviceRemoveEvents(); |
| 53 | |
| 54 | // Sets up default results for mock methods. |
| 55 | void SetupDefaultReplies(); |
| 56 | |
[email protected] | 9c5620d3 | 2012-07-31 01:00:38 | [diff] [blame] | 57 | // Creates a fake disk entry for the mounted device. This function is |
[email protected] | 5cfc0942 | 2013-03-04 23:48:42 | [diff] [blame] | 58 | // primarily for StorageMonitorTest. |
[email protected] | 9c5620d3 | 2012-07-31 01:00:38 | [diff] [blame] | 59 | void CreateDiskEntryForMountDevice( |
| 60 | const DiskMountManager::MountPointInfo& mount_info, |
[email protected] | 48faf41 | 2012-09-17 07:41:43 | [diff] [blame] | 61 | const std::string& device_id, |
[email protected] | dee4c09 | 2012-11-15 02:53:21 | [diff] [blame] | 62 | const std::string& device_label, |
| 63 | const std::string& vendor_name, |
| 64 | const std::string& product_name, |
| 65 | DeviceType device_type, |
[email protected] | 6b091d97 | 2014-03-30 18:21:12 | [diff] [blame] | 66 | uint64 total_size_in_bytes, |
| 67 | bool is_parent, |
| 68 | bool has_media, |
[email protected] | 79ed457b | 2014-07-22 04:07:26 | [diff] [blame] | 69 | bool on_boot_device, |
| 70 | bool on_removable_device); |
[email protected] | 9c5620d3 | 2012-07-31 01:00:38 | [diff] [blame] | 71 | |
| 72 | // Removes the fake disk entry associated with the mounted device. This |
[email protected] | 5cfc0942 | 2013-03-04 23:48:42 | [diff] [blame] | 73 | // function is primarily for StorageMonitorTest. |
[email protected] | 9c5620d3 | 2012-07-31 01:00:38 | [diff] [blame] | 74 | void RemoveDiskEntryForMountDevice( |
| 75 | const DiskMountManager::MountPointInfo& mount_info); |
| 76 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 77 | private: |
| 78 | // Is used to implement AddObserver. |
| 79 | void AddObserverInternal(DiskMountManager::Observer* observer); |
| 80 | |
| 81 | // Is used to implement RemoveObserver. |
| 82 | void RemoveObserverInternal(DiskMountManager::Observer* observer); |
| 83 | |
| 84 | // Is used to implement disks. |
| 85 | const DiskMountManager::DiskMap& disksInternal() const { return disks_; } |
| 86 | |
[email protected] | cd66eab | 2012-08-03 21:55:37 | [diff] [blame] | 87 | const DiskMountManager::MountPointMap& mountPointsInternal() const; |
| 88 | |
[email protected] | bcfa007 | 2012-08-07 01:08:57 | [diff] [blame] | 89 | // Returns Disk object associated with the |source_path| or NULL on failure. |
| 90 | const DiskMountManager::Disk* FindDiskBySourcePathInternal( |
| 91 | const std::string& source_path) const; |
| 92 | |
[email protected] | a2e4ee2 | 2014-07-11 05:16:35 | [diff] [blame] | 93 | // Is used to implement EnsureMountInfoRefreshed. |
| 94 | void EnsureMountInfoRefreshedInternal( |
hirono | a4b675d | 2015-07-29 01:13:37 | [diff] [blame] | 95 | const EnsureMountInfoRefreshedCallback& callback, |
| 96 | bool force); |
[email protected] | a2e4ee2 | 2014-07-11 05:16:35 | [diff] [blame] | 97 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 98 | // Notifies observers about device status update. |
[email protected] | e3c1fc9 | 2012-11-15 00:56:46 | [diff] [blame] | 99 | void NotifyDeviceChanged(DeviceEvent event, |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 100 | const std::string& path); |
| 101 | |
| 102 | // Notifies observers about disk status update. |
[email protected] | e3c1fc9 | 2012-11-15 00:56:46 | [diff] [blame] | 103 | void NotifyDiskChanged(DiskEvent event, |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 104 | const DiskMountManager::Disk* disk); |
| 105 | |
| 106 | // The list of observers. |
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 107 | base::ObserverList<DiskMountManager::Observer> observers_; |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 108 | |
| 109 | // The list of disks found. |
| 110 | DiskMountManager::DiskMap disks_; |
| 111 | |
[email protected] | cd66eab | 2012-08-03 21:55:37 | [diff] [blame] | 112 | // The list of existing mount points. |
| 113 | DiskMountManager::MountPointMap mount_points_; |
| 114 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 115 | DISALLOW_COPY_AND_ASSIGN(MockDiskMountManager); |
| 116 | }; |
| 117 | |
| 118 | } // namespace disks |
| 119 | } // namespace chromeos |
| 120 | |
[email protected] | 4cbead4 | 2012-08-26 12:02:39 | [diff] [blame] | 121 | #endif // CHROMEOS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_ |