Home | History | Annotate | Download | only in disks
      1 // Copyright (c) 2012 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 #ifndef CHROMEOS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_
      6 #define CHROMEOS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/observer_list.h"
     11 #include "chromeos/dbus/cros_disks_client.h"
     12 #include "chromeos/disks/disk_mount_manager.h"
     13 #include "testing/gmock/include/gmock/gmock.h"
     14 #include "testing/gtest/include/gtest/gtest.h"
     15 
     16 namespace chromeos {
     17 namespace disks {
     18 
     19 // TODO(tbarzic): Replace this mock with a fake implementation
     20 // (http://crbug.com/355757)
     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));
     31   MOCK_CONST_METHOD1(FindDiskBySourcePath,
     32                      const DiskMountManager::Disk*(const std::string&));
     33   MOCK_CONST_METHOD0(mount_points,
     34                      const DiskMountManager::MountPointMap&(void));
     35   MOCK_METHOD1(EnsureMountInfoRefreshed,
     36                void(const EnsureMountInfoRefreshedCallback&));
     37   MOCK_METHOD4(MountPath, void(const std::string&, const std::string&,
     38                                const std::string&, MountType));
     39   MOCK_METHOD3(UnmountPath, void(const std::string&,
     40                                  UnmountOptions,
     41                                  const DiskMountManager::UnmountPathCallback&));
     42   MOCK_METHOD1(FormatMountedDevice, void(const std::string&));
     43   MOCK_METHOD2(
     44       UnmountDeviceRecursively,
     45       void(const std::string&,
     46            const DiskMountManager::UnmountDeviceRecursivelyCallbackType&));
     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 
     57   // Creates a fake disk entry for the mounted device. This function is
     58   // primarily for StorageMonitorTest.
     59   void CreateDiskEntryForMountDevice(
     60       const DiskMountManager::MountPointInfo& mount_info,
     61       const std::string& device_id,
     62       const std::string& device_label,
     63       const std::string& vendor_name,
     64       const std::string& product_name,
     65       DeviceType device_type,
     66       uint64 total_size_in_bytes,
     67       bool is_parent,
     68       bool has_media,
     69       bool on_boot_device,
     70       bool on_removable_device);
     71 
     72   // Removes the fake disk entry associated with the mounted device. This
     73   // function is primarily for StorageMonitorTest.
     74   void RemoveDiskEntryForMountDevice(
     75       const DiskMountManager::MountPointInfo& mount_info);
     76 
     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 
     87   const DiskMountManager::MountPointMap& mountPointsInternal() const;
     88 
     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 
     93   // Is used to implement EnsureMountInfoRefreshed.
     94   void EnsureMountInfoRefreshedInternal(
     95       const EnsureMountInfoRefreshedCallback& callback);
     96 
     97   // Notifies observers about device status update.
     98   void NotifyDeviceChanged(DeviceEvent event,
     99                            const std::string& path);
    100 
    101   // Notifies observers about disk status update.
    102   void NotifyDiskChanged(DiskEvent event,
    103                          const DiskMountManager::Disk* disk);
    104 
    105   // The list of observers.
    106   ObserverList<DiskMountManager::Observer> observers_;
    107 
    108   // The list of disks found.
    109   DiskMountManager::DiskMap disks_;
    110 
    111   // The list of existing mount points.
    112   DiskMountManager::MountPointMap mount_points_;
    113 
    114   DISALLOW_COPY_AND_ASSIGN(MockDiskMountManager);
    115 };
    116 
    117 }  // namespace disks
    118 }  // namespace chromeos
    119 
    120 #endif  // CHROMEOS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_
    121