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 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
;
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
,
54 const std::string
& mount_path
);
56 // Returns how many times Unmount() was called.
57 int unmount_call_count() const {
58 return unmount_call_count_
;
61 // Returns the |device_path| parameter from the last invocation of Unmount().
62 const std::string
& last_unmount_device_path() const {
63 return last_unmount_device_path_
;
66 // Returns the |options| parameter from the last invocation of Unmount().
67 UnmountOptions
last_unmount_options() const {
68 return last_unmount_options_
;
71 // Makes the subsequent Unmount() calls fail. Unmount() succeeds by default.
72 void MakeUnmountFail() {
73 unmount_success_
= false;
76 // Sets a listener callbackif the following Unmount() call is success or not.
77 // Unmount() calls the corresponding callback given as a parameter.
78 void set_unmount_listener(base::Closure listener
) {
79 unmount_listener_
= listener
;
82 // Returns how many times FormatDevice() was called.
83 int format_device_call_count() const {
84 return format_device_call_count_
;
87 // Returns the |device_path| parameter from the last invocation of
89 const std::string
& last_format_device_device_path() const {
90 return last_format_device_device_path_
;
93 // Returns the |filesystem| parameter from the last invocation of
95 const std::string
& last_format_device_filesystem() const {
96 return last_format_device_filesystem_
;
99 // Makes the subsequent FormatDevice() calls fail. FormatDevice() succeeds by
101 void MakeFormatDeviceFail() {
102 format_device_success_
= false;
106 MountEventHandler mount_event_handler_
;
107 MountCompletedHandler mount_completed_handler_
;
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_
;
120 } // namespace chromeos
122 #endif // CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_