OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" | 5 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/stl_util.h" | |
8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 | 11 |
11 using content::BrowserThread; | 12 using content::BrowserThread; |
12 using testing::_; | 13 using testing::_; |
13 using testing::AnyNumber; | 14 using testing::AnyNumber; |
14 using testing::Invoke; | 15 using testing::Invoke; |
15 using testing::ReturnRef; | 16 using testing::ReturnRef; |
16 | 17 |
17 namespace chromeos { | 18 namespace chromeos { |
18 namespace disks { | 19 namespace disks { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const char* kTestSystemPath = "/this/system/path"; | 23 const char* kTestSystemPath = "/this/system/path"; |
23 const char* kTestSystemPathPrefix = "/this/system"; | 24 const char* kTestSystemPathPrefix = "/this/system"; |
24 const char* kTestDevicePath = "/this/device/path"; | 25 const char* kTestDevicePath = "/this/device/path"; |
25 const char* kTestMountPath = "/media/foofoo"; | 26 const char* kTestMountPath = "/media/foofoo"; |
26 const char* kTestFilePath = "/this/file/path"; | 27 const char* kTestFilePath = "/this/file/path"; |
27 const char* kTestDeviceLabel = "A label"; | 28 const char* kTestDeviceLabel = "A label"; |
28 const char* kTestDriveLabel = "Another label"; | 29 const char* kTestDriveLabel = "Another label"; |
30 const char* kTestUuid = "FFFF-FFFF"; | |
29 | 31 |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 void MockDiskMountManager::AddObserverInternal( | 34 void MockDiskMountManager::AddObserverInternal( |
33 DiskMountManager::Observer* observer) { | 35 DiskMountManager::Observer* observer) { |
34 observers_.AddObserver(observer); | 36 observers_.AddObserver(observer); |
35 } | 37 } |
36 | 38 |
37 void MockDiskMountManager::RemoveObserverInternal( | 39 void MockDiskMountManager::RemoveObserverInternal( |
38 DiskMountManager::Observer* observer) { | 40 DiskMountManager::Observer* observer) { |
39 observers_.RemoveObserver(observer); | 41 observers_.RemoveObserver(observer); |
40 } | 42 } |
41 | 43 |
42 MockDiskMountManager::MockDiskMountManager() { | 44 MockDiskMountManager::MockDiskMountManager() { |
43 ON_CALL(*this, AddObserver(_)) | 45 ON_CALL(*this, AddObserver(_)) |
44 .WillByDefault(Invoke(this, &MockDiskMountManager::AddObserverInternal)); | 46 .WillByDefault(Invoke(this, &MockDiskMountManager::AddObserverInternal)); |
45 ON_CALL(*this, RemoveObserver(_)) | 47 ON_CALL(*this, RemoveObserver(_)) |
46 .WillByDefault(Invoke(this, | 48 .WillByDefault(Invoke(this, |
47 &MockDiskMountManager::RemoveObserverInternal)); | 49 &MockDiskMountManager::RemoveObserverInternal)); |
48 ON_CALL(*this, disks()) | 50 ON_CALL(*this, disks()) |
49 .WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal)); | 51 .WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal)); |
50 } | 52 } |
51 | 53 |
52 MockDiskMountManager::~MockDiskMountManager() { | 54 MockDiskMountManager::~MockDiskMountManager() { |
55 STLDeleteContainerPairSecondPointers(disks_.begin(), disks_.end()); | |
56 disks_.clear(); | |
53 } | 57 } |
54 | 58 |
55 void MockDiskMountManager::NotifyDeviceInsertEvents() { | 59 void MockDiskMountManager::NotifyDeviceInsertEvents() { |
56 scoped_ptr<DiskMountManager::Disk> disk1(new DiskMountManager::Disk( | 60 scoped_ptr<DiskMountManager::Disk> disk1(new DiskMountManager::Disk( |
57 std::string(kTestDevicePath), | 61 std::string(kTestDevicePath), |
58 std::string(), | 62 std::string(), |
59 std::string(kTestSystemPath), | 63 std::string(kTestSystemPath), |
60 std::string(kTestFilePath), | 64 std::string(kTestFilePath), |
61 std::string(), | 65 std::string(), |
62 std::string(kTestDriveLabel), | 66 std::string(kTestDriveLabel), |
67 std::string(kTestUuid), | |
63 std::string(kTestSystemPathPrefix), | 68 std::string(kTestSystemPathPrefix), |
64 DEVICE_TYPE_USB, | 69 DEVICE_TYPE_USB, |
65 4294967295U, | 70 4294967295U, |
66 false, // is_parent | 71 false, // is_parent |
67 false, // is_read_only | 72 false, // is_read_only |
68 true, // has_media | 73 true, // has_media |
69 false, // on_boot_device | 74 false, // on_boot_device |
70 false)); // is_hidden | 75 false)); // is_hidden |
71 | 76 |
72 disks_.clear(); | 77 disks_.clear(); |
(...skipping 10 matching lines...) Expand all Loading... | |
83 NotifyDiskChanged(event, disk1.get()); | 88 NotifyDiskChanged(event, disk1.get()); |
84 | 89 |
85 // Disk Changed | 90 // Disk Changed |
86 scoped_ptr<DiskMountManager::Disk> disk2(new DiskMountManager::Disk( | 91 scoped_ptr<DiskMountManager::Disk> disk2(new DiskMountManager::Disk( |
87 std::string(kTestDevicePath), | 92 std::string(kTestDevicePath), |
88 std::string(kTestMountPath), | 93 std::string(kTestMountPath), |
89 std::string(kTestSystemPath), | 94 std::string(kTestSystemPath), |
90 std::string(kTestFilePath), | 95 std::string(kTestFilePath), |
91 std::string(kTestDeviceLabel), | 96 std::string(kTestDeviceLabel), |
92 std::string(kTestDriveLabel), | 97 std::string(kTestDriveLabel), |
98 std::string(kTestUuid), | |
Lei Zhang
2012/07/30 22:11:32
either this is correct and the change on line 121
kmadhusu
2012/07/30 22:51:14
oops. Good catch. Line 98 is correct. Fixed line 1
| |
93 std::string(kTestSystemPathPrefix), | 99 std::string(kTestSystemPathPrefix), |
94 DEVICE_TYPE_MOBILE, | 100 DEVICE_TYPE_MOBILE, |
95 1073741824, | 101 1073741824, |
96 false, // is_parent | 102 false, // is_parent |
97 false, // is_read_only | 103 false, // is_read_only |
98 true, // has_media | 104 true, // has_media |
99 false, // on_boot_device | 105 false, // on_boot_device |
100 false)); // is_hidden | 106 false)); // is_hidden |
101 disks_.clear(); | 107 disks_.clear(); |
102 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( | 108 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( |
103 std::string(kTestDevicePath), disk2.get())); | 109 std::string(kTestDevicePath), disk2.get())); |
104 event = MOUNT_DISK_CHANGED; | 110 event = MOUNT_DISK_CHANGED; |
105 NotifyDiskChanged(event, disk2.get()); | 111 NotifyDiskChanged(event, disk2.get()); |
106 } | 112 } |
107 | 113 |
108 void MockDiskMountManager::NotifyDeviceRemoveEvents() { | 114 void MockDiskMountManager::NotifyDeviceRemoveEvents() { |
109 scoped_ptr<DiskMountManager::Disk> disk(new DiskMountManager::Disk( | 115 scoped_ptr<DiskMountManager::Disk> disk(new DiskMountManager::Disk( |
110 std::string(kTestDevicePath), | 116 std::string(kTestDevicePath), |
111 std::string(kTestMountPath), | 117 std::string(kTestMountPath), |
112 std::string(kTestSystemPath), | 118 std::string(kTestSystemPath), |
113 std::string(kTestFilePath), | 119 std::string(kTestFilePath), |
114 std::string(kTestDeviceLabel), | 120 std::string(kTestDeviceLabel), |
121 std::string(kTestUuid), | |
115 std::string(kTestDriveLabel), | 122 std::string(kTestDriveLabel), |
116 std::string(kTestSystemPathPrefix), | 123 std::string(kTestSystemPathPrefix), |
117 DEVICE_TYPE_SD, | 124 DEVICE_TYPE_SD, |
118 1073741824, | 125 1073741824, |
119 false, // is_parent | 126 false, // is_parent |
120 false, // is_read_only | 127 false, // is_read_only |
121 true, // has_media | 128 true, // has_media |
122 false, // on_boot_device | 129 false, // on_boot_device |
123 false)); // is_hidden | 130 false)); // is_hidden |
124 disks_.clear(); | 131 disks_.clear(); |
(...skipping 16 matching lines...) Expand all Loading... | |
141 EXPECT_CALL(*this, UnmountPath(_)) | 148 EXPECT_CALL(*this, UnmountPath(_)) |
142 .Times(AnyNumber()); | 149 .Times(AnyNumber()); |
143 EXPECT_CALL(*this, FormatUnmountedDevice(_)) | 150 EXPECT_CALL(*this, FormatUnmountedDevice(_)) |
144 .Times(AnyNumber()); | 151 .Times(AnyNumber()); |
145 EXPECT_CALL(*this, FormatMountedDevice(_)) | 152 EXPECT_CALL(*this, FormatMountedDevice(_)) |
146 .Times(AnyNumber()); | 153 .Times(AnyNumber()); |
147 EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _)) | 154 EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _)) |
148 .Times(AnyNumber()); | 155 .Times(AnyNumber()); |
149 } | 156 } |
150 | 157 |
158 void MockDiskMountManager::CreateDiskEntryForMountDevice( | |
159 const DiskMountManager::MountPointInfo& mount_info, | |
160 const std::string& device_id) { | |
161 Disk* disk = new DiskMountManager::Disk(std::string(mount_info.source_path), | |
Ben Chan
2012/07/30 22:03:59
nit: remove the extra space after =
kmadhusu
2012/07/30 22:51:14
Done.
| |
162 std::string(mount_info.mount_path), | |
163 std::string(), | |
Ben Chan
2012/07/30 22:03:59
nit: comment what these empty strings are
kmadhusu
2012/07/30 22:51:14
Done.
| |
164 std::string(), | |
165 std::string(), | |
166 std::string(), | |
167 std::string(device_id), | |
Ben Chan
2012/07/30 22:03:59
std::string(device_id) -> device_id
kmadhusu
2012/07/30 22:51:14
Done.
| |
168 std::string(), | |
169 DEVICE_TYPE_USB, | |
170 1073741824, | |
171 false, // is_parent | |
172 false, // is_read_only | |
173 true, // has_media | |
174 false, // on_boot_device | |
175 false); // is_hidden | |
176 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( | |
177 std::string(mount_info.source_path), disk)); | |
178 } | |
179 | |
180 void MockDiskMountManager::RemoveDiskEntryForMountDevice( | |
181 const DiskMountManager::MountPointInfo& mount_info) { | |
182 DiskMountManager::DiskMap::iterator it = disks_.find(mount_info.source_path); | |
183 if (it != disks_.end()) { | |
184 delete it->second; | |
185 disks_.erase(it); | |
186 } | |
187 } | |
188 | |
151 void MockDiskMountManager::NotifyDiskChanged(DiskMountManagerEventType event, | 189 void MockDiskMountManager::NotifyDiskChanged(DiskMountManagerEventType event, |
152 const DiskMountManager::Disk* disk) | 190 const DiskMountManager::Disk* disk) |
153 { | 191 { |
154 // Make sure we run on UI thread. | 192 // Make sure we run on UI thread. |
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
156 | 194 |
157 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(event, disk)); | 195 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(event, disk)); |
158 } | 196 } |
159 | 197 |
160 void MockDiskMountManager::NotifyDeviceChanged(DiskMountManagerEventType event, | 198 void MockDiskMountManager::NotifyDeviceChanged(DiskMountManagerEventType event, |
161 const std::string& path) { | 199 const std::string& path) { |
162 // Make sure we run on UI thread. | 200 // Make sure we run on UI thread. |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
164 | 202 |
165 FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(event, path)); | 203 FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(event, path)); |
166 } | 204 } |
167 | 205 |
168 } // namespace disks | 206 } // namespace disks |
169 } // namespace chromeos | 207 } // namespace chromeos |
OLD | NEW |