[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / chromeos / dbus / fake_cros_disks_client.h
blobea96ad1aa524c02f453f2c6c3351cd733a6329f6
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_
8 #include <set>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "chromeos/dbus/cros_disks_client.h"
15 namespace chromeos {
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 {
20 public:
21 FakeCrosDisksClient();
22 ~FakeCrosDisksClient() override;
24 // CrosDisksClient overrides
25 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 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 void Unmount(const std::string& device_path,
37 UnmountOptions options,
38 const base::Closure& callback,
39 const base::Closure& error_callback) override;
40 void EnumerateAutoMountableDevices(
41 const EnumerateAutoMountableDevicesCallback& callback,
42 const base::Closure& error_callback) override;
43 void EnumerateMountEntries(const EnumerateMountEntriesCallback& callback,
44 const base::Closure& error_callback) override;
45 void Format(const std::string& device_path,
46 const std::string& filesystem,
47 const base::Closure& callback,
48 const base::Closure& error_callback) override;
49 void GetDeviceProperties(const std::string& device_path,
50 const GetDevicePropertiesCallback& callback,
51 const base::Closure& error_callback) override;
52 void SetMountEventHandler(
53 const MountEventHandler& mount_event_handler) override;
54 void SetMountCompletedHandler(
55 const MountCompletedHandler& mount_completed_handler) override;
56 void SetFormatCompletedHandler(
57 const FormatCompletedHandler& format_completed_handler) override;
59 // Used in tests to simulate signals sent by cros disks layer.
60 // Invokes handlers set in |SetMountEventHandler|, |SetMountCompletedHandler|,
61 // and |SetFormatCompletedHandler|.
62 bool SendMountEvent(MountEventType event, const std::string& path);
63 bool SendMountCompletedEvent(MountError error_code,
64 const std::string& source_path,
65 MountType mount_type,
66 const std::string& mount_path);
67 bool SendFormatCompletedEvent(FormatError error_code,
68 const std::string& device_path);
70 // Returns how many times Unmount() was called.
71 int unmount_call_count() const {
72 return unmount_call_count_;
75 // Returns the |device_path| parameter from the last invocation of Unmount().
76 const std::string& last_unmount_device_path() const {
77 return last_unmount_device_path_;
80 // Returns the |options| parameter from the last invocation of Unmount().
81 UnmountOptions last_unmount_options() const {
82 return last_unmount_options_;
85 // Makes the subsequent Unmount() calls fail. Unmount() succeeds by default.
86 void MakeUnmountFail() {
87 unmount_success_ = false;
90 // Sets a listener callbackif the following Unmount() call is success or not.
91 // Unmount() calls the corresponding callback given as a parameter.
92 void set_unmount_listener(base::Closure listener) {
93 unmount_listener_ = listener;
96 // Returns how many times Format() was called.
97 int format_call_count() const {
98 return format_call_count_;
101 // Returns the |device_path| parameter from the last invocation of Format().
102 const std::string& last_format_device_path() const {
103 return last_format_device_path_;
106 // Returns the |filesystem| parameter from the last invocation of Format().
107 const std::string& last_format_filesystem() const {
108 return last_format_filesystem_;
111 // Makes the subsequent Format() calls fail. Format() succeeds by default.
112 void MakeFormatFail() {
113 format_success_ = false;
116 private:
117 MountEventHandler mount_event_handler_;
118 MountCompletedHandler mount_completed_handler_;
119 FormatCompletedHandler format_completed_handler_;
121 int unmount_call_count_;
122 std::string last_unmount_device_path_;
123 UnmountOptions last_unmount_options_;
124 bool unmount_success_;
125 base::Closure unmount_listener_;
126 int format_call_count_;
127 std::string last_format_device_path_;
128 std::string last_format_filesystem_;
129 bool format_success_;
130 std::set<base::FilePath> mounted_paths_;
133 } // namespace chromeos
135 #endif // CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_