File: mock_disk_mount_manager.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (136 lines) | stat: -rw-r--r-- 4,632 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_
#define CHROMEOS_ASH_COMPONENTS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_

#include <stdint.h>

#include <string>

#include "base/observer_list.h"
#include "chromeos/ash/components/dbus/cros_disks/cros_disks_client.h"
#include "chromeos/ash/components/disks/disk_mount_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace ash {
namespace disks {

// TODO(tbarzic): Replace this mock with a fake implementation
// (http://crbug.com/355757)
class MockDiskMountManager : public DiskMountManager {
 public:
  MockDiskMountManager();

  MockDiskMountManager(const MockDiskMountManager&) = delete;
  MockDiskMountManager& operator=(const MockDiskMountManager&) = delete;

  ~MockDiskMountManager() override;

  // DiskMountManager override.
  void AddObserver(DiskMountManager::Observer*) override;
  void RemoveObserver(DiskMountManager::Observer*) override;
  MOCK_METHOD(const DiskMountManager::Disks&, disks, (), (const, override));
  MOCK_METHOD(const Disk*,
              FindDiskBySourcePath,
              (std::string_view),
              (const, override));
  MOCK_METHOD(const DiskMountManager::MountPoints&,
              mount_points,
              (),
              (const, override));
  MOCK_METHOD(void,
              EnsureMountInfoRefreshed,
              (EnsureMountInfoRefreshedCallback, bool),
              (override));
  MOCK_METHOD(void,
              MountPath,
              (const std::string&,
               const std::string&,
               const std::string&,
               const std::vector<std::string>&,
               MountType,
               MountAccessMode,
               DiskMountManager::MountPathCallback),
              (override));
  MOCK_METHOD(void,
              UnmountPath,
              (const std::string&, DiskMountManager::UnmountPathCallback),
              (override));
  MOCK_METHOD(void,
              RemountRemovableDrive,
              (const Disk&, MountAccessMode),
              (override));
  MOCK_METHOD(void,
              FormatMountedDevice,
              (const std::string&, FormatFileSystemType, const std::string&),
              (override));
  MOCK_METHOD(void,
              SinglePartitionFormatDevice,
              (const std::string&, FormatFileSystemType, const std::string&),
              (override));
  MOCK_METHOD(void,
              RenameMountedDevice,
              (const std::string&, const std::string&),
              (override));
  MOCK_METHOD(void,
              UnmountDeviceRecursively,
              (const std::string&,
               DiskMountManager::UnmountDeviceRecursivelyCallbackType),
              (override));

  // Invokes specified mount event.
  void NotifyMountEvent(MountEvent event,
                        MountError error_code,
                        const MountPoint& mount_info);

  // Sets up default results for mock methods.
  void SetupDefaultReplies();

  bool AddDiskForTest(std::unique_ptr<Disk> disk) override;

  // Creates a fake disk entry for the mounted device.
  void CreateDiskEntryForMountDevice(
      const DiskMountManager::MountPoint& mount_info,
      const std::string& device_id,
      const std::string& device_label,
      const std::string& vendor_name,
      const std::string& product_name,
      DeviceType device_type,
      uint64_t total_size_in_bytes,
      bool is_parent,
      bool has_media,
      bool on_boot_device,
      bool on_removable_device,
      const std::string& file_system_type);

  // Removes the fake disk entry associated with the mounted device. This
  // function is primarily for StorageMonitorTest.
  void RemoveDiskEntryForMountDevice(
      const DiskMountManager::MountPoint& mount_info);

 private:
  // Is used to implement disks.
  const DiskMountManager::Disks& disksInternal() const { return disks_; }

  const DiskMountManager::MountPoints& mountPointsInternal() const;

  // Returns Disk object associated with the |source_path| or NULL on failure.
  const Disk* FindDiskBySourcePathInternal(std::string_view source_path) const;

  // The list of observers.
  base::ObserverList<DiskMountManager::Observer> observers_;

  // The list of disks found.
  DiskMountManager::Disks disks_;

  // The list of existing mount points.
  DiskMountManager::MountPoints mount_points_;
};

}  // namespace disks
}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_DISKS_MOCK_DISK_MOUNT_MANAGER_H_