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.
5 #ifndef CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_
10 #include "base/callback.h"
11 #include "chromeos/dbus/cros_disks_client.h"
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
{
19 FakeCrosDisksClient();
20 virtual ~FakeCrosDisksClient();
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 Format(const std::string
& device_path
,
37 const std::string
& filesystem
,
38 const base::Closure
& 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 SetMountEventHandler(
45 const MountEventHandler
& mount_event_handler
) OVERRIDE
;
46 virtual void SetMountCompletedHandler(
47 const MountCompletedHandler
& mount_completed_handler
) OVERRIDE
;
48 virtual void SetFormatCompletedHandler(
49 const FormatCompletedHandler
& format_completed_handler
) OVERRIDE
;
51 // Used in tests to simulate signals sent by cros disks layer.
52 // Invokes handlers set in |SetMountEventHandler|, |SetMountCompletedHandler|,
53 // and |SetFormatCompletedHandler|.
54 bool SendMountEvent(MountEventType event
, const std::string
& path
);
55 bool SendMountCompletedEvent(MountError error_code
,
56 const std::string
& source_path
,
58 const std::string
& mount_path
);
59 bool SendFormatCompletedEvent(FormatError error_code
,
60 const std::string
& device_path
);
62 // Returns how many times Unmount() was called.
63 int unmount_call_count() const {
64 return unmount_call_count_
;
67 // Returns the |device_path| parameter from the last invocation of Unmount().
68 const std::string
& last_unmount_device_path() const {
69 return last_unmount_device_path_
;
72 // Returns the |options| parameter from the last invocation of Unmount().
73 UnmountOptions
last_unmount_options() const {
74 return last_unmount_options_
;
77 // Makes the subsequent Unmount() calls fail. Unmount() succeeds by default.
78 void MakeUnmountFail() {
79 unmount_success_
= false;
82 // Sets a listener callbackif the following Unmount() call is success or not.
83 // Unmount() calls the corresponding callback given as a parameter.
84 void set_unmount_listener(base::Closure listener
) {
85 unmount_listener_
= listener
;
88 // Returns how many times Format() was called.
89 int format_call_count() const {
90 return format_call_count_
;
93 // Returns the |device_path| parameter from the last invocation of Format().
94 const std::string
& last_format_device_path() const {
95 return last_format_device_path_
;
98 // Returns the |filesystem| parameter from the last invocation of Format().
99 const std::string
& last_format_filesystem() const {
100 return last_format_filesystem_
;
103 // Makes the subsequent Format() calls fail. Format() succeeds by default.
104 void MakeFormatFail() {
105 format_success_
= false;
109 MountEventHandler mount_event_handler_
;
110 MountCompletedHandler mount_completed_handler_
;
111 FormatCompletedHandler format_completed_handler_
;
113 int unmount_call_count_
;
114 std::string last_unmount_device_path_
;
115 UnmountOptions last_unmount_options_
;
116 bool unmount_success_
;
117 base::Closure unmount_listener_
;
118 int format_call_count_
;
119 std::string last_format_device_path_
;
120 std::string last_format_filesystem_
;
121 bool format_success_
;
124 } // namespace chromeos
126 #endif // CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_