• 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 EnumerateMountEntries(
37       const EnumerateMountEntriesCallback& callback,
38       const base::Closure& error_callback) OVERRIDE;
39   virtual void Format(const std::string& device_path,
40                       const std::string& filesystem,
41                       const base::Closure& callback,
42                       const base::Closure& error_callback) OVERRIDE;
43   virtual void GetDeviceProperties(
44       const std::string& device_path,
45       const GetDevicePropertiesCallback& callback,
46       const base::Closure& error_callback) OVERRIDE;
47   virtual void SetMountEventHandler(
48       const MountEventHandler& mount_event_handler) OVERRIDE;
49   virtual void SetMountCompletedHandler(
50       const MountCompletedHandler& mount_completed_handler) OVERRIDE;
51   virtual void SetFormatCompletedHandler(
52       const FormatCompletedHandler& format_completed_handler) OVERRIDE;
53 
54   // Used in tests to simulate signals sent by cros disks layer.
55   // Invokes handlers set in |SetMountEventHandler|, |SetMountCompletedHandler|,
56   // and |SetFormatCompletedHandler|.
57   bool SendMountEvent(MountEventType event, const std::string& path);
58   bool SendMountCompletedEvent(MountError error_code,
59                                const std::string& source_path,
60                                MountType mount_type,
61                                const std::string& mount_path);
62   bool SendFormatCompletedEvent(FormatError error_code,
63                                 const std::string& device_path);
64 
65   // Returns how many times Unmount() was called.
unmount_call_count()66   int unmount_call_count() const {
67     return unmount_call_count_;
68   }
69 
70   // Returns the |device_path| parameter from the last invocation of Unmount().
last_unmount_device_path()71   const std::string& last_unmount_device_path() const {
72     return last_unmount_device_path_;
73   }
74 
75   // Returns the |options| parameter from the last invocation of Unmount().
last_unmount_options()76   UnmountOptions last_unmount_options() const {
77     return last_unmount_options_;
78   }
79 
80   // Makes the subsequent Unmount() calls fail. Unmount() succeeds by default.
MakeUnmountFail()81   void MakeUnmountFail() {
82     unmount_success_ = false;
83   }
84 
85   // Sets a listener callbackif the following Unmount() call is success or not.
86   // Unmount() calls the corresponding callback given as a parameter.
set_unmount_listener(base::Closure listener)87   void set_unmount_listener(base::Closure listener) {
88     unmount_listener_ = listener;
89   }
90 
91   // Returns how many times Format() was called.
format_call_count()92   int format_call_count() const {
93     return format_call_count_;
94   }
95 
96   // Returns the |device_path| parameter from the last invocation of Format().
last_format_device_path()97   const std::string& last_format_device_path() const {
98     return last_format_device_path_;
99   }
100 
101   // Returns the |filesystem| parameter from the last invocation of Format().
last_format_filesystem()102   const std::string& last_format_filesystem() const {
103     return last_format_filesystem_;
104   }
105 
106   // Makes the subsequent Format() calls fail. Format() succeeds by default.
MakeFormatFail()107   void MakeFormatFail() {
108     format_success_ = false;
109   }
110 
111  private:
112   MountEventHandler mount_event_handler_;
113   MountCompletedHandler mount_completed_handler_;
114   FormatCompletedHandler format_completed_handler_;
115 
116   int unmount_call_count_;
117   std::string last_unmount_device_path_;
118   UnmountOptions last_unmount_options_;
119   bool unmount_success_;
120   base::Closure unmount_listener_;
121   int format_call_count_;
122   std::string last_format_device_path_;
123   std::string last_format_filesystem_;
124   bool format_success_;
125 };
126 
127 }  // namespace chromeos
128 
129 #endif  // CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_
130