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 "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" | 17 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" |
17 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace chromeos { | 21 namespace chromeos { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 using content::BrowserThread; | 25 using content::BrowserThread; |
25 using disks::DiskMountManager; | 26 using disks::DiskMountManager; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 139 |
139 // Simple test case where we attach and detach a media device. | 140 // Simple test case where we attach and detach a media device. |
140 TEST_F(MediaDeviceNotificationsTest, BasicAttachDetach) { | 141 TEST_F(MediaDeviceNotificationsTest, BasicAttachDetach) { |
141 testing::Sequence mock_sequence; | 142 testing::Sequence mock_sequence; |
142 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 143 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
143 ASSERT_FALSE(mount_path1.empty()); | 144 ASSERT_FALSE(mount_path1.empty()); |
144 DiskMountManager::MountPointInfo mount_info(kDevice1, | 145 DiskMountManager::MountPointInfo mount_info(kDevice1, |
145 mount_path1.value(), | 146 mount_path1.value(), |
146 MOUNT_TYPE_DEVICE, | 147 MOUNT_TYPE_DEVICE, |
147 disks::MOUNT_CONDITION_NONE); | 148 disks::MOUNT_CONDITION_NONE); |
148 EXPECT_CALL(observer(), OnMediaDeviceAttached(0, kDevice1Name, mount_path1)) | 149 const std::string kDeviceId0 = "0"; |
| 150 EXPECT_CALL(observer(), |
| 151 OnMediaDeviceAttached(kDeviceId0, |
| 152 ASCIIToUTF16(kDevice1Name), |
| 153 base::SystemMonitor::TYPE_PATH, |
| 154 mount_path1.value())) |
149 .InSequence(mock_sequence); | 155 .InSequence(mock_sequence); |
150 MountDevice(MOUNT_ERROR_NONE, mount_info); | 156 MountDevice(MOUNT_ERROR_NONE, mount_info); |
151 | 157 |
152 EXPECT_CALL(observer(), OnMediaDeviceDetached(0)).InSequence(mock_sequence); | 158 EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId0)) |
| 159 .InSequence(mock_sequence); |
153 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 160 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
154 | 161 |
155 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); | 162 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); |
156 ASSERT_FALSE(mount_path2.empty()); | 163 ASSERT_FALSE(mount_path2.empty()); |
157 DiskMountManager::MountPointInfo mount_info2(kDevice2, | 164 DiskMountManager::MountPointInfo mount_info2(kDevice2, |
158 mount_path2.value(), | 165 mount_path2.value(), |
159 MOUNT_TYPE_DEVICE, | 166 MOUNT_TYPE_DEVICE, |
160 disks::MOUNT_CONDITION_NONE); | 167 disks::MOUNT_CONDITION_NONE); |
161 EXPECT_CALL(observer(), OnMediaDeviceAttached(1, kDevice2Name, mount_path2)) | 168 const std::string kDeviceId1 = "1"; |
| 169 |
| 170 EXPECT_CALL(observer(), |
| 171 OnMediaDeviceAttached(kDeviceId1, |
| 172 ASCIIToUTF16(kDevice2Name), |
| 173 base::SystemMonitor::TYPE_PATH, |
| 174 mount_path2.value())) |
162 .InSequence(mock_sequence); | 175 .InSequence(mock_sequence); |
163 MountDevice(MOUNT_ERROR_NONE, mount_info2); | 176 MountDevice(MOUNT_ERROR_NONE, mount_info2); |
164 | 177 |
165 EXPECT_CALL(observer(), OnMediaDeviceDetached(1)).InSequence(mock_sequence); | 178 EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId1)) |
| 179 .InSequence(mock_sequence); |
166 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | 180 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
167 } | 181 } |
168 | 182 |
169 // Only mount points with DCIM directories are recognized. | 183 // Only mount points with DCIM directories are recognized. |
170 TEST_F(MediaDeviceNotificationsTest, DCIM) { | 184 TEST_F(MediaDeviceNotificationsTest, DCIM) { |
171 testing::Sequence mock_sequence; | 185 testing::Sequence mock_sequence; |
172 FilePath mount_path = CreateMountPoint(kMountPointA, false); | 186 FilePath mount_path = CreateMountPoint(kMountPointA, false); |
173 ASSERT_FALSE(mount_path.empty()); | 187 ASSERT_FALSE(mount_path.empty()); |
174 DiskMountManager::MountPointInfo mount_info(kDevice1, | 188 DiskMountManager::MountPointInfo mount_info(kDevice1, |
175 mount_path.value(), | 189 mount_path.value(), |
176 MOUNT_TYPE_DEVICE, | 190 MOUNT_TYPE_DEVICE, |
177 disks::MOUNT_CONDITION_NONE); | 191 disks::MOUNT_CONDITION_NONE); |
178 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); | 192 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); |
179 MountDevice(MOUNT_ERROR_NONE, mount_info); | 193 MountDevice(MOUNT_ERROR_NONE, mount_info); |
180 } | 194 } |
181 | 195 |
182 // Non device mounts and mount errors are ignored. | 196 // Non device mounts and mount errors are ignored. |
183 TEST_F(MediaDeviceNotificationsTest, Ignore) { | 197 TEST_F(MediaDeviceNotificationsTest, Ignore) { |
184 testing::Sequence mock_sequence; | 198 testing::Sequence mock_sequence; |
185 FilePath mount_path = CreateMountPoint(kMountPointA, true); | 199 FilePath mount_path = CreateMountPoint(kMountPointA, true); |
186 ASSERT_FALSE(mount_path.empty()); | 200 ASSERT_FALSE(mount_path.empty()); |
187 | 201 |
188 // Mount error. | 202 // Mount error. |
189 DiskMountManager::MountPointInfo mount_info(kDevice1, | 203 DiskMountManager::MountPointInfo mount_info(kDevice1, |
190 mount_path.value(), | 204 mount_path.value(), |
191 MOUNT_TYPE_DEVICE, | 205 MOUNT_TYPE_DEVICE, |
192 disks::MOUNT_CONDITION_NONE); | 206 disks::MOUNT_CONDITION_NONE); |
193 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); | 207 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); |
194 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info); | 208 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info); |
195 | 209 |
196 // Not a device | 210 // Not a device |
197 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; | 211 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; |
198 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); | 212 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); |
199 MountDevice(MOUNT_ERROR_NONE, mount_info); | 213 MountDevice(MOUNT_ERROR_NONE, mount_info); |
200 | 214 |
201 // Unsupported file system. | 215 // Unsupported file system. |
202 mount_info.mount_type = MOUNT_TYPE_DEVICE; | 216 mount_info.mount_type = MOUNT_TYPE_DEVICE; |
203 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; | 217 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
204 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); | 218 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); |
205 MountDevice(MOUNT_ERROR_NONE, mount_info); | 219 MountDevice(MOUNT_ERROR_NONE, mount_info); |
206 } | 220 } |
207 | 221 |
208 } // namespace | 222 } // namespace |
209 | 223 |
210 } // namespace chrome | 224 } // namespace chrome |
OLD | NEW |