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 // MediaDeviceNotificationsLinux unit tests. | 5 // RemovableDeviceNotificationsLinux unit tests. |
6 | 6 |
7 #include "chrome/browser/media_gallery/media_device_notifications_linux.h" | 7 #include "chrome/browser/media_gallery/removable_device_notifications_linux.h" |
8 | 8 |
9 #include <mntent.h> | 9 #include <mntent.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
30 using testing::_; | 30 using testing::_; |
31 | 31 |
32 const char kValidFS[] = "vfat"; | 32 const char kValidFS[] = "vfat"; |
33 const char kInvalidFS[] = "invalidfs"; | 33 const char kInvalidFS[] = "invalidfs"; |
34 | 34 |
35 const char kInvalidPath[] = "invalid path does not exist"; | 35 const char kInvalidPath[] = "invalid path does not exist"; |
36 | 36 |
37 const char kDevice1[] = "d1"; | 37 const char kDevice1[] = "d1"; |
38 const char kDevice2[] = "d2"; | 38 const char kDevice2[] = "d2"; |
39 const char kDevice3[] = "d3"; | 39 const char kDevice3[] = "d3"; |
40 const char kDevice4[] = "d4"; | |
41 const char kDevice5[] = "d5"; | |
40 | 42 |
41 const char kDeviceId1[] = "UUID:FFF0-000F"; | 43 const char kInvalidDevice[] = "invalid_device"; |
42 const char kDeviceId2[] = "VendorModelSerial:ComName:Model2010:898989898989"; | |
43 const char kDeviceId3[] = "VendorModelSerial:::WEM319X792"; | |
44 | |
45 const char kDeviceLabel1[] = "TEST_USB_MODEL_1"; | |
46 const char kDeviceLabel2[] = "TEST_USB_MODEL_2"; | |
47 const char kDeviceLabel3[] = "TEST_USB_MODEL_3"; | |
48 | 44 |
49 const char kMountPointA[] = "mnt_a"; | 45 const char kMountPointA[] = "mnt_a"; |
50 const char kMountPointB[] = "mnt_b"; | 46 const char kMountPointB[] = "mnt_b"; |
47 const char kMountPointC[] = "mnt_c"; | |
51 | 48 |
52 std::string GetDCIMDeviceId(std::string unique_id) { | 49 struct TestDeviceData { |
53 return chrome::MediaStorageUtil::MakeDeviceId( | 50 const char* device_path; |
54 chrome::MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM, unique_id); | 51 const char* unique_id; |
52 const char* device_name; | |
53 MediaStorageUtil::Type type; | |
54 }; | |
55 | |
56 const TestDeviceData kTestDeviceData[] = { | |
57 {kDevice1, "UUID:FFF0-000F", "TEST_USB_MODEL_1", | |
58 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM}, | |
59 {kDevice2, "VendorModelSerial:ComName:Model2010:89898989", "TEST_USB_MODEL_2", | |
60 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM}, | |
61 {kDevice3, "VendorModelSerial:::WEM319X792", "TEST_USB_MODEL_3", | |
62 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM}, | |
63 {kDevice4, "UUID:ABCD-1234", "TEST_USB_MODEL_4", | |
64 MediaStorageUtil::USB_MASS_STORAGE_NO_DCIM}, | |
65 {kDevice5, "UUID:743A91FD2349", "TEST_USB_MODEL_5", | |
66 MediaStorageUtil::OTHER_MASS_STORAGE}, | |
67 }; | |
68 | |
69 bool GetDeviceInfo(const FilePath& device_path, std::string* id, | |
70 string16* name, bool* removable) { | |
71 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { | |
72 if (device_path.value() == kTestDeviceData[i].device_path) { | |
73 if (id) | |
74 *id = kTestDeviceData[i].unique_id; | |
75 if (name) | |
76 *name = ASCIIToUTF16(kTestDeviceData[i].device_name); | |
77 if (removable) { | |
78 MediaStorageUtil::Type type = kTestDeviceData[i].type; | |
79 *removable = (type == MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM) || | |
80 (type == MediaStorageUtil::USB_MASS_STORAGE_NO_DCIM); | |
81 } | |
82 return true; | |
83 } | |
84 } | |
85 return false; | |
55 } | 86 } |
56 | 87 |
57 bool GetDeviceInfo(const std::string& dev_path, std::string* id, | 88 std::string GetDeviceId(const std::string& device) { |
58 string16* name) { | 89 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { |
59 std::string device_name; | 90 if (device == kTestDeviceData[i].device_path) { |
60 if (dev_path == kDevice1) { | 91 return MediaStorageUtil::MakeDeviceId(kTestDeviceData[i].type, |
61 *id = GetDCIMDeviceId(kDeviceId1); | 92 kTestDeviceData[i].unique_id); |
62 device_name = kDeviceLabel1; | 93 } |
63 } else if (dev_path == kDevice2) { | |
64 *id = GetDCIMDeviceId(kDeviceId2); | |
65 device_name = kDeviceLabel2; | |
66 } else if (dev_path == kDevice3) { | |
67 *id = GetDCIMDeviceId(kDeviceId3); | |
68 device_name = kDeviceLabel3; | |
69 } else { | |
70 return false; | |
71 } | 94 } |
72 | 95 if (device == kInvalidDevice) |
Lei Zhang
2012/08/28 07:55:30
nit: curly brackets
vandebo (ex-Chrome)
2012/08/28 18:59:30
Done.
| |
73 *name = ASCIIToUTF16(device_name); | 96 return MediaStorageUtil::MakeDeviceId(MediaStorageUtil::OTHER_MASS_STORAGE, |
74 return true; | 97 kInvalidDevice); |
98 return std::string(); | |
99 } | |
100 string16 GetDeviceName(const std::string& device) { | |
101 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { | |
102 if (device == kTestDeviceData[i].device_path) | |
103 return ASCIIToUTF16(kTestDeviceData[i].device_name); | |
104 } | |
105 return string16(); | |
75 } | 106 } |
76 | 107 |
77 class MediaDeviceNotificationsLinuxTestWrapper | 108 class RemovableDeviceNotificationsLinuxTestWrapper |
78 : public MediaDeviceNotificationsLinux { | 109 : public RemovableDeviceNotificationsLinux { |
79 public: | 110 public: |
80 MediaDeviceNotificationsLinuxTestWrapper(const FilePath& path, | 111 RemovableDeviceNotificationsLinuxTestWrapper(const FilePath& path, |
81 MessageLoop* message_loop) | 112 MessageLoop* message_loop) |
82 : MediaDeviceNotificationsLinux(path, &GetDeviceInfo), | 113 : RemovableDeviceNotificationsLinux(path, &GetDeviceInfo), |
83 message_loop_(message_loop) { | 114 message_loop_(message_loop) { |
84 } | 115 } |
85 | 116 |
86 private: | 117 private: |
87 // Avoids code deleting the object while there are references to it. | 118 // Avoids code deleting the object while there are references to it. |
88 // Aside from the base::RefCountedThreadSafe friend class, any attempts to | 119 // Aside from the base::RefCountedThreadSafe friend class, any attempts to |
89 // call this dtor will result in a compile-time error. | 120 // call this dtor will result in a compile-time error. |
90 ~MediaDeviceNotificationsLinuxTestWrapper() {} | 121 ~RemovableDeviceNotificationsLinuxTestWrapper() {} |
91 | 122 |
92 virtual void OnFilePathChanged(const FilePath& path, bool error) OVERRIDE { | 123 virtual void OnFilePathChanged(const FilePath& path, bool error) OVERRIDE { |
93 MediaDeviceNotificationsLinux::OnFilePathChanged(path, error); | 124 RemovableDeviceNotificationsLinux::OnFilePathChanged(path, error); |
94 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 125 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
95 } | 126 } |
96 | 127 |
97 MessageLoop* message_loop_; | 128 MessageLoop* message_loop_; |
98 | 129 |
99 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinuxTestWrapper); | 130 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinuxTestWrapper); |
100 }; | 131 }; |
101 | 132 |
102 class MediaDeviceNotificationsLinuxTest : public testing::Test { | 133 class RemovableDeviceNotificationLinuxTest : public testing::Test { |
103 public: | 134 public: |
104 struct MtabTestData { | 135 struct MtabTestData { |
105 MtabTestData(const std::string& mount_device, | 136 MtabTestData(const std::string& mount_device, |
106 const std::string& mount_point, | 137 const std::string& mount_point, |
107 const std::string& mount_type) | 138 const std::string& mount_type) |
108 : mount_device(mount_device), | 139 : mount_device(mount_device), |
109 mount_point(mount_point), | 140 mount_point(mount_point), |
110 mount_type(mount_type) { | 141 mount_type(mount_type) { |
111 } | 142 } |
112 | 143 |
113 const std::string mount_device; | 144 const std::string mount_device; |
114 const std::string mount_point; | 145 const std::string mount_point; |
115 const std::string mount_type; | 146 const std::string mount_type; |
116 }; | 147 }; |
117 | 148 |
118 MediaDeviceNotificationsLinuxTest() | 149 RemovableDeviceNotificationLinuxTest() |
119 : message_loop_(MessageLoop::TYPE_IO), | 150 : message_loop_(MessageLoop::TYPE_IO), |
120 file_thread_(content::BrowserThread::FILE, &message_loop_) { | 151 file_thread_(content::BrowserThread::FILE, &message_loop_) { |
121 } | 152 } |
122 virtual ~MediaDeviceNotificationsLinuxTest() {} | 153 virtual ~RemovableDeviceNotificationLinuxTest() {} |
123 | 154 |
124 protected: | 155 protected: |
125 virtual void SetUp() OVERRIDE { | 156 virtual void SetUp() OVERRIDE { |
126 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | 157 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); |
127 system_monitor_.AddDevicesChangedObserver( | 158 system_monitor_.AddDevicesChangedObserver( |
128 mock_devices_changed_observer_.get()); | 159 mock_devices_changed_observer_.get()); |
129 | 160 |
130 // Create and set up a temp dir with files for the test. | 161 // Create and set up a temp dir with files for the test. |
131 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 162 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
132 FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc"); | 163 FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc"); |
133 ASSERT_TRUE(file_util::CreateDirectory(test_dir)); | 164 ASSERT_TRUE(file_util::CreateDirectory(test_dir)); |
134 mtab_file_ = test_dir.AppendASCII("test_mtab"); | 165 mtab_file_ = test_dir.AppendASCII("test_mtab"); |
135 MtabTestData initial_test_data[] = { | 166 MtabTestData initial_test_data[] = { |
136 MtabTestData("dummydevice", "dummydir", kInvalidFS), | 167 MtabTestData("dummydevice", "dummydir", kInvalidFS), |
137 }; | 168 }; |
138 WriteToMtab(initial_test_data, | 169 WriteToMtab(initial_test_data, |
139 arraysize(initial_test_data), | 170 arraysize(initial_test_data), |
140 true /* overwrite */); | 171 true /* overwrite */); |
141 | 172 |
142 // Initialize the test subject. | 173 // Initialize the test subject. |
143 notifications_ = | 174 notifications_ = new RemovableDeviceNotificationsLinuxTestWrapper( |
144 new MediaDeviceNotificationsLinuxTestWrapper(mtab_file_, | 175 mtab_file_, &message_loop_); |
145 &message_loop_); | |
146 notifications_->Init(); | 176 notifications_->Init(); |
147 message_loop_.RunAllPending(); | 177 message_loop_.RunAllPending(); |
148 } | 178 } |
149 | 179 |
150 virtual void TearDown() OVERRIDE { | 180 virtual void TearDown() OVERRIDE { |
151 message_loop_.RunAllPending(); | 181 message_loop_.RunAllPending(); |
152 notifications_ = NULL; | 182 notifications_ = NULL; |
153 system_monitor_.RemoveDevicesChangedObserver( | 183 system_monitor_.RemoveDevicesChangedObserver( |
154 mock_devices_changed_observer_.get()); | 184 mock_devices_changed_observer_.get()); |
155 } | 185 } |
(...skipping 13 matching lines...) Expand all Loading... | |
169 } | 199 } |
170 | 200 |
171 // Simplied version of OverwriteMtabAndRunLoop() that just deletes all the | 201 // Simplied version of OverwriteMtabAndRunLoop() that just deletes all the |
172 // entries in the mtab file. | 202 // entries in the mtab file. |
173 void WriteEmptyMtabAndRunLoop() { | 203 void WriteEmptyMtabAndRunLoop() { |
174 OverwriteMtabAndRunLoop(NULL, // No data. | 204 OverwriteMtabAndRunLoop(NULL, // No data. |
175 0); // No data length. | 205 0); // No data length. |
176 } | 206 } |
177 | 207 |
178 // Create a directory named |dir| relative to the test directory. | 208 // Create a directory named |dir| relative to the test directory. |
179 // It has a DCIM directory, so MediaDeviceNotificationsLinux recognizes it as | 209 // It has a DCIM directory, so RemovableDeviceNotificationsLinux recognizes it |
180 // a media directory. | 210 // as a media directory. |
181 FilePath CreateMountPointWithDCIMDir(const std::string& dir) { | 211 FilePath CreateMountPointWithDCIMDir(const std::string& dir) { |
182 return CreateMountPoint(dir, true /* create DCIM dir */); | 212 return CreateMountPoint(dir, true /* create DCIM dir */); |
183 } | 213 } |
184 | 214 |
185 // Create a directory named |dir| relative to the test directory. | 215 // Create a directory named |dir| relative to the test directory. |
186 // It does not have a DCIM directory, so MediaDeviceNotificationsLinux does | 216 // It does not have a DCIM directory, so RemovableDeviceNotificationsLinux |
187 // not recognizes it as a media directory. | 217 // does not recognizes it as a media directory. |
188 FilePath CreateMountPointWithoutDCIMDir(const std::string& dir) { | 218 FilePath CreateMountPointWithoutDCIMDir(const std::string& dir) { |
189 return CreateMountPoint(dir, false /* do not create DCIM dir */); | 219 return CreateMountPoint(dir, false /* do not create DCIM dir */); |
190 } | 220 } |
191 | 221 |
192 base::MockDevicesChangedObserver& observer() { | 222 base::MockDevicesChangedObserver& observer() { |
193 return *mock_devices_changed_observer_; | 223 return *mock_devices_changed_observer_; |
194 } | 224 } |
195 | 225 |
226 RemovableDeviceNotificationsLinux* notifier() { | |
227 return notifications_.get(); | |
228 } | |
229 | |
196 private: | 230 private: |
197 // Create a directory named |dir| relative to the test directory. | 231 // Create a directory named |dir| relative to the test directory. |
198 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 232 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
199 // subdirectory. | 233 // subdirectory. |
200 // Returns the full path to the created directory on success, or an empty | 234 // Returns the full path to the created directory on success, or an empty |
201 // path on failure. | 235 // path on failure. |
202 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { | 236 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { |
203 FilePath return_path(scoped_temp_dir_.path()); | 237 FilePath return_path(scoped_temp_dir_.path()); |
204 return_path = return_path.AppendASCII(dir); | 238 return_path = return_path.AppendASCII(dir); |
205 FilePath path(return_path); | 239 FilePath path(return_path); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 | 283 |
250 // SystemMonitor and DevicesChangedObserver to hook together to test. | 284 // SystemMonitor and DevicesChangedObserver to hook together to test. |
251 base::SystemMonitor system_monitor_; | 285 base::SystemMonitor system_monitor_; |
252 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; | 286 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; |
253 | 287 |
254 // Temporary directory for created test data. | 288 // Temporary directory for created test data. |
255 ScopedTempDir scoped_temp_dir_; | 289 ScopedTempDir scoped_temp_dir_; |
256 // Path to the test mtab file. | 290 // Path to the test mtab file. |
257 FilePath mtab_file_; | 291 FilePath mtab_file_; |
258 | 292 |
259 scoped_refptr<MediaDeviceNotificationsLinuxTestWrapper> notifications_; | 293 scoped_refptr<RemovableDeviceNotificationsLinuxTestWrapper> notifications_; |
260 | 294 |
261 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinuxTest); | 295 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationLinuxTest); |
262 }; | 296 }; |
263 | 297 |
264 // Simple test case where we attach and detach a media device. | 298 // Simple test case where we attach and detach a media device. |
265 TEST_F(MediaDeviceNotificationsLinuxTest, BasicAttachDetach) { | 299 TEST_F(RemovableDeviceNotificationLinuxTest, BasicAttachDetach) { |
266 testing::Sequence mock_sequence; | 300 testing::Sequence mock_sequence; |
267 FilePath test_path = CreateMountPointWithDCIMDir(kMountPointA); | 301 FilePath test_path = CreateMountPointWithDCIMDir(kMountPointA); |
268 ASSERT_FALSE(test_path.empty()); | 302 ASSERT_FALSE(test_path.empty()); |
269 MtabTestData test_data[] = { | 303 MtabTestData test_data[] = { |
270 MtabTestData(kDevice1, kInvalidPath, kValidFS), | 304 MtabTestData(kDevice1, kInvalidPath, kValidFS), |
271 MtabTestData(kDevice2, test_path.value(), kValidFS), | 305 MtabTestData(kDevice2, test_path.value(), kValidFS), |
272 }; | 306 }; |
273 // Only |kDevice2| should be attached, since |kDevice1| has a bad path. | 307 // Only |kDevice2| should be attached, since |kDevice1| has a bad path. |
274 EXPECT_CALL(observer(), | 308 EXPECT_CALL(observer(), OnRemovableStorageAttached(GetDeviceId(kDevice2), |
275 OnRemovableStorageAttached(GetDCIMDeviceId(kDeviceId2), | 309 GetDeviceName(kDevice2), |
276 ASCIIToUTF16(kDeviceLabel2), | 310 test_path.value())) |
277 test_path.value())) | |
278 .InSequence(mock_sequence); | 311 .InSequence(mock_sequence); |
279 AppendToMtabAndRunLoop(test_data, arraysize(test_data)); | 312 AppendToMtabAndRunLoop(test_data, arraysize(test_data)); |
280 | 313 |
281 // |kDevice2| should be detached here. | 314 // |kDevice2| should be detached here. |
282 EXPECT_CALL(observer(), | 315 EXPECT_CALL(observer(), OnRemovableStorageDetached(GetDeviceId(kDevice2))) |
283 OnRemovableStorageDetached(GetDCIMDeviceId(kDeviceId2))) | |
284 .InSequence(mock_sequence); | 316 .InSequence(mock_sequence); |
285 WriteEmptyMtabAndRunLoop(); | 317 WriteEmptyMtabAndRunLoop(); |
286 } | 318 } |
287 | 319 |
288 // Only mount points with DCIM directories are recognized. | 320 // Only mount points with DCIM directories are recognized. |
289 TEST_F(MediaDeviceNotificationsLinuxTest, DCIM) { | 321 TEST_F(RemovableDeviceNotificationLinuxTest, DCIM) { |
290 testing::Sequence mock_sequence; | 322 testing::Sequence mock_sequence; |
291 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 323 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
292 ASSERT_FALSE(test_path_a.empty()); | 324 ASSERT_FALSE(test_path_a.empty()); |
293 MtabTestData test_data1[] = { | 325 MtabTestData test_data1[] = { |
294 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | 326 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
295 }; | 327 }; |
296 // |kDevice1| should be attached as expected. | 328 // |kDevice1| should be attached as expected. |
297 EXPECT_CALL(observer(), | 329 EXPECT_CALL(observer(), OnRemovableStorageAttached(GetDeviceId(kDevice1), |
298 OnRemovableStorageAttached(GetDCIMDeviceId(kDeviceId1), | 330 GetDeviceName(kDevice1), |
299 ASCIIToUTF16(kDeviceLabel1), | 331 test_path_a.value())) |
300 test_path_a.value())) | |
301 .InSequence(mock_sequence); | 332 .InSequence(mock_sequence); |
302 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); | 333 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
303 | 334 |
304 // This should do nothing, since |kMountPointB| does not have a DCIM dir. | 335 // This should do nothing, since |kMountPointB| does not have a DCIM dir. |
305 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); | 336 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); |
306 ASSERT_FALSE(test_path_b.empty()); | 337 ASSERT_FALSE(test_path_b.empty()); |
307 MtabTestData test_data2[] = { | 338 MtabTestData test_data2[] = { |
308 MtabTestData(kDevice2, test_path_b.value(), kValidFS), | 339 MtabTestData(kDevice2, test_path_b.value(), kValidFS), |
309 }; | 340 }; |
310 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); | 341 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); |
311 | 342 |
312 // |kDevice1| should be detached as expected. | 343 // |kDevice1| should be detached as expected. |
313 EXPECT_CALL(observer(), | 344 EXPECT_CALL(observer(), OnRemovableStorageDetached(GetDeviceId(kDevice1))) |
314 OnRemovableStorageDetached(GetDCIMDeviceId(kDeviceId1))) | |
315 .InSequence(mock_sequence); | 345 .InSequence(mock_sequence); |
316 WriteEmptyMtabAndRunLoop(); | 346 WriteEmptyMtabAndRunLoop(); |
317 } | 347 } |
318 | 348 |
319 // More complicated test case with multiple devices on multiple mount points. | 349 // More complicated test case with multiple devices on multiple mount points. |
320 TEST_F(MediaDeviceNotificationsLinuxTest, SwapMountPoints) { | 350 TEST_F(RemovableDeviceNotificationLinuxTest, SwapMountPoints) { |
321 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 351 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
322 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); | 352 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
323 ASSERT_FALSE(test_path_a.empty()); | 353 ASSERT_FALSE(test_path_a.empty()); |
324 ASSERT_FALSE(test_path_b.empty()); | 354 ASSERT_FALSE(test_path_b.empty()); |
325 | 355 |
326 // Attach two devices. | 356 // Attach two devices. |
327 // kDevice1 -> kMountPointA | 357 // kDevice1 -> kMountPointA |
328 // kDevice2 -> kMountPointB | 358 // kDevice2 -> kMountPointB |
329 MtabTestData test_data1[] = { | 359 MtabTestData test_data1[] = { |
330 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | 360 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
(...skipping 15 matching lines...) Expand all Loading... | |
346 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(2); | 376 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(2); |
347 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); | 377 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); |
348 | 378 |
349 // Detach all devices. | 379 // Detach all devices. |
350 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 380 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
351 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(2); | 381 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(2); |
352 WriteEmptyMtabAndRunLoop(); | 382 WriteEmptyMtabAndRunLoop(); |
353 } | 383 } |
354 | 384 |
355 // More complicated test case with multiple devices on multiple mount points. | 385 // More complicated test case with multiple devices on multiple mount points. |
356 TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesMultiMountPoints) { | 386 TEST_F(RemovableDeviceNotificationLinuxTest, MultiDevicesMultiMountPoints) { |
357 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 387 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
358 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); | 388 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
359 ASSERT_FALSE(test_path_a.empty()); | 389 ASSERT_FALSE(test_path_a.empty()); |
360 ASSERT_FALSE(test_path_b.empty()); | 390 ASSERT_FALSE(test_path_b.empty()); |
361 | 391 |
362 // Attach two devices. | 392 // Attach two devices. |
363 // kDevice1 -> kMountPointA | 393 // kDevice1 -> kMountPointA * |
364 // kDevice2 -> kMountPointB | 394 // kDevice2 -> kMountPointB * |
365 MtabTestData test_data1[] = { | 395 MtabTestData test_data1[] = { |
366 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | 396 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
367 MtabTestData(kDevice2, test_path_b.value(), kValidFS), | 397 MtabTestData(kDevice2, test_path_b.value(), kValidFS), |
368 }; | 398 }; |
369 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(2); | 399 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(2); |
370 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | 400 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); |
371 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); | 401 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
372 | 402 |
373 // Attach |kDevice1| to |kMountPointB|. | 403 // Attach |kDevice1| to |kMountPointB|. |
374 // |kDevice2| is inaccessible, so it is detached. |kDevice1| has been | 404 // |kDevice2| is inaccessible, so it is detached. |kDevice1| has been |
375 // re-attached at |kMountPointB|, so it is 'detached' from kMountPointA. | 405 // attached at |kMountPointB|, but is still accessible from |kMountPointA|. |
376 // kDevice1 -> kMountPointA | 406 // kDevice1 -> kMountPointA * |
Lei Zhang
2012/08/28 07:55:30
When I first wrote the test, I thought we came to
vandebo (ex-Chrome)
2012/08/28 18:59:30
But if we've already notified consumers of system
| |
377 // kDevice2 -> kMountPointB | 407 // kDevice2 -> kMountPointB |
378 // kDevice1 -> kMountPointB | 408 // kDevice1 -> kMountPointB |
379 MtabTestData test_data2[] = { | 409 MtabTestData test_data2[] = { |
380 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | 410 MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
381 }; | 411 }; |
382 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); | 412 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
383 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(2); | 413 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); |
384 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); | 414 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); |
385 | 415 |
386 // Attach |kDevice2| to |kMountPointA|. | 416 // Detach |kDevice1| from |kMountPointA|, causing a detach and attach event. |
387 // kDevice1 -> kMountPointA | |
388 // kDevice2 -> kMountPointB | 417 // kDevice2 -> kMountPointB |
389 // kDevice1 -> kMountPointB | 418 // kDevice1 -> kMountPointB * |
390 // kDevice2 -> kMountPointA | |
391 MtabTestData test_data3[] = { | 419 MtabTestData test_data3[] = { |
392 MtabTestData(kDevice2, test_path_a.value(), kValidFS), | |
393 }; | |
394 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); | |
395 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | |
396 AppendToMtabAndRunLoop(test_data3, arraysize(test_data3)); | |
397 | |
398 // Detach |kDevice2| from |kMountPointA|. | |
399 // kDevice1 -> kMountPointA | |
400 // kDevice2 -> kMountPointB | |
401 // kDevice1 -> kMountPointB | |
402 MtabTestData test_data4[] = { | |
403 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | |
404 MtabTestData(kDevice2, test_path_b.value(), kValidFS), | 420 MtabTestData(kDevice2, test_path_b.value(), kValidFS), |
405 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | 421 MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
406 }; | 422 }; |
423 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); | |
424 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | |
425 OverwriteMtabAndRunLoop(test_data3, arraysize(test_data3)); | |
426 | |
427 // Attach |kDevice1| to |kMountPointA|. | |
428 // kDevice2 -> kMountPointB | |
429 // kDevice1 -> kMountPointB * | |
430 // kDevice1 -> kMountPointA | |
431 MtabTestData test_data4[] = { | |
432 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | |
433 }; | |
407 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 434 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
408 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | 435 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); |
409 OverwriteMtabAndRunLoop(test_data4, arraysize(test_data4)); | 436 AppendToMtabAndRunLoop(test_data4, arraysize(test_data4)); |
410 | 437 |
411 // Detach |kDevice1| from |kMountPointB|. | 438 // Detach |kDevice1| from |kMountPointB|. |
412 // kDevice1 -> kMountPointA | 439 // kDevice1 -> kMountPointA * |
413 // kDevice2 -> kMountPointB | 440 // kDevice2 -> kMountPointB * |
414 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(2); | 441 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(2); |
415 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | 442 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); |
416 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); | 443 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); |
417 | 444 |
418 // Detach all devices. | 445 // Detach all devices. |
419 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 446 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
420 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(2); | 447 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(2); |
421 WriteEmptyMtabAndRunLoop(); | 448 WriteEmptyMtabAndRunLoop(); |
422 } | 449 } |
423 | 450 |
424 // More complicated test case with multiple devices on one mount point. | 451 TEST_F(RemovableDeviceNotificationLinuxTest, |
425 TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesOneMountPoint) { | 452 MultipleMountPointsWithNonDCIMDevices) { |
426 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 453 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
427 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); | 454 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
428 ASSERT_FALSE(test_path_a.empty()); | 455 ASSERT_FALSE(test_path_a.empty()); |
429 ASSERT_FALSE(test_path_b.empty()); | 456 ASSERT_FALSE(test_path_b.empty()); |
430 | 457 |
431 // |kDevice1| is most recently mounted at |kMountPointB|. | 458 // Attach to one first. |
459 // kDevice1 -> kMountPointA * | |
460 MtabTestData test_data1[] = { | |
461 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | |
462 }; | |
463 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); | |
464 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | |
465 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); | |
466 | |
467 // Attach |kDevice1| to |kMountPointB|. | |
468 // kDevice1 -> kMountPointA * | |
469 // kDevice1 -> kMountPointB | |
470 MtabTestData test_data2[] = { | |
471 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | |
472 }; | |
473 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
474 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | |
475 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); | |
476 | |
477 // Attach |kDevice4| (a non-DCIM device) to |kMountPointA|. | |
432 // kDevice1 -> kMountPointA | 478 // kDevice1 -> kMountPointA |
433 // kDevice2 -> kMountPointB | 479 // kDevice1 -> kMountPointB * |
480 // kDevice4 -> kMountPointA | |
481 MtabTestData test_data3[] = { | |
482 MtabTestData(kDevice4, test_path_a.value(), kValidFS), | |
483 }; | |
484 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); | |
485 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | |
486 file_util::Delete(test_path_a.Append("DCIM"), false); | |
487 AppendToMtabAndRunLoop(test_data3, arraysize(test_data3)); | |
488 | |
489 // Detach |kDevice4|. | |
490 // kDevice1 -> kMountPointA | |
491 // kDevice1 -> kMountPointB * | |
492 MtabTestData test_data4[] = { | |
493 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | |
494 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | |
495 }; | |
496 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
497 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | |
498 OverwriteMtabAndRunLoop(test_data4, arraysize(test_data4)); | |
499 | |
500 // Detach |kDevice1| from |kMountPointA|. | |
501 // kDevice1 -> kMountPointB * | |
502 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
503 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | |
504 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); | |
505 | |
506 // Detach all devices. | |
507 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
508 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | |
509 WriteEmptyMtabAndRunLoop(); | |
510 } | |
511 | |
512 TEST_F(RemovableDeviceNotificationLinuxTest, MountLookUp) { | |
513 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | |
514 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); | |
515 FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); | |
516 ASSERT_FALSE(test_path_a.empty()); | |
517 ASSERT_FALSE(test_path_b.empty()); | |
518 ASSERT_FALSE(test_path_c.empty()); | |
519 | |
520 // Attach to one first. | |
521 // kDevice1 -> kMountPointA * | |
522 // kDevice4 -> kMountPointB | |
523 // kDevice5 -> kMountPointC | |
524 MtabTestData test_data1[] = { | |
525 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | |
526 MtabTestData(kDevice4, test_path_b.value(), kValidFS), | |
527 MtabTestData(kDevice5, test_path_c.value(), kValidFS), | |
528 }; | |
529 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); | |
530 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | |
531 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); | |
532 | |
533 EXPECT_EQ(test_path_a, | |
534 notifier()->GetDeviceMountPoint(GetDeviceId(kDevice1))); | |
535 EXPECT_EQ(test_path_b, | |
536 notifier()->GetDeviceMountPoint(GetDeviceId(kDevice4))); | |
537 EXPECT_EQ(test_path_c, | |
538 notifier()->GetDeviceMountPoint(GetDeviceId(kDevice5))); | |
539 EXPECT_EQ(FilePath(), | |
540 notifier()->GetDeviceMountPoint(GetDeviceId(kInvalidDevice))); | |
541 | |
542 // Make |kDevice1| mounted in multiple places. | |
543 // kDevice1 -> kMountPointA * | |
434 // kDevice1 -> kMountPointB | 544 // kDevice1 -> kMountPointB |
545 // kDevice1 -> kMountPointC | |
546 MtabTestData test_data2[] = { | |
547 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | |
548 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | |
549 MtabTestData(kDevice1, test_path_c.value(), kValidFS), | |
550 }; | |
551 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
552 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | |
553 // Add DCIM dirs. | |
554 CreateMountPointWithDCIMDir(kMountPointB); | |
555 CreateMountPointWithDCIMDir(kMountPointC); | |
556 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); | |
557 | |
558 EXPECT_EQ(test_path_a, | |
559 notifier()->GetDeviceMountPoint(GetDeviceId(kDevice1))); | |
560 | |
561 // Unmount |kDevice1| from |kMountPointA|. | |
562 // kDevice1 -> kMountPointB * | |
563 // kDevice1 -> kMountPointC | |
564 // Either |kMountPointB| or |kMountPointC| is a valid new default, but | |
565 // it turns out that it will be B. | |
566 MtabTestData test_data3[] = { | |
567 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | |
568 }; | |
569 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); | |
570 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | |
571 OverwriteMtabAndRunLoop(test_data3, arraysize(test_data3)); | |
572 | |
573 EXPECT_EQ(test_path_b, | |
574 notifier()->GetDeviceMountPoint(GetDeviceId(kDevice1))); | |
575 | |
576 // Mount a non-removable device in multiple places. | |
577 // kDevice5 -> kMountPointA | |
578 // kDevice5 -> kMountPointB | |
579 // kDevice5 -> kMountPointC | |
580 MtabTestData test_data4[] = { | |
581 MtabTestData(kDevice5, test_path_a.value(), kValidFS), | |
582 MtabTestData(kDevice5, test_path_b.value(), kValidFS), | |
583 MtabTestData(kDevice5, test_path_c.value(), kValidFS), | |
584 }; | |
585 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
586 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | |
587 // Remove DCIM dirs. | |
588 file_util::Delete(test_path_a.Append("DCIM"), false); | |
Lei Zhang
2012/08/28 07:55:30
DCIM should be a constant.
vandebo (ex-Chrome)
2012/08/28 18:59:30
Done.
| |
589 file_util::Delete(test_path_b.Append("DCIM"), false); | |
590 file_util::Delete(test_path_c.Append("DCIM"), false); | |
591 OverwriteMtabAndRunLoop(test_data4, arraysize(test_data4)); | |
592 | |
593 // Any of the mount points would be valid. | |
594 EXPECT_EQ(test_path_a.value(), | |
595 notifier()->GetDeviceMountPoint(GetDeviceId(kDevice5)).value()); | |
596 } | |
597 | |
598 TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) { | |
599 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | |
600 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); | |
601 FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); | |
602 ASSERT_FALSE(test_path_a.empty()); | |
603 ASSERT_FALSE(test_path_b.empty()); | |
604 ASSERT_FALSE(test_path_c.empty()); | |
605 | |
606 // Attach to one first. | |
607 // kDevice1 -> kMountPointA * | |
608 // kDevice4 -> kMountPointB | |
609 // kDevice5 -> kMountPointC | |
435 MtabTestData test_data1[] = { | 610 MtabTestData test_data1[] = { |
436 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | 611 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
437 MtabTestData(kDevice2, test_path_b.value(), kValidFS), | 612 MtabTestData(kDevice4, test_path_b.value(), kValidFS), |
438 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | 613 MtabTestData(kDevice5, test_path_c.value(), kValidFS), |
439 }; | 614 }; |
440 EXPECT_CALL(observer(), | 615 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); |
441 OnRemovableStorageAttached(GetDCIMDeviceId(kDeviceId1), | 616 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); |
442 ASCIIToUTF16(kDeviceLabel1), | 617 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
443 test_path_b.value())) | 618 |
444 .Times(1); | 619 FilePath relative_path; |
445 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | 620 EXPECT_EQ(GetDeviceId(kDevice1), |
446 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); | 621 notifier()->GetDeviceIdForPath(test_path_a, &relative_path)); |
447 | 622 EXPECT_EQ(FilePath().value(), relative_path.value()); |
Lei Zhang
2012/08/28 07:55:30
I think you can just compare FilePaths directly.
vandebo (ex-Chrome)
2012/08/28 18:59:30
Nope, it compares the pointer values instead.
| |
448 // Attach |kDevice3| to |kMountPointB|. | 623 EXPECT_EQ(GetDeviceId(kDevice4), |
449 // |kDevice1| is inaccessible at its most recent mount point, so it is | 624 notifier()->GetDeviceIdForPath(test_path_b, &relative_path)); |
450 // detached and unavailable, even though it is still accessible via | 625 EXPECT_EQ(FilePath().value(), relative_path.value()); |
451 // |kMountPointA|. | 626 EXPECT_EQ(GetDeviceId(kDevice5), |
452 // kDevice1 -> kMountPointA | 627 notifier()->GetDeviceIdForPath(test_path_c, NULL)); |
453 // kDevice2 -> kMountPointB | 628 |
454 // kDevice1 -> kMountPointB | 629 // An invalid path. |
455 // kDevice3 -> kMountPointB | 630 EXPECT_EQ(std::string(), |
631 notifier()->GetDeviceIdForPath(FilePath(kInvalidPath), NULL)); | |
632 | |
633 // Test filling in of the relative path. | |
634 FilePath extra_path("some/other/path"); | |
635 EXPECT_EQ(GetDeviceId(kDevice1), | |
636 notifier()->GetDeviceIdForPath(test_path_a.Append(extra_path), | |
637 &relative_path)); | |
638 EXPECT_EQ(extra_path.value(), relative_path.value()); | |
639 | |
640 // One device attached at multiple points. | |
641 // kDevice1 -> kMountPointA * | |
642 // kDevice5 -> kMountPointB | |
643 // kDevice5 -> kMountPointC | |
456 MtabTestData test_data2[] = { | 644 MtabTestData test_data2[] = { |
457 MtabTestData(kDevice3, test_path_b.value(), kValidFS), | 645 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
458 }; | 646 MtabTestData(kDevice5, test_path_b.value(), kValidFS), |
459 EXPECT_CALL(observer(), | 647 MtabTestData(kDevice5, test_path_c.value(), kValidFS), |
460 OnRemovableStorageDetached(GetDCIMDeviceId(kDeviceId1))) | 648 }; |
461 .Times(1); | 649 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
462 EXPECT_CALL(observer(), | 650 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); |
463 OnRemovableStorageAttached(GetDCIMDeviceId(kDeviceId3), | |
464 ASCIIToUTF16(kDeviceLabel3), | |
465 test_path_b.value())) | |
466 .Times(1); | |
467 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); | 651 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); |
468 | 652 |
469 // Detach all devices. | 653 EXPECT_EQ(GetDeviceId(kDevice1), |
470 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 654 notifier()->GetDeviceIdForPath(test_path_a, NULL)); |
471 EXPECT_CALL(observer(), | 655 EXPECT_EQ(GetDeviceId(kDevice5), |
472 OnRemovableStorageDetached(GetDCIMDeviceId(kDeviceId3))) | 656 notifier()->GetDeviceIdForPath(test_path_b, NULL)); |
473 .Times(1); | 657 EXPECT_EQ(GetDeviceId(kDevice5), |
474 WriteEmptyMtabAndRunLoop(); | 658 notifier()->GetDeviceIdForPath(test_path_c, NULL)); |
475 } | 659 } |
476 | 660 |
477 } // namespace | 661 } // namespace |
478 | 662 |
479 } // namespace chrome | 663 } // namespace chrome |
OLD | NEW |