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_
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "chromeos/dbus/cros_disks_client.h"
17 // A fake implementation of CrosDiskeClient. This class provides a fake behavior
18 // and the user of this class can raise a fake mouse events.
19 class CHROMEOS_EXPORT FakeCrosDisksClient
: public CrosDisksClient
{
21 FakeCrosDisksClient();
22 virtual ~FakeCrosDisksClient();
24 // CrosDisksClient overrides
25 virtual void Init(dbus::Bus
* bus
) override
;
27 // Performs fake mounting for archive files. Instead of actually extracting
28 // contents of archive files, this function creates a directory that
29 // contains a dummy file.
30 virtual void Mount(const std::string
& source_path
,
31 const std::string
& source_format
,
32 const std::string
& mount_label
,
33 const base::Closure
& callback
,
34 const base::Closure
& error_callback
) override
;
35 // Deletes the directory created in Mount().
36 virtual void Unmount(const std::string
& device_path
,
37 UnmountOptions options
,
38 const base::Closure
& callback
,
39 const base::Closure
& error_callback
) override
;
40 virtual void EnumerateAutoMountableDevices(
41 const EnumerateAutoMountableDevicesCallback
& callback
,
42 const base::Closure
& error_callback
) override
;
43 virtual void EnumerateMountEntries(
44 const EnumerateMountEntriesCallback
& callback
,
45 const base::Closure
& error_callback
) override
;
46 virtual void Format(const std::string
& device_path
,
47 const std::string
& filesystem
,
48 const base::Closure
& callback
,
49 const base::Closure
& error_callback
) override
;
50 virtual void GetDeviceProperties(
51 const std::string
& device_path
,
52 const GetDevicePropertiesCallback
& callback
,
53 const base::Closure
& error_callback
) override
;
54 virtual void SetMountEventHandler(
55 const MountEventHandler
& mount_event_handler
) override
;
56 virtual void SetMountCompletedHandler(
57 const MountCompletedHandler
& mount_completed_handler
) override
;
58 virtual void SetFormatCompletedHandler(
59 const FormatCompletedHandler
& format_completed_handler
) override
;
61 // Used in tests to simulate signals sent by cros disks layer.
62 // Invokes handlers set in |SetMountEventHandler|, |SetMountCompletedHandler|,
63 // and |SetFormatCompletedHandler|.
64 bool SendMountEvent(MountEventType event
, const std::string
& path
);
65 bool SendMountCompletedEvent(MountError error_code
,
66 const std::string
& source_path
,
68 const std::string
& mount_path
);
69 bool SendFormatCompletedEvent(FormatError error_code
,
70 const std::string
& device_path
);
72 // Returns how many times Unmount() was called.
73 int unmount_call_count() const {
74 return unmount_call_count_
;
77 // Returns the |device_path| parameter from the last invocation of Unmount().
78 const std::string
& last_unmount_device_path() const {
79 return last_unmount_device_path_
;
82 // Returns the |options| parameter from the last invocation of Unmount().
83 UnmountOptions
last_unmount_options() const {
84 return last_unmount_options_
;
87 // Makes the subsequent Unmount() calls fail. Unmount() succeeds by default.
88 void MakeUnmountFail() {
89 unmount_success_
= false;
92 // Sets a listener callbackif the following Unmount() call is success or not.
93 // Unmount() calls the corresponding callback given as a parameter.
94 void set_unmount_listener(base::Closure listener
) {
95 unmount_listener_
= listener
;
98 // Returns how many times Format() was called.
99 int format_call_count() const {
100 return format_call_count_
;
103 // Returns the |device_path| parameter from the last invocation of Format().
104 const std::string
& last_format_device_path() const {
105 return last_format_device_path_
;
108 // Returns the |filesystem| parameter from the last invocation of Format().
109 const std::string
& last_format_filesystem() const {
110 return last_format_filesystem_
;
113 // Makes the subsequent Format() calls fail. Format() succeeds by default.
114 void MakeFormatFail() {
115 format_success_
= false;
119 MountEventHandler mount_event_handler_
;
120 MountCompletedHandler mount_completed_handler_
;
121 FormatCompletedHandler format_completed_handler_
;
123 int unmount_call_count_
;
124 std::string last_unmount_device_path_
;
125 UnmountOptions last_unmount_options_
;
126 bool unmount_success_
;
127 base::Closure unmount_listener_
;
128 int format_call_count_
;
129 std::string last_format_device_path_
;
130 std::string last_format_filesystem_
;
131 bool format_success_
;
132 std::set
<base::FilePath
> mounted_paths_
;
135 } // namespace chromeos
137 #endif // CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_