Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/media_gallery/media_device_notifications_chromeos_unittest.cc

Issue 10830003: Extract and dispatch device uuid in media device attached notification message. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 system_monitor_.RemoveDevicesChangedObserver( 66 system_monitor_.RemoveDevicesChangedObserver(
67 mock_devices_changed_observer_.get()); 67 mock_devices_changed_observer_.get());
68 WaitForFileThread(); 68 WaitForFileThread();
69 } 69 }
70 70
71 base::MockDevicesChangedObserver& observer() { 71 base::MockDevicesChangedObserver& observer() {
72 return *mock_devices_changed_observer_; 72 return *mock_devices_changed_observer_;
73 } 73 }
74 74
75 void MountDevice(MountError error_code, 75 void MountDevice(MountError error_code,
76 const DiskMountManager::MountPointInfo& mount_info) { 76 const DiskMountManager::MountPointInfo& mount_info,
77 const std::string& device_id) {
78 if (error_code == MOUNT_ERROR_NONE) {
79 disk_mount_manager_mock_->CreateDiskEntryForMountDevice(
80 mount_info, device_id);
81 }
77 notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, 82 notifications_->MountCompleted(disks::DiskMountManager::MOUNTING,
78 error_code, 83 error_code,
79 mount_info); 84 mount_info);
80 WaitForFileThread(); 85 WaitForFileThread();
81 } 86 }
82 87
83 void UnmountDevice(MountError error_code, 88 void UnmountDevice(MountError error_code,
84 const DiskMountManager::MountPointInfo& mount_info) { 89 const DiskMountManager::MountPointInfo& mount_info) {
85 notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, 90 notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING,
86 error_code, 91 error_code,
87 mount_info); 92 mount_info);
93 if (error_code == MOUNT_ERROR_NONE) {
94 disk_mount_manager_mock_->RemoveDiskEntryForMountDevice(
95 mount_info);
96 }
88 WaitForFileThread(); 97 WaitForFileThread();
89 } 98 }
90 99
91 // Create a directory named |dir| relative to the test directory. 100 // Create a directory named |dir| relative to the test directory.
92 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" 101 // Set |with_dcim_dir| to true if the created directory will have a "DCIM"
93 // subdirectory. 102 // subdirectory.
94 // Returns the full path to the created directory on success, or an empty 103 // Returns the full path to the created directory on success, or an empty
95 // path on failure. 104 // path on failure.
96 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { 105 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) {
97 FilePath return_path(scoped_temp_dir_.path()); 106 FilePath return_path(scoped_temp_dir_.path());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 148
140 // Simple test case where we attach and detach a media device. 149 // Simple test case where we attach and detach a media device.
141 TEST_F(MediaDeviceNotificationsTest, BasicAttachDetach) { 150 TEST_F(MediaDeviceNotificationsTest, BasicAttachDetach) {
142 testing::Sequence mock_sequence; 151 testing::Sequence mock_sequence;
143 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); 152 FilePath mount_path1 = CreateMountPoint(kMountPointA, true);
144 ASSERT_FALSE(mount_path1.empty()); 153 ASSERT_FALSE(mount_path1.empty());
145 DiskMountManager::MountPointInfo mount_info(kDevice1, 154 DiskMountManager::MountPointInfo mount_info(kDevice1,
146 mount_path1.value(), 155 mount_path1.value(),
147 MOUNT_TYPE_DEVICE, 156 MOUNT_TYPE_DEVICE,
148 disks::MOUNT_CONDITION_NONE); 157 disks::MOUNT_CONDITION_NONE);
149 const std::string kDeviceId0 = "0"; 158 const std::string kDeviceId0 = "FFFF-FFFF";
150 EXPECT_CALL(observer(), 159 EXPECT_CALL(observer(),
151 OnMediaDeviceAttached(kDeviceId0, 160 OnMediaDeviceAttached(kDeviceId0,
152 ASCIIToUTF16(kDevice1Name), 161 ASCIIToUTF16(kDevice1Name),
153 base::SystemMonitor::TYPE_PATH, 162 base::SystemMonitor::TYPE_PATH,
154 mount_path1.value())) 163 mount_path1.value()))
155 .InSequence(mock_sequence); 164 .InSequence(mock_sequence);
156 MountDevice(MOUNT_ERROR_NONE, mount_info); 165 MountDevice(MOUNT_ERROR_NONE, mount_info, kDeviceId0);
157 166
158 EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId0)) 167 EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId0))
159 .InSequence(mock_sequence); 168 .InSequence(mock_sequence);
160 UnmountDevice(MOUNT_ERROR_NONE, mount_info); 169 UnmountDevice(MOUNT_ERROR_NONE, mount_info);
161 170
162 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); 171 FilePath mount_path2 = CreateMountPoint(kMountPointB, true);
163 ASSERT_FALSE(mount_path2.empty()); 172 ASSERT_FALSE(mount_path2.empty());
164 DiskMountManager::MountPointInfo mount_info2(kDevice2, 173 DiskMountManager::MountPointInfo mount_info2(kDevice2,
165 mount_path2.value(), 174 mount_path2.value(),
166 MOUNT_TYPE_DEVICE, 175 MOUNT_TYPE_DEVICE,
167 disks::MOUNT_CONDITION_NONE); 176 disks::MOUNT_CONDITION_NONE);
168 const std::string kDeviceId1 = "1"; 177 const std::string kDeviceId1 = "FFF0-FFF0";
169 178
170 EXPECT_CALL(observer(), 179 EXPECT_CALL(observer(),
171 OnMediaDeviceAttached(kDeviceId1, 180 OnMediaDeviceAttached(kDeviceId1,
172 ASCIIToUTF16(kDevice2Name), 181 ASCIIToUTF16(kDevice2Name),
173 base::SystemMonitor::TYPE_PATH, 182 base::SystemMonitor::TYPE_PATH,
174 mount_path2.value())) 183 mount_path2.value()))
175 .InSequence(mock_sequence); 184 .InSequence(mock_sequence);
176 MountDevice(MOUNT_ERROR_NONE, mount_info2); 185 MountDevice(MOUNT_ERROR_NONE, mount_info2, kDeviceId1);
177 186
178 EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId1)) 187 EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId1))
179 .InSequence(mock_sequence); 188 .InSequence(mock_sequence);
180 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); 189 UnmountDevice(MOUNT_ERROR_NONE, mount_info2);
181 } 190 }
182 191
183 // Only mount points with DCIM directories are recognized. 192 // Only mount points with DCIM directories are recognized.
184 TEST_F(MediaDeviceNotificationsTest, DCIM) { 193 TEST_F(MediaDeviceNotificationsTest, DCIM) {
185 testing::Sequence mock_sequence; 194 testing::Sequence mock_sequence;
186 FilePath mount_path = CreateMountPoint(kMountPointA, false); 195 FilePath mount_path = CreateMountPoint(kMountPointA, false);
196 const std::string kDeviceId = "FFFF-FFFF";
187 ASSERT_FALSE(mount_path.empty()); 197 ASSERT_FALSE(mount_path.empty());
188 DiskMountManager::MountPointInfo mount_info(kDevice1, 198 DiskMountManager::MountPointInfo mount_info(kDevice1,
189 mount_path.value(), 199 mount_path.value(),
190 MOUNT_TYPE_DEVICE, 200 MOUNT_TYPE_DEVICE,
191 disks::MOUNT_CONDITION_NONE); 201 disks::MOUNT_CONDITION_NONE);
192 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); 202 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0);
193 MountDevice(MOUNT_ERROR_NONE, mount_info); 203 MountDevice(MOUNT_ERROR_NONE, mount_info, kDeviceId);
194 } 204 }
195 205
196 // Non device mounts and mount errors are ignored. 206 // Non device mounts and mount errors are ignored.
197 TEST_F(MediaDeviceNotificationsTest, Ignore) { 207 TEST_F(MediaDeviceNotificationsTest, Ignore) {
198 testing::Sequence mock_sequence; 208 testing::Sequence mock_sequence;
199 FilePath mount_path = CreateMountPoint(kMountPointA, true); 209 FilePath mount_path = CreateMountPoint(kMountPointA, true);
210 const std::string kDeviceId = "FFFF-FFFF";
200 ASSERT_FALSE(mount_path.empty()); 211 ASSERT_FALSE(mount_path.empty());
201 212
202 // Mount error. 213 // Mount error.
203 DiskMountManager::MountPointInfo mount_info(kDevice1, 214 DiskMountManager::MountPointInfo mount_info(kDevice1,
204 mount_path.value(), 215 mount_path.value(),
205 MOUNT_TYPE_DEVICE, 216 MOUNT_TYPE_DEVICE,
206 disks::MOUNT_CONDITION_NONE); 217 disks::MOUNT_CONDITION_NONE);
207 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); 218 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0);
208 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info); 219 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kDeviceId);
209 220
210 // Not a device 221 // Not a device
211 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; 222 mount_info.mount_type = MOUNT_TYPE_ARCHIVE;
212 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); 223 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0);
213 MountDevice(MOUNT_ERROR_NONE, mount_info); 224 MountDevice(MOUNT_ERROR_NONE, mount_info, kDeviceId);
214 225
215 // Unsupported file system. 226 // Unsupported file system.
216 mount_info.mount_type = MOUNT_TYPE_DEVICE; 227 mount_info.mount_type = MOUNT_TYPE_DEVICE;
217 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; 228 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM;
218 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); 229 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0);
219 MountDevice(MOUNT_ERROR_NONE, mount_info); 230 MountDevice(MOUNT_ERROR_NONE, mount_info, kDeviceId);
220 } 231 }
221 232
222 } // namespace 233 } // namespace
223 234
224 } // namespace chrome 235 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698