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 // chromeos::RemovableDeviceNotificationsCros unit tests. | 5 // chromeos::RemovableDeviceNotificationsCros unit tests. |
6 | 6 |
7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos. h" | 7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos. h" |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace chromeos { | 23 namespace chromeos { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 using content::BrowserThread; | 27 using content::BrowserThread; |
28 using disks::DiskMountManager; | 28 using disks::DiskMountManager; |
29 using testing::_; | 29 using testing::_; |
30 | 30 |
31 const char kDeviceNameWithManufacturerDetails[] = "110 KB (CompanyA, Z101)"; | |
31 const char kDevice1[] = "/dev/d1"; | 32 const char kDevice1[] = "/dev/d1"; |
33 const char kDevice1Name[] = "d1"; | |
34 const char kDevice1NameWithSizeInfo[] = "110 KB d1"; | |
35 const char kDevice1Size[] = "110 KB"; | |
32 const char kDevice2[] = "/dev/disk/d2"; | 36 const char kDevice2[] = "/dev/disk/d2"; |
33 const char kDevice1Name[] = "d1"; | |
34 const char kDevice2Name[] = "d2"; | 37 const char kDevice2Name[] = "d2"; |
38 const char kDevice2NameWithSizeInfo[] = "19.8 GB d2"; | |
39 const char kEmptyDeviceLabel[] = ""; | |
35 const char kMountPointA[] = "mnt_a"; | 40 const char kMountPointA[] = "mnt_a"; |
36 const char kMountPointB[] = "mnt_b"; | 41 const char kMountPointB[] = "mnt_b"; |
42 const char kSDCardDeviceName1[] = "8.6 MB Amy_SD"; | |
43 const char kSDCardDeviceName2[] = "8.6 MB SD Card"; | |
44 const char kSDCardMountPoint1[] = "/media/removable/Amy_SD"; | |
45 const char kSDCardMountPoint2[] = "/media/removable/SD Card"; | |
46 const char kProductName[] = "Z101"; | |
47 const char kVendorName[] = "CompanyA"; | |
48 | |
49 uint64 kDevice1SizeInBytes = 113048; | |
50 uint64 kDevice2SizeInBytes = 21231209600; | |
51 uint64 kSDCardSizeInBytes = 9000000; | |
37 | 52 |
38 std::string GetDCIMDeviceId(const std::string& unique_id) { | 53 std::string GetDCIMDeviceId(const std::string& unique_id) { |
39 return chrome::MediaStorageUtil::MakeDeviceId( | 54 return chrome::MediaStorageUtil::MakeDeviceId( |
40 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, | 55 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, |
41 chrome::kFSUniqueIdPrefix + unique_id); | 56 chrome::kFSUniqueIdPrefix + unique_id); |
42 } | 57 } |
43 | 58 |
59 // Wrapper class to test RemovableDeviceNotificationsCros. | |
44 class RemovableDeviceNotificationsCrosTest : public testing::Test { | 60 class RemovableDeviceNotificationsCrosTest : public testing::Test { |
45 public: | 61 public: |
46 RemovableDeviceNotificationsCrosTest() | 62 RemovableDeviceNotificationsCrosTest() |
47 : ui_thread_(BrowserThread::UI, &ui_loop_), | 63 : ui_thread_(BrowserThread::UI, &ui_loop_), |
48 file_thread_(BrowserThread::FILE) { | 64 file_thread_(BrowserThread::FILE) { |
49 } | 65 } |
50 virtual ~RemovableDeviceNotificationsCrosTest() {} | 66 virtual ~RemovableDeviceNotificationsCrosTest() {} |
51 | 67 |
52 protected: | 68 protected: |
53 virtual void SetUp() { | 69 virtual void SetUp() OVERRIDE { |
54 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 70 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
55 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 71 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
56 file_thread_.Start(); | 72 file_thread_.Start(); |
57 | 73 |
58 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | 74 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); |
59 system_monitor_.AddDevicesChangedObserver( | 75 system_monitor_.AddDevicesChangedObserver( |
60 mock_devices_changed_observer_.get()); | 76 mock_devices_changed_observer_.get()); |
61 | 77 |
62 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); | 78 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); |
63 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | 79 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); |
64 disk_mount_manager_mock_->SetupDefaultReplies(); | 80 disk_mount_manager_mock_->SetupDefaultReplies(); |
65 | 81 |
66 // Initialize the test subject. | 82 // Initialize the test subject. |
67 notifications_ = new RemovableDeviceNotificationsCros(); | 83 notifications_ = new RemovableDeviceNotificationsCros(); |
68 } | 84 } |
69 | 85 |
70 virtual void TearDown() { | 86 virtual void TearDown() OVERRIDE { |
71 notifications_ = NULL; | 87 notifications_ = NULL; |
72 disk_mount_manager_mock_ = NULL; | 88 disk_mount_manager_mock_ = NULL; |
73 DiskMountManager::Shutdown(); | 89 DiskMountManager::Shutdown(); |
74 system_monitor_.RemoveDevicesChangedObserver( | 90 system_monitor_.RemoveDevicesChangedObserver( |
75 mock_devices_changed_observer_.get()); | 91 mock_devices_changed_observer_.get()); |
76 WaitForFileThread(); | 92 WaitForFileThread(); |
77 } | 93 } |
78 | 94 |
79 base::MockDevicesChangedObserver& observer() { | 95 base::MockDevicesChangedObserver& observer() { |
80 return *mock_devices_changed_observer_; | 96 return *mock_devices_changed_observer_; |
81 } | 97 } |
82 | 98 |
83 void MountDevice(MountError error_code, | 99 void MountDevice(MountError error_code, |
84 const DiskMountManager::MountPointInfo& mount_info, | 100 const DiskMountManager::MountPointInfo& mount_info, |
85 const std::string& unique_id, | 101 const std::string& unique_id, |
86 const std::string& device_label) { | 102 const std::string& device_label, |
103 const std::string& vendor_name, | |
104 const std::string& product_name, | |
105 DeviceType device_type, | |
106 uint64 device_size_in_bytes) { | |
87 if (error_code == MOUNT_ERROR_NONE) { | 107 if (error_code == MOUNT_ERROR_NONE) { |
88 disk_mount_manager_mock_->CreateDiskEntryForMountDevice( | 108 disk_mount_manager_mock_->CreateDiskEntryForMountDevice( |
89 mount_info, unique_id, device_label); | 109 mount_info, unique_id, device_label, vendor_name, product_name, |
110 device_type, device_size_in_bytes); | |
90 } | 111 } |
91 notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, | 112 notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, |
92 error_code, | 113 error_code, |
93 mount_info); | 114 mount_info); |
94 WaitForFileThread(); | 115 WaitForFileThread(); |
95 } | 116 } |
96 | 117 |
97 void UnmountDevice(MountError error_code, | 118 void UnmountDevice(MountError error_code, |
98 const DiskMountManager::MountPointInfo& mount_info) { | 119 const DiskMountManager::MountPointInfo& mount_info) { |
99 notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, | 120 notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, |
100 error_code, | 121 error_code, |
101 mount_info); | 122 mount_info); |
102 if (error_code == MOUNT_ERROR_NONE) { | 123 if (error_code == MOUNT_ERROR_NONE) { |
103 disk_mount_manager_mock_->RemoveDiskEntryForMountDevice( | 124 disk_mount_manager_mock_->RemoveDiskEntryForMountDevice( |
104 mount_info); | 125 mount_info); |
105 } | 126 } |
106 WaitForFileThread(); | 127 WaitForFileThread(); |
107 } | 128 } |
108 | 129 |
130 string16 GetDeviceStorageSize(const std::string& device_location) { | |
131 return notifications_->GetStorageSize(device_location); | |
132 } | |
133 | |
109 // Create a directory named |dir| relative to the test directory. | 134 // Create a directory named |dir| relative to the test directory. |
110 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 135 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
111 // subdirectory. | 136 // subdirectory. |
112 // Returns the full path to the created directory on success, or an empty | 137 // Returns the full path to the created directory on success, or an empty |
113 // path on failure. | 138 // path on failure. |
114 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { | 139 FilePath CreateMountPoint(const std::string& dir, |
Lei Zhang
2012/11/12 07:46:56
unneeded change?
kmadhusu
2012/11/12 19:56:56
Reverted.
| |
140 bool with_dcim_dir) { | |
115 FilePath return_path(scoped_temp_dir_.path()); | 141 FilePath return_path(scoped_temp_dir_.path()); |
116 return_path = return_path.AppendASCII(dir); | 142 return_path = return_path.AppendASCII(dir); |
117 FilePath path(return_path); | 143 FilePath path(return_path); |
118 if (with_dcim_dir) | 144 if (with_dcim_dir) |
119 path = path.AppendASCII("DCIM"); | 145 path = path.AppendASCII("DCIM"); |
120 if (!file_util::CreateDirectory(path)) | 146 if (!file_util::CreateDirectory(path)) |
121 return FilePath(); | 147 return FilePath(); |
122 return return_path; | 148 return return_path; |
123 } | 149 } |
124 | 150 |
125 static void PostQuitToUIThread() { | 151 static void PostQuitToUIThread() { |
126 BrowserThread::PostTask(BrowserThread::UI, | 152 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
127 FROM_HERE, | |
128 MessageLoop::QuitClosure()); | 153 MessageLoop::QuitClosure()); |
129 } | 154 } |
130 | 155 |
131 static void WaitForFileThread() { | 156 static void WaitForFileThread() { |
132 BrowserThread::PostTask(BrowserThread::FILE, | 157 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
133 FROM_HERE, | |
134 base::Bind(&PostQuitToUIThread)); | 158 base::Bind(&PostQuitToUIThread)); |
135 MessageLoop::current()->Run(); | 159 MessageLoop::current()->Run(); |
136 } | 160 } |
137 | 161 |
138 private: | 162 private: |
139 // The message loops and threads to run tests on. | 163 // The message loops and threads to run tests on. |
140 MessageLoop ui_loop_; | 164 MessageLoop ui_loop_; |
141 content::TestBrowserThread ui_thread_; | 165 content::TestBrowserThread ui_thread_; |
142 content::TestBrowserThread file_thread_; | 166 content::TestBrowserThread file_thread_; |
143 | 167 |
(...skipping 16 matching lines...) Expand all Loading... | |
160 testing::Sequence mock_sequence; | 184 testing::Sequence mock_sequence; |
161 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 185 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
162 ASSERT_FALSE(mount_path1.empty()); | 186 ASSERT_FALSE(mount_path1.empty()); |
163 DiskMountManager::MountPointInfo mount_info(kDevice1, | 187 DiskMountManager::MountPointInfo mount_info(kDevice1, |
164 mount_path1.value(), | 188 mount_path1.value(), |
165 MOUNT_TYPE_DEVICE, | 189 MOUNT_TYPE_DEVICE, |
166 disks::MOUNT_CONDITION_NONE); | 190 disks::MOUNT_CONDITION_NONE); |
167 const std::string kUniqueId0 = "FFFF-FFFF"; | 191 const std::string kUniqueId0 = "FFFF-FFFF"; |
168 EXPECT_CALL(observer(), | 192 EXPECT_CALL(observer(), |
169 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId0), | 193 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId0), |
170 ASCIIToUTF16(kDevice1Name), | 194 ASCIIToUTF16(kDevice1NameWithSizeInfo), |
171 mount_path1.value())) | 195 mount_path1.value())) |
172 .InSequence(mock_sequence); | 196 .InSequence(mock_sequence); |
173 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kDevice1Name); | 197 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kDevice1Name, |
198 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
174 | 199 |
175 EXPECT_CALL(observer(), | 200 EXPECT_CALL(observer(), |
176 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | 201 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) |
177 .InSequence(mock_sequence); | 202 .InSequence(mock_sequence); |
178 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 203 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
179 | 204 |
180 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); | 205 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); |
181 ASSERT_FALSE(mount_path2.empty()); | 206 ASSERT_FALSE(mount_path2.empty()); |
182 DiskMountManager::MountPointInfo mount_info2(kDevice2, | 207 DiskMountManager::MountPointInfo mount_info2(kDevice2, |
183 mount_path2.value(), | 208 mount_path2.value(), |
184 MOUNT_TYPE_DEVICE, | 209 MOUNT_TYPE_DEVICE, |
185 disks::MOUNT_CONDITION_NONE); | 210 disks::MOUNT_CONDITION_NONE); |
186 const std::string kUniqueId1 = "FFF0-FFF0"; | 211 const std::string kUniqueId1 = "FFF0-FFF0"; |
187 | 212 |
188 EXPECT_CALL(observer(), | 213 EXPECT_CALL(observer(), |
189 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), | 214 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), |
190 ASCIIToUTF16(kDevice2Name), | 215 ASCIIToUTF16(kDevice2NameWithSizeInfo), |
191 mount_path2.value())) | 216 mount_path2.value())) |
192 .InSequence(mock_sequence); | 217 .InSequence(mock_sequence); |
193 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId1, kDevice2Name); | 218 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId1, kDevice2Name, |
219 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice2SizeInBytes); | |
194 | 220 |
195 EXPECT_CALL(observer(), | 221 EXPECT_CALL(observer(), |
196 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | 222 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) |
197 .InSequence(mock_sequence); | 223 .InSequence(mock_sequence); |
198 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | 224 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
199 } | 225 } |
200 | 226 |
201 // Removable mass storage devices with no dcim folder are also recognized. | 227 // Removable mass storage devices with no dcim folder are also recognized. |
202 TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { | 228 TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { |
203 testing::Sequence mock_sequence; | 229 testing::Sequence mock_sequence; |
204 FilePath mount_path = CreateMountPoint(kMountPointA, false); | 230 FilePath mount_path = CreateMountPoint(kMountPointA, false); |
205 const std::string kUniqueId = "FFFF-FFFF"; | 231 const std::string kUniqueId = "FFFF-FFFF"; |
206 ASSERT_FALSE(mount_path.empty()); | 232 ASSERT_FALSE(mount_path.empty()); |
207 DiskMountManager::MountPointInfo mount_info(kDevice1, | 233 DiskMountManager::MountPointInfo mount_info(kDevice1, |
208 mount_path.value(), | 234 mount_path.value(), |
209 MOUNT_TYPE_DEVICE, | 235 MOUNT_TYPE_DEVICE, |
210 disks::MOUNT_CONDITION_NONE); | 236 disks::MOUNT_CONDITION_NONE); |
211 const std::string device_id = chrome::MediaStorageUtil::MakeDeviceId( | 237 const std::string device_id = chrome::MediaStorageUtil::MakeDeviceId( |
212 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, | 238 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, |
213 chrome::kFSUniqueIdPrefix + kUniqueId); | 239 chrome::kFSUniqueIdPrefix + kUniqueId); |
214 EXPECT_CALL(observer(), | 240 EXPECT_CALL(observer(), |
215 OnRemovableStorageAttached(device_id, ASCIIToUTF16(kDevice1Name), | 241 OnRemovableStorageAttached(device_id, |
242 ASCIIToUTF16(kDevice1NameWithSizeInfo), | |
216 mount_path.value())).Times(1); | 243 mount_path.value())).Times(1); |
217 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); | 244 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
245 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
218 } | 246 } |
219 | 247 |
220 // Non device mounts and mount errors are ignored. | 248 // Non device mounts and mount errors are ignored. |
221 TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { | 249 TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { |
222 testing::Sequence mock_sequence; | 250 testing::Sequence mock_sequence; |
223 FilePath mount_path = CreateMountPoint(kMountPointA, true); | 251 FilePath mount_path = CreateMountPoint(kMountPointA, true); |
224 const std::string kUniqueId = "FFFF-FFFF"; | 252 const std::string kUniqueId = "FFFF-FFFF"; |
225 ASSERT_FALSE(mount_path.empty()); | 253 ASSERT_FALSE(mount_path.empty()); |
226 | 254 |
227 // Mount error. | 255 // Mount error. |
228 DiskMountManager::MountPointInfo mount_info(kDevice1, | 256 DiskMountManager::MountPointInfo mount_info(kDevice1, |
229 mount_path.value(), | 257 mount_path.value(), |
230 MOUNT_TYPE_DEVICE, | 258 MOUNT_TYPE_DEVICE, |
231 disks::MOUNT_CONDITION_NONE); | 259 disks::MOUNT_CONDITION_NONE); |
232 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 260 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
233 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name); | 261 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name, |
262 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
234 | 263 |
235 // Not a device | 264 // Not a device |
236 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; | 265 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; |
237 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 266 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
238 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); | 267 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
268 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
239 | 269 |
240 // Unsupported file system. | 270 // Unsupported file system. |
241 mount_info.mount_type = MOUNT_TYPE_DEVICE; | 271 mount_info.mount_type = MOUNT_TYPE_DEVICE; |
242 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; | 272 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
243 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 273 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
244 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); | 274 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
275 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
276 } | |
277 | |
278 TEST_F(RemovableDeviceNotificationsCrosTest, SDCardAttachDetach) { | |
279 testing::Sequence mock_sequence; | |
280 FilePath mount_path1 = CreateMountPoint(kSDCardMountPoint1, true); | |
281 ASSERT_FALSE(mount_path1.empty()); | |
282 DiskMountManager::MountPointInfo mount_info1(kSDCardDeviceName1, | |
283 mount_path1.value(), | |
284 MOUNT_TYPE_DEVICE, | |
285 disks::MOUNT_CONDITION_NONE); | |
286 const std::string kUniqueId1 = "FFFF-FFFF"; | |
287 EXPECT_CALL(observer(), | |
288 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), | |
289 ASCIIToUTF16(kSDCardDeviceName1), | |
290 mount_path1.value())) | |
291 .InSequence(mock_sequence); | |
292 MountDevice(MOUNT_ERROR_NONE, mount_info1, kUniqueId1, kSDCardDeviceName1, | |
293 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); | |
294 | |
295 EXPECT_CALL(observer(), | |
296 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | |
297 .InSequence(mock_sequence); | |
298 UnmountDevice(MOUNT_ERROR_NONE, mount_info1); | |
299 | |
300 FilePath mount_path2 = CreateMountPoint(kSDCardMountPoint2, true); | |
301 ASSERT_FALSE(mount_path2.empty()); | |
302 DiskMountManager::MountPointInfo mount_info2(kSDCardDeviceName2, | |
303 mount_path2.value(), | |
304 MOUNT_TYPE_DEVICE, | |
305 disks::MOUNT_CONDITION_NONE); | |
306 const std::string kUniqueId2 = "F0FF-FFF0"; | |
307 EXPECT_CALL(observer(), | |
308 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId2), | |
309 ASCIIToUTF16(kSDCardDeviceName2), | |
310 mount_path2.value())) | |
311 .InSequence(mock_sequence); | |
312 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kSDCardDeviceName2, | |
313 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); | |
314 | |
315 EXPECT_CALL(observer(), | |
316 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) | |
317 .InSequence(mock_sequence); | |
318 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | |
319 } | |
320 | |
321 TEST_F(RemovableDeviceNotificationsCrosTest, AttachDeviceWithEmptyLabel) { | |
322 testing::Sequence mock_sequence; | |
323 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | |
324 ASSERT_FALSE(mount_path1.empty()); | |
325 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, | |
326 mount_path1.value(), | |
327 MOUNT_TYPE_DEVICE, | |
328 disks::MOUNT_CONDITION_NONE); | |
329 const std::string kUniqueId0 = "FFFF-FFFF"; | |
330 EXPECT_CALL(observer(), OnRemovableStorageAttached( | |
331 GetDCIMDeviceId(kUniqueId0), | |
332 ASCIIToUTF16(kDeviceNameWithManufacturerDetails), | |
333 mount_path1.value())) | |
334 .InSequence(mock_sequence); | |
335 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kEmptyDeviceLabel, | |
336 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
337 | |
338 EXPECT_CALL(observer(), | |
339 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | |
340 .InSequence(mock_sequence); | |
341 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | |
342 } | |
343 | |
344 TEST_F(RemovableDeviceNotificationsCrosTest, GetStorageSize) { | |
345 testing::Sequence mock_sequence; | |
346 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | |
347 ASSERT_FALSE(mount_path1.empty()); | |
348 ASSERT_TRUE(GetDeviceStorageSize(mount_path1.value()).empty()); | |
349 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, | |
350 mount_path1.value(), | |
351 MOUNT_TYPE_DEVICE, | |
352 disks::MOUNT_CONDITION_NONE); | |
353 const std::string kUniqueId0 = "FFFF-FFFF"; | |
354 EXPECT_CALL(observer(), OnRemovableStorageAttached( | |
355 GetDCIMDeviceId(kUniqueId0), | |
356 ASCIIToUTF16(kDeviceNameWithManufacturerDetails), | |
357 mount_path1.value())) | |
358 .InSequence(mock_sequence); | |
359 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kEmptyDeviceLabel, | |
360 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
361 | |
362 EXPECT_EQ(ASCIIToUTF16(kDevice1Size), | |
363 GetDeviceStorageSize(mount_path1.value())); | |
364 EXPECT_CALL(observer(), | |
365 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | |
366 .InSequence(mock_sequence); | |
367 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | |
245 } | 368 } |
246 | 369 |
247 } // namespace | 370 } // namespace |
248 | 371 |
249 } // namespace chrome | 372 } // namespace chrome |
OLD | NEW |