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::MediaDeviceNotifications unit tests. | 5 // chromeos::MediaDeviceNotifications unit tests. |
6 | 6 |
7 #include "chrome/browser/media_gallery/media_device_notifications_chromeos.h" | 7 #include "chrome/browser/media_gallery/media_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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
14 #include "base/system_monitor/system_monitor.h" | 14 #include "base/system_monitor/system_monitor.h" |
15 #include "base/test/mock_devices_changed_observer.h" | 15 #include "base/test/mock_devices_changed_observer.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" | 17 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" |
| 18 #include "chrome/browser/media_gallery/media_storage_util.h" |
18 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace chromeos { | 22 namespace chromeos { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 using content::BrowserThread; | 26 using content::BrowserThread; |
26 using disks::DiskMountManager; | 27 using disks::DiskMountManager; |
27 using testing::_; | 28 using testing::_; |
28 | 29 |
29 const char kDevice1[] = "/dev/d1"; | 30 const char kDevice1[] = "/dev/d1"; |
30 const char kDevice2[] = "/dev/disk/d2"; | 31 const char kDevice2[] = "/dev/disk/d2"; |
31 const char kDevice1Name[] = "d1"; | 32 const char kDevice1Name[] = "d1"; |
32 const char kDevice2Name[] = "d2"; | 33 const char kDevice2Name[] = "d2"; |
33 const char kMountPointA[] = "mnt_a"; | 34 const char kMountPointA[] = "mnt_a"; |
34 const char kMountPointB[] = "mnt_b"; | 35 const char kMountPointB[] = "mnt_b"; |
35 | 36 |
| 37 std::string GetDCIMDeviceId(const std::string& unique_id) { |
| 38 return chrome::MediaStorageUtil::MakeDeviceId( |
| 39 chrome::MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM, unique_id); |
| 40 } |
| 41 |
36 class MediaDeviceNotificationsTest : public testing::Test { | 42 class MediaDeviceNotificationsTest : public testing::Test { |
37 public: | 43 public: |
38 MediaDeviceNotificationsTest() | 44 MediaDeviceNotificationsTest() |
39 : ui_thread_(BrowserThread::UI, &ui_loop_), | 45 : ui_thread_(BrowserThread::UI, &ui_loop_), |
40 file_thread_(BrowserThread::FILE) { | 46 file_thread_(BrowserThread::FILE) { |
41 } | 47 } |
42 virtual ~MediaDeviceNotificationsTest() {} | 48 virtual ~MediaDeviceNotificationsTest() {} |
43 | 49 |
44 protected: | 50 protected: |
45 virtual void SetUp() { | 51 virtual void SetUp() { |
(...skipping 21 matching lines...) Expand all Loading... |
67 mock_devices_changed_observer_.get()); | 73 mock_devices_changed_observer_.get()); |
68 WaitForFileThread(); | 74 WaitForFileThread(); |
69 } | 75 } |
70 | 76 |
71 base::MockDevicesChangedObserver& observer() { | 77 base::MockDevicesChangedObserver& observer() { |
72 return *mock_devices_changed_observer_; | 78 return *mock_devices_changed_observer_; |
73 } | 79 } |
74 | 80 |
75 void MountDevice(MountError error_code, | 81 void MountDevice(MountError error_code, |
76 const DiskMountManager::MountPointInfo& mount_info, | 82 const DiskMountManager::MountPointInfo& mount_info, |
77 const std::string& device_id) { | 83 const std::string& unique_id) { |
78 if (error_code == MOUNT_ERROR_NONE) { | 84 if (error_code == MOUNT_ERROR_NONE) { |
79 disk_mount_manager_mock_->CreateDiskEntryForMountDevice( | 85 disk_mount_manager_mock_->CreateDiskEntryForMountDevice( |
80 mount_info, device_id); | 86 mount_info, unique_id); |
81 } | 87 } |
82 notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, | 88 notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, |
83 error_code, | 89 error_code, |
84 mount_info); | 90 mount_info); |
85 WaitForFileThread(); | 91 WaitForFileThread(); |
86 } | 92 } |
87 | 93 |
88 void UnmountDevice(MountError error_code, | 94 void UnmountDevice(MountError error_code, |
89 const DiskMountManager::MountPointInfo& mount_info) { | 95 const DiskMountManager::MountPointInfo& mount_info) { |
90 notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, | 96 notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 154 |
149 // Simple test case where we attach and detach a media device. | 155 // Simple test case where we attach and detach a media device. |
150 TEST_F(MediaDeviceNotificationsTest, BasicAttachDetach) { | 156 TEST_F(MediaDeviceNotificationsTest, BasicAttachDetach) { |
151 testing::Sequence mock_sequence; | 157 testing::Sequence mock_sequence; |
152 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 158 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
153 ASSERT_FALSE(mount_path1.empty()); | 159 ASSERT_FALSE(mount_path1.empty()); |
154 DiskMountManager::MountPointInfo mount_info(kDevice1, | 160 DiskMountManager::MountPointInfo mount_info(kDevice1, |
155 mount_path1.value(), | 161 mount_path1.value(), |
156 MOUNT_TYPE_DEVICE, | 162 MOUNT_TYPE_DEVICE, |
157 disks::MOUNT_CONDITION_NONE); | 163 disks::MOUNT_CONDITION_NONE); |
158 const std::string kDeviceId0 = "FFFF-FFFF"; | 164 const std::string kUniqueId0 = "FFFF-FFFF"; |
159 EXPECT_CALL(observer(), | 165 EXPECT_CALL(observer(), |
160 OnMediaDeviceAttached(kDeviceId0, | 166 OnMediaDeviceAttached(GetDCIMDeviceId(kUniqueId0), |
161 ASCIIToUTF16(kDevice1Name), | 167 ASCIIToUTF16(kDevice1Name), |
162 base::SystemMonitor::TYPE_PATH, | |
163 mount_path1.value())) | 168 mount_path1.value())) |
164 .InSequence(mock_sequence); | 169 .InSequence(mock_sequence); |
165 MountDevice(MOUNT_ERROR_NONE, mount_info, kDeviceId0); | 170 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0); |
166 | 171 |
167 EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId0)) | 172 EXPECT_CALL(observer(), OnMediaDeviceDetached(GetDCIMDeviceId(kUniqueId0))) |
168 .InSequence(mock_sequence); | 173 .InSequence(mock_sequence); |
169 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 174 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
170 | 175 |
171 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); | 176 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); |
172 ASSERT_FALSE(mount_path2.empty()); | 177 ASSERT_FALSE(mount_path2.empty()); |
173 DiskMountManager::MountPointInfo mount_info2(kDevice2, | 178 DiskMountManager::MountPointInfo mount_info2(kDevice2, |
174 mount_path2.value(), | 179 mount_path2.value(), |
175 MOUNT_TYPE_DEVICE, | 180 MOUNT_TYPE_DEVICE, |
176 disks::MOUNT_CONDITION_NONE); | 181 disks::MOUNT_CONDITION_NONE); |
177 const std::string kDeviceId1 = "FFF0-FFF0"; | 182 const std::string kUniqueId1 = "FFF0-FFF0"; |
178 | 183 |
179 EXPECT_CALL(observer(), | 184 EXPECT_CALL(observer(), |
180 OnMediaDeviceAttached(kDeviceId1, | 185 OnMediaDeviceAttached(GetDCIMDeviceId(kUniqueId1), |
181 ASCIIToUTF16(kDevice2Name), | 186 ASCIIToUTF16(kDevice2Name), |
182 base::SystemMonitor::TYPE_PATH, | |
183 mount_path2.value())) | 187 mount_path2.value())) |
184 .InSequence(mock_sequence); | 188 .InSequence(mock_sequence); |
185 MountDevice(MOUNT_ERROR_NONE, mount_info2, kDeviceId1); | 189 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId1); |
186 | 190 |
187 EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId1)) | 191 EXPECT_CALL(observer(), OnMediaDeviceDetached(GetDCIMDeviceId(kUniqueId1))) |
188 .InSequence(mock_sequence); | 192 .InSequence(mock_sequence); |
189 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | 193 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
190 } | 194 } |
191 | 195 |
192 // Only mount points with DCIM directories are recognized. | 196 // Only mount points with DCIM directories are recognized. |
193 TEST_F(MediaDeviceNotificationsTest, DCIM) { | 197 TEST_F(MediaDeviceNotificationsTest, DCIM) { |
194 testing::Sequence mock_sequence; | 198 testing::Sequence mock_sequence; |
195 FilePath mount_path = CreateMountPoint(kMountPointA, false); | 199 FilePath mount_path = CreateMountPoint(kMountPointA, false); |
196 const std::string kDeviceId = "FFFF-FFFF"; | 200 const std::string kUniqueId = "FFFF-FFFF"; |
197 ASSERT_FALSE(mount_path.empty()); | 201 ASSERT_FALSE(mount_path.empty()); |
198 DiskMountManager::MountPointInfo mount_info(kDevice1, | 202 DiskMountManager::MountPointInfo mount_info(kDevice1, |
199 mount_path.value(), | 203 mount_path.value(), |
200 MOUNT_TYPE_DEVICE, | 204 MOUNT_TYPE_DEVICE, |
201 disks::MOUNT_CONDITION_NONE); | 205 disks::MOUNT_CONDITION_NONE); |
202 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); | 206 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
203 MountDevice(MOUNT_ERROR_NONE, mount_info, kDeviceId); | 207 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId); |
204 } | 208 } |
205 | 209 |
206 // Non device mounts and mount errors are ignored. | 210 // Non device mounts and mount errors are ignored. |
207 TEST_F(MediaDeviceNotificationsTest, Ignore) { | 211 TEST_F(MediaDeviceNotificationsTest, Ignore) { |
208 testing::Sequence mock_sequence; | 212 testing::Sequence mock_sequence; |
209 FilePath mount_path = CreateMountPoint(kMountPointA, true); | 213 FilePath mount_path = CreateMountPoint(kMountPointA, true); |
210 const std::string kDeviceId = "FFFF-FFFF"; | 214 const std::string kUniqueId = "FFFF-FFFF"; |
211 ASSERT_FALSE(mount_path.empty()); | 215 ASSERT_FALSE(mount_path.empty()); |
212 | 216 |
213 // Mount error. | 217 // Mount error. |
214 DiskMountManager::MountPointInfo mount_info(kDevice1, | 218 DiskMountManager::MountPointInfo mount_info(kDevice1, |
215 mount_path.value(), | 219 mount_path.value(), |
216 MOUNT_TYPE_DEVICE, | 220 MOUNT_TYPE_DEVICE, |
217 disks::MOUNT_CONDITION_NONE); | 221 disks::MOUNT_CONDITION_NONE); |
218 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); | 222 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
219 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kDeviceId); | 223 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId); |
220 | 224 |
221 // Not a device | 225 // Not a device |
222 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; | 226 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; |
223 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); | 227 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
224 MountDevice(MOUNT_ERROR_NONE, mount_info, kDeviceId); | 228 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId); |
225 | 229 |
226 // Unsupported file system. | 230 // Unsupported file system. |
227 mount_info.mount_type = MOUNT_TYPE_DEVICE; | 231 mount_info.mount_type = MOUNT_TYPE_DEVICE; |
228 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; | 232 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
229 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); | 233 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
230 MountDevice(MOUNT_ERROR_NONE, mount_info, kDeviceId); | 234 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId); |
231 } | 235 } |
232 | 236 |
233 } // namespace | 237 } // namespace |
234 | 238 |
235 } // namespace chrome | 239 } // namespace chrome |
OLD | NEW |