Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / fake_cros_disks_client.h
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 <set>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "chromeos/dbus/cros_disks_client.h"
14
15 namespace chromeos {
16
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   virtual ~FakeCrosDisksClient();
23
24   // CrosDisksClient overrides
25   virtual void Init(dbus::Bus* bus) override;
26
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;
60
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,
67                                MountType mount_type,
68                                const std::string& mount_path);
69   bool SendFormatCompletedEvent(FormatError error_code,
70                                 const std::string& device_path);
71
72   // Returns how many times Unmount() was called.
73   int unmount_call_count() const {
74     return unmount_call_count_;
75   }
76
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_;
80   }
81
82   // Returns the |options| parameter from the last invocation of Unmount().
83   UnmountOptions last_unmount_options() const {
84     return last_unmount_options_;
85   }
86
87   // Makes the subsequent Unmount() calls fail. Unmount() succeeds by default.
88   void MakeUnmountFail() {
89     unmount_success_ = false;
90   }
91
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;
96   }
97
98   // Returns how many times Format() was called.
99   int format_call_count() const {
100     return format_call_count_;
101   }
102
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_;
106   }
107
108   // Returns the |filesystem| parameter from the last invocation of Format().
109   const std::string& last_format_filesystem() const {
110     return last_format_filesystem_;
111   }
112
113   // Makes the subsequent Format() calls fail. Format() succeeds by default.
114   void MakeFormatFail() {
115     format_success_ = false;
116   }
117
118  private:
119   MountEventHandler mount_event_handler_;
120   MountCompletedHandler mount_completed_handler_;
121   FormatCompletedHandler format_completed_handler_;
122
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_;
133 };
134
135 }  // namespace chromeos
136
137 #endif  // CHROMEOS_DBUS_FAKE_CROS_DISKS_CLIENT_H_