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