mock_disk_mount_manager.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #ifndef ASH_COMPONENTS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_
  5. #define ASH_COMPONENTS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "ash/components/disks/disk_mount_manager.h"
  9. #include "base/observer_list.h"
  10. #include "chromeos/ash/components/dbus/cros_disks/cros_disks_client.h"
  11. #include "testing/gmock/include/gmock/gmock.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. namespace ash {
  14. namespace disks {
  15. // TODO(tbarzic): Replace this mock with a fake implementation
  16. // (http://crbug.com/355757)
  17. class MockDiskMountManager : public DiskMountManager {
  18. public:
  19. MockDiskMountManager();
  20. MockDiskMountManager(const MockDiskMountManager&) = delete;
  21. MockDiskMountManager& operator=(const MockDiskMountManager&) = delete;
  22. ~MockDiskMountManager() override;
  23. // DiskMountManager override.
  24. void AddObserver(DiskMountManager::Observer*) override;
  25. void RemoveObserver(DiskMountManager::Observer*) override;
  26. MOCK_METHOD(const DiskMountManager::Disks&, disks, (), (const, override));
  27. MOCK_METHOD(const Disk*,
  28. FindDiskBySourcePath,
  29. (const std::string&),
  30. (const, override));
  31. MOCK_METHOD(const DiskMountManager::MountPoints&,
  32. mount_points,
  33. (),
  34. (const, override));
  35. MOCK_METHOD(void,
  36. EnsureMountInfoRefreshed,
  37. (EnsureMountInfoRefreshedCallback, bool),
  38. (override));
  39. MOCK_METHOD(void,
  40. MountPath,
  41. (const std::string&,
  42. const std::string&,
  43. const std::string&,
  44. const std::vector<std::string>&,
  45. MountType,
  46. MountAccessMode,
  47. DiskMountManager::MountPathCallback),
  48. (override));
  49. MOCK_METHOD(void,
  50. UnmountPath,
  51. (const std::string&, DiskMountManager::UnmountPathCallback),
  52. (override));
  53. MOCK_METHOD(void, RemountAllRemovableDrives, (MountAccessMode), (override));
  54. MOCK_METHOD(void,
  55. FormatMountedDevice,
  56. (const std::string&, FormatFileSystemType, const std::string&),
  57. (override));
  58. MOCK_METHOD(void,
  59. SinglePartitionFormatDevice,
  60. (const std::string&, FormatFileSystemType, const std::string&),
  61. (override));
  62. MOCK_METHOD(void,
  63. RenameMountedDevice,
  64. (const std::string&, const std::string&),
  65. (override));
  66. MOCK_METHOD(void,
  67. UnmountDeviceRecursively,
  68. (const std::string&,
  69. DiskMountManager::UnmountDeviceRecursivelyCallbackType),
  70. (override));
  71. // Invokes fake device insert events.
  72. void NotifyDeviceInsertEvents();
  73. // Invokes fake device remove events.
  74. void NotifyDeviceRemoveEvents();
  75. // Invokes specified mount event.
  76. void NotifyMountEvent(MountEvent event,
  77. MountError error_code,
  78. const MountPoint& mount_info);
  79. // Sets up default results for mock methods.
  80. void SetupDefaultReplies();
  81. // Creates a fake disk entry for the mounted device.
  82. void CreateDiskEntryForMountDevice(std::unique_ptr<Disk> disk);
  83. // Creates a fake disk entry for the mounted device.
  84. void CreateDiskEntryForMountDevice(
  85. const DiskMountManager::MountPoint& mount_info,
  86. const std::string& device_id,
  87. const std::string& device_label,
  88. const std::string& vendor_name,
  89. const std::string& product_name,
  90. DeviceType device_type,
  91. uint64_t total_size_in_bytes,
  92. bool is_parent,
  93. bool has_media,
  94. bool on_boot_device,
  95. bool on_removable_device,
  96. const std::string& file_system_type);
  97. // Removes the fake disk entry associated with the mounted device. This
  98. // function is primarily for StorageMonitorTest.
  99. void RemoveDiskEntryForMountDevice(
  100. const DiskMountManager::MountPoint& mount_info);
  101. private:
  102. // Is used to implement AddObserver.
  103. void AddObserverInternal(DiskMountManager::Observer* observer);
  104. // Is used to implement RemoveObserver.
  105. void RemoveObserverInternal(DiskMountManager::Observer* observer);
  106. // Is used to implement disks.
  107. const DiskMountManager::Disks& disksInternal() const { return disks_; }
  108. const DiskMountManager::MountPoints& mountPointsInternal() const;
  109. // Returns Disk object associated with the |source_path| or NULL on failure.
  110. const Disk* FindDiskBySourcePathInternal(
  111. const std::string& source_path) const;
  112. // Notifies observers about device status update.
  113. void NotifyDeviceChanged(DeviceEvent event,
  114. const std::string& path);
  115. // Notifies observers about disk status update.
  116. void NotifyDiskChanged(DiskEvent event, const Disk* disk);
  117. // The list of observers.
  118. base::ObserverList<DiskMountManager::Observer> observers_;
  119. // The list of disks found.
  120. DiskMountManager::Disks disks_;
  121. // The list of existing mount points.
  122. DiskMountManager::MountPoints mount_points_;
  123. };
  124. } // namespace disks
  125. } // namespace ash
  126. #endif // ASH_COMPONENTS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_