Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/chromeos/disks/mock_disk_mount_manager.cc

Issue 10874067: chromeos: Move src/chrome/browser/chromeos/disks to src/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h"
6
7 #include <utility>
8
9 #include "base/message_loop.h"
10 #include "base/stl_util.h"
11 #include "base/string_util.h"
12 #include "content/public/browser/browser_thread.h"
13
14 using content::BrowserThread;
15 using testing::_;
16 using testing::AnyNumber;
17 using testing::Invoke;
18 using testing::ReturnRef;
19
20 namespace chromeos {
21 namespace disks {
22
23 namespace {
24
25 const char* kTestSystemPath = "/this/system/path";
26 const char* kTestSystemPathPrefix = "/this/system";
27 const char* kTestDevicePath = "/this/device/path";
28 const char* kTestMountPath = "/media/foofoo";
29 const char* kTestFilePath = "/this/file/path";
30 const char* kTestDeviceLabel = "A label";
31 const char* kTestDriveLabel = "Another label";
32 const char* kTestUuid = "FFFF-FFFF";
33
34 } // namespace
35
36 void MockDiskMountManager::AddObserverInternal(
37 DiskMountManager::Observer* observer) {
38 observers_.AddObserver(observer);
39 }
40
41 void MockDiskMountManager::RemoveObserverInternal(
42 DiskMountManager::Observer* observer) {
43 observers_.RemoveObserver(observer);
44 }
45
46 MockDiskMountManager::MockDiskMountManager() {
47 ON_CALL(*this, AddObserver(_))
48 .WillByDefault(Invoke(this, &MockDiskMountManager::AddObserverInternal));
49 ON_CALL(*this, RemoveObserver(_))
50 .WillByDefault(Invoke(this,
51 &MockDiskMountManager::RemoveObserverInternal));
52 ON_CALL(*this, disks())
53 .WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal));
54 ON_CALL(*this, mount_points())
55 .WillByDefault(Invoke(this, &MockDiskMountManager::mountPointsInternal));
56 ON_CALL(*this, FindDiskBySourcePath(_))
57 .WillByDefault(Invoke(
58 this, &MockDiskMountManager::FindDiskBySourcePathInternal));
59 }
60
61 MockDiskMountManager::~MockDiskMountManager() {
62 STLDeleteContainerPairSecondPointers(disks_.begin(), disks_.end());
63 disks_.clear();
64 }
65
66 void MockDiskMountManager::NotifyDeviceInsertEvents() {
67 scoped_ptr<DiskMountManager::Disk> disk1(new DiskMountManager::Disk(
68 std::string(kTestDevicePath),
69 std::string(),
70 std::string(kTestSystemPath),
71 std::string(kTestFilePath),
72 std::string(),
73 std::string(kTestDriveLabel),
74 std::string(kTestUuid),
75 std::string(kTestSystemPathPrefix),
76 DEVICE_TYPE_USB,
77 4294967295U,
78 false, // is_parent
79 false, // is_read_only
80 true, // has_media
81 false, // on_boot_device
82 false)); // is_hidden
83
84 disks_.clear();
85 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
86 std::string(kTestDevicePath), disk1.get()));
87
88 // Device Added
89 DiskMountManagerEventType event;
90 event = MOUNT_DEVICE_ADDED;
91 NotifyDeviceChanged(event, kTestSystemPath);
92
93 // Disk Added
94 event = MOUNT_DISK_ADDED;
95 NotifyDiskChanged(event, disk1.get());
96
97 // Disk Changed
98 scoped_ptr<DiskMountManager::Disk> disk2(new DiskMountManager::Disk(
99 std::string(kTestDevicePath),
100 std::string(kTestMountPath),
101 std::string(kTestSystemPath),
102 std::string(kTestFilePath),
103 std::string(kTestDeviceLabel),
104 std::string(kTestDriveLabel),
105 std::string(kTestUuid),
106 std::string(kTestSystemPathPrefix),
107 DEVICE_TYPE_MOBILE,
108 1073741824,
109 false, // is_parent
110 false, // is_read_only
111 true, // has_media
112 false, // on_boot_device
113 false)); // is_hidden
114 disks_.clear();
115 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
116 std::string(kTestDevicePath), disk2.get()));
117 event = MOUNT_DISK_CHANGED;
118 NotifyDiskChanged(event, disk2.get());
119 }
120
121 void MockDiskMountManager::NotifyDeviceRemoveEvents() {
122 scoped_ptr<DiskMountManager::Disk> disk(new DiskMountManager::Disk(
123 std::string(kTestDevicePath),
124 std::string(kTestMountPath),
125 std::string(kTestSystemPath),
126 std::string(kTestFilePath),
127 std::string(kTestDeviceLabel),
128 std::string(kTestDriveLabel),
129 std::string(kTestUuid),
130 std::string(kTestSystemPathPrefix),
131 DEVICE_TYPE_SD,
132 1073741824,
133 false, // is_parent
134 false, // is_read_only
135 true, // has_media
136 false, // on_boot_device
137 false)); // is_hidden
138 disks_.clear();
139 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
140 std::string(kTestDevicePath), disk.get()));
141 NotifyDiskChanged(MOUNT_DISK_REMOVED, disk.get());
142 }
143
144 void MockDiskMountManager::SetupDefaultReplies() {
145 EXPECT_CALL(*this, AddObserver(_))
146 .Times(AnyNumber());
147 EXPECT_CALL(*this, RemoveObserver(_))
148 .Times(AnyNumber());
149 EXPECT_CALL(*this, disks())
150 .WillRepeatedly(ReturnRef(disks_));
151 EXPECT_CALL(*this, mount_points())
152 .WillRepeatedly(ReturnRef(mount_points_));
153 EXPECT_CALL(*this, FindDiskBySourcePath(_))
154 .Times(AnyNumber());
155 EXPECT_CALL(*this, RequestMountInfoRefresh())
156 .Times(AnyNumber());
157 EXPECT_CALL(*this, MountPath(_, _, _, _))
158 .Times(AnyNumber());
159 EXPECT_CALL(*this, UnmountPath(_))
160 .Times(AnyNumber());
161 EXPECT_CALL(*this, FormatUnmountedDevice(_))
162 .Times(AnyNumber());
163 EXPECT_CALL(*this, FormatMountedDevice(_))
164 .Times(AnyNumber());
165 EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _))
166 .Times(AnyNumber());
167 }
168
169 void MockDiskMountManager::CreateDiskEntryForMountDevice(
170 const DiskMountManager::MountPointInfo& mount_info,
171 const std::string& device_id) {
172 Disk* disk = new DiskMountManager::Disk(std::string(mount_info.source_path),
173 std::string(mount_info.mount_path),
174 std::string(), // system_path
175 std::string(), // file_path
176 std::string(), // device_label
177 std::string(), // drive_label
178 device_id, // fs_uuid
179 std::string(), // system_path_prefix
180 DEVICE_TYPE_USB, // device_type
181 1073741824, // total_size_in_bytes
182 false, // is_parent
183 false, // is_read_only
184 true, // has_media
185 false, // on_boot_device
186 false); // is_hidden
187 DiskMountManager::DiskMap::iterator it = disks_.find(mount_info.source_path);
188 if (it == disks_.end()) {
189 disks_.insert(std::make_pair(std::string(mount_info.source_path), disk));
190 } else {
191 delete it->second;
192 it->second = disk;
193 }
194 }
195
196 void MockDiskMountManager::RemoveDiskEntryForMountDevice(
197 const DiskMountManager::MountPointInfo& mount_info) {
198 DiskMountManager::DiskMap::iterator it = disks_.find(mount_info.source_path);
199 if (it != disks_.end()) {
200 delete it->second;
201 disks_.erase(it);
202 }
203 }
204
205 const DiskMountManager::MountPointMap&
206 MockDiskMountManager::mountPointsInternal() const {
207 return mount_points_;
208 }
209
210 const DiskMountManager::Disk*
211 MockDiskMountManager::FindDiskBySourcePathInternal(
212 const std::string& source_path) const {
213 DiskMap::const_iterator disk_it = disks_.find(source_path);
214 return disk_it == disks_.end() ? NULL : disk_it->second;
215 }
216
217 void MockDiskMountManager::NotifyDiskChanged(
218 DiskMountManagerEventType event,
219 const DiskMountManager::Disk* disk) {
220 // Make sure we run on UI thread.
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
222
223 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(event, disk));
224 }
225
226 void MockDiskMountManager::NotifyDeviceChanged(DiskMountManagerEventType event,
227 const std::string& path) {
228 // Make sure we run on UI thread.
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
230
231 FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(event, path));
232 }
233
234 } // namespace disks
235 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698