• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 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_DBUS_FAKE_CROS_DISKS_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_
7 
8 #include <string>
9 
10 #include "base/callback.h"
11 #include "chromeos/dbus/cros_disks_client.h"
12 
13 namespace chromeos {
14 
15 // A fake implementation of CrosDiskeClient. This class provides a fake behavior
16 // and the user of this class can raise a fake mouse events.
17 class FakeCrosDisksClient : public CrosDisksClient {
18  public:
19   FakeCrosDisksClient();
20   virtual ~FakeCrosDisksClient();
21 
22   // CrosDisksClient overrides
23   virtual void Init(dbus::Bus* bus) OVERRIDE;
24   virtual void Mount(const std::string& source_path,
25                      const std::string& source_format,
26                      const std::string& mount_label,
27                      const base::Closure& callback,
28                      const base::Closure& error_callback) OVERRIDE;
29   virtual void Unmount(const std::string& device_path,
30                        UnmountOptions options,
31                        const base::Closure& callback,
32                        const base::Closure& error_callback) OVERRIDE;
33   virtual void EnumerateAutoMountableDevices(
34       const EnumerateAutoMountableDevicesCallback& callback,
35       const base::Closure& error_callback) OVERRIDE;
36   virtual void FormatDevice(const std::string& device_path,
37                             const std::string& filesystem,
38                             const FormatDeviceCallback& callback,
39                             const base::Closure& error_callback) OVERRIDE;
40   virtual void GetDeviceProperties(
41       const std::string& device_path,
42       const GetDevicePropertiesCallback& callback,
43       const base::Closure& error_callback) OVERRIDE;
44   virtual void SetUpConnections(
45       const MountEventHandler& mount_event_handler,
46       const MountCompletedHandler& mount_completed_handler) OVERRIDE;
47 
48   // Used in tests to simulate signals sent by cros disks layer.
49   // Invokes handlers set in |SetUpConnections|.
50   bool SendMountEvent(MountEventType event, const std::string& path);
51   bool SendMountCompletedEvent(MountError error_code,
52                                const std::string& source_path,
53                                MountType mount_type,
54                                const std::string& mount_path);
55 
56   // Returns how many times Unmount() was called.
unmount_call_count()57   int unmount_call_count() const {
58     return unmount_call_count_;
59   }
60 
61   // Returns the |device_path| parameter from the last invocation of Unmount().
last_unmount_device_path()62   const std::string& last_unmount_device_path() const {
63     return last_unmount_device_path_;
64   }
65 
66   // Returns the |options| parameter from the last invocation of Unmount().
last_unmount_options()67   UnmountOptions last_unmount_options() const {
68     return last_unmount_options_;
69   }
70 
71   // Makes the subsequent Unmount() calls fail. Unmount() succeeds by default.
MakeUnmountFail()72   void MakeUnmountFail() {
73     unmount_success_ = false;
74   }
75 
76   // Sets a listener callbackif the following Unmount() call is success or not.
77   // Unmount() calls the corresponding callback given as a parameter.
set_unmount_listener(base::Closure listener)78   void set_unmount_listener(base::Closure listener) {
79     unmount_listener_ = listener;
80   }
81 
82   // Returns how many times FormatDevice() was called.
format_device_call_count()83   int format_device_call_count() const {
84     return format_device_call_count_;
85   }
86 
87   // Returns the |device_path| parameter from the last invocation of
88   // FormatDevice().
last_format_device_device_path()89   const std::string& last_format_device_device_path() const {
90     return last_format_device_device_path_;
91   }
92 
93   // Returns the |filesystem| parameter from the last invocation of
94   // FormatDevice().
last_format_device_filesystem()95   const std::string& last_format_device_filesystem() const {
96     return last_format_device_filesystem_;
97   }
98 
99   // Makes the subsequent FormatDevice() calls fail. FormatDevice() succeeds by
100   // default.
MakeFormatDeviceFail()101   void MakeFormatDeviceFail() {
102     format_device_success_ = false;
103   }
104 
105  private:
106   MountEventHandler mount_event_handler_;
107   MountCompletedHandler mount_completed_handler_;
108 
109   int unmount_call_count_;
110   std::string last_unmount_device_path_;
111   UnmountOptions last_unmount_options_;
112   bool unmount_success_;
113   base::Closure unmount_listener_;
114   int format_device_call_count_;
115   std::string last_format_device_device_path_;
116   std::string last_format_device_filesystem_;
117   bool format_device_success_;
118 };
119 
120 }  // namespace chromeos
121 
122 #endif  // CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_
123