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