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

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_linux_unittest.cc

Issue 12382005: Rename RemovableDeviceNotifications=>StorageMonitor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix more indentation issues. Created 7 years, 9 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
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 // RemovableDeviceNotificationsLinux unit tests. 5 // StorageMonitorLinux unit tests.
6 6
7 #include "chrome/browser/storage_monitor/removable_device_notifications_linux.h" 7 #include "chrome/browser/storage_monitor/storage_monitor_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/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 string16 GetDeviceName(const std::string& device) { 129 string16 GetDeviceName(const std::string& device) {
130 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { 130 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) {
131 if (device == kTestDeviceData[i].device_path) 131 if (device == kTestDeviceData[i].device_path)
132 return ASCIIToUTF16(kTestDeviceData[i].device_name); 132 return ASCIIToUTF16(kTestDeviceData[i].device_name);
133 } 133 }
134 return string16(); 134 return string16();
135 } 135 }
136 136
137 class RemovableDeviceNotificationsLinuxTestWrapper 137 class TestStorageMonitorLinux : public StorageMonitorLinux {
138 : public RemovableDeviceNotificationsLinux {
139 public: 138 public:
140 RemovableDeviceNotificationsLinuxTestWrapper(const base::FilePath& path, 139 TestStorageMonitorLinux(const base::FilePath& path, MessageLoop* message_loop)
141 MessageLoop* message_loop) 140 : StorageMonitorLinux(path, &GetDeviceInfo),
142 : RemovableDeviceNotificationsLinux(path, &GetDeviceInfo),
143 message_loop_(message_loop) { 141 message_loop_(message_loop) {
144 } 142 }
145 143
146 private: 144 private:
147 // Avoids code deleting the object while there are references to it. 145 // Avoids code deleting the object while there are references to it.
148 // Aside from the base::RefCountedThreadSafe friend class, any attempts to 146 // Aside from the base::RefCountedThreadSafe friend class, any attempts to
149 // call this dtor will result in a compile-time error. 147 // call this dtor will result in a compile-time error.
150 virtual ~RemovableDeviceNotificationsLinuxTestWrapper() {} 148 virtual ~TestStorageMonitorLinux() {}
151 149
152 virtual void OnFilePathChanged(const base::FilePath& path, 150 virtual void OnFilePathChanged(const base::FilePath& path,
153 bool error) OVERRIDE { 151 bool error) OVERRIDE {
154 RemovableDeviceNotificationsLinux::OnFilePathChanged(path, error); 152 StorageMonitorLinux::OnFilePathChanged(path, error);
155 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 153 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure());
156 } 154 }
157 155
158 MessageLoop* message_loop_; 156 MessageLoop* message_loop_;
159 157
160 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinuxTestWrapper); 158 DISALLOW_COPY_AND_ASSIGN(TestStorageMonitorLinux);
161 }; 159 };
162 160
163 class RemovableDeviceNotificationLinuxTest : public testing::Test { 161 class StorageMonitorLinuxTest : public testing::Test {
164 public: 162 public:
165 struct MtabTestData { 163 struct MtabTestData {
166 MtabTestData(const std::string& mount_device, 164 MtabTestData(const std::string& mount_device,
167 const std::string& mount_point, 165 const std::string& mount_point,
168 const std::string& mount_type) 166 const std::string& mount_type)
169 : mount_device(mount_device), 167 : mount_device(mount_device),
170 mount_point(mount_point), 168 mount_point(mount_point),
171 mount_type(mount_type) { 169 mount_type(mount_type) {
172 } 170 }
173 171
174 const std::string mount_device; 172 const std::string mount_device;
175 const std::string mount_point; 173 const std::string mount_point;
176 const std::string mount_type; 174 const std::string mount_type;
177 }; 175 };
178 176
179 RemovableDeviceNotificationLinuxTest() 177 StorageMonitorLinuxTest()
180 : message_loop_(MessageLoop::TYPE_IO), 178 : message_loop_(MessageLoop::TYPE_IO),
181 file_thread_(content::BrowserThread::FILE, &message_loop_) { 179 file_thread_(content::BrowserThread::FILE, &message_loop_) {
182 } 180 }
183 virtual ~RemovableDeviceNotificationLinuxTest() {} 181 virtual ~StorageMonitorLinuxTest() {}
184 182
185 protected: 183 protected:
186 virtual void SetUp() OVERRIDE { 184 virtual void SetUp() OVERRIDE {
187 // Create and set up a temp dir with files for the test. 185 // Create and set up a temp dir with files for the test.
188 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); 186 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
189 base::FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc"); 187 base::FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc");
190 ASSERT_TRUE(file_util::CreateDirectory(test_dir)); 188 ASSERT_TRUE(file_util::CreateDirectory(test_dir));
191 mtab_file_ = test_dir.AppendASCII("test_mtab"); 189 mtab_file_ = test_dir.AppendASCII("test_mtab");
192 MtabTestData initial_test_data[] = { 190 MtabTestData initial_test_data[] = {
193 MtabTestData("dummydevice", "dummydir", kInvalidFS), 191 MtabTestData("dummydevice", "dummydir", kInvalidFS),
194 }; 192 };
195 WriteToMtab(initial_test_data, 193 WriteToMtab(initial_test_data,
196 arraysize(initial_test_data), 194 arraysize(initial_test_data),
197 true /* overwrite */); 195 true /* overwrite */);
198 196
199 // Initialize the test subject. 197 // Initialize the test subject.
200 notifications_ = new RemovableDeviceNotificationsLinuxTestWrapper( 198 monitor_ = new TestStorageMonitorLinux(mtab_file_, &message_loop_);
201 mtab_file_, &message_loop_);
202 mock_storage_observer_.reset(new MockRemovableStorageObserver); 199 mock_storage_observer_.reset(new MockRemovableStorageObserver);
203 notifications_->AddObserver(mock_storage_observer_.get()); 200 monitor_->AddObserver(mock_storage_observer_.get());
204 201
205 notifications_->Init(); 202 monitor_->Init();
206 message_loop_.RunUntilIdle(); 203 message_loop_.RunUntilIdle();
207 } 204 }
208 205
209 virtual void TearDown() OVERRIDE { 206 virtual void TearDown() OVERRIDE {
210 message_loop_.RunUntilIdle(); 207 message_loop_.RunUntilIdle();
211 notifications_->RemoveObserver(mock_storage_observer_.get()); 208 monitor_->RemoveObserver(mock_storage_observer_.get());
212 notifications_ = NULL; 209 monitor_ = NULL;
213 } 210 }
214 211
215 // Append mtab entries from the |data| array of size |data_size| to the mtab 212 // Append mtab entries from the |data| array of size |data_size| to the mtab
216 // file, and run the message loop. 213 // file, and run the message loop.
217 void AppendToMtabAndRunLoop(const MtabTestData* data, size_t data_size) { 214 void AppendToMtabAndRunLoop(const MtabTestData* data, size_t data_size) {
218 WriteToMtab(data, data_size, false /* do not overwrite */); 215 WriteToMtab(data, data_size, false /* do not overwrite */);
219 message_loop_.Run(); 216 message_loop_.Run();
220 } 217 }
221 218
222 // Overwrite the mtab file with mtab entries from the |data| array of size 219 // Overwrite the mtab file with mtab entries from the |data| array of size
223 // |data_size|, and run the message loop. 220 // |data_size|, and run the message loop.
224 void OverwriteMtabAndRunLoop(const MtabTestData* data, size_t data_size) { 221 void OverwriteMtabAndRunLoop(const MtabTestData* data, size_t data_size) {
225 WriteToMtab(data, data_size, true /* overwrite */); 222 WriteToMtab(data, data_size, true /* overwrite */);
226 message_loop_.Run(); 223 message_loop_.Run();
227 } 224 }
228 225
229 // Simplied version of OverwriteMtabAndRunLoop() that just deletes all the 226 // Simplied version of OverwriteMtabAndRunLoop() that just deletes all the
230 // entries in the mtab file. 227 // entries in the mtab file.
231 void WriteEmptyMtabAndRunLoop() { 228 void WriteEmptyMtabAndRunLoop() {
232 OverwriteMtabAndRunLoop(NULL, // No data. 229 OverwriteMtabAndRunLoop(NULL, // No data.
233 0); // No data length. 230 0); // No data length.
234 } 231 }
235 232
236 // Create a directory named |dir| relative to the test directory. 233 // Create a directory named |dir| relative to the test directory.
237 // It has a DCIM directory, so RemovableDeviceNotificationsLinux recognizes it 234 // It has a DCIM directory, so StorageMonitorLinux recognizes it
238 // as a media directory. 235 // as a media directory.
vandebo (ex-Chrome) 2013/03/02 00:23:37 nit: line wrap.
239 base::FilePath CreateMountPointWithDCIMDir(const std::string& dir) { 236 base::FilePath CreateMountPointWithDCIMDir(const std::string& dir) {
240 return CreateMountPoint(dir, true /* create DCIM dir */); 237 return CreateMountPoint(dir, true /* create DCIM dir */);
241 } 238 }
242 239
243 // Create a directory named |dir| relative to the test directory. 240 // Create a directory named |dir| relative to the test directory.
244 // It does not have a DCIM directory, so RemovableDeviceNotificationsLinux 241 // It does not have a DCIM directory, so StorageMonitorLinux
245 // does not recognizes it as a media directory. 242 // does not recognizes it as a media directory.
vandebo (ex-Chrome) 2013/03/02 00:23:37 nit: line wrap.
246 base::FilePath CreateMountPointWithoutDCIMDir(const std::string& dir) { 243 base::FilePath CreateMountPointWithoutDCIMDir(const std::string& dir) {
247 return CreateMountPoint(dir, false /* do not create DCIM dir */); 244 return CreateMountPoint(dir, false /* do not create DCIM dir */);
248 } 245 }
249 246
250 void RemoveDCIMDirFromMountPoint(const std::string& dir) { 247 void RemoveDCIMDirFromMountPoint(const std::string& dir) {
251 base::FilePath dcim = 248 base::FilePath dcim =
252 scoped_temp_dir_.path().AppendASCII(dir).Append(kDCIMDirectoryName); 249 scoped_temp_dir_.path().AppendASCII(dir).Append(kDCIMDirectoryName);
253 file_util::Delete(dcim, false); 250 file_util::Delete(dcim, false);
254 } 251 }
255 252
256 MockRemovableStorageObserver& observer() { 253 MockRemovableStorageObserver& observer() {
257 return *mock_storage_observer_; 254 return *mock_storage_observer_;
258 } 255 }
259 256
260 RemovableDeviceNotificationsLinux* notifier() { 257 StorageMonitorLinux* notifier() {
261 return notifications_.get(); 258 return monitor_.get();
262 } 259 }
263 260
264 private: 261 private:
265 // Create a directory named |dir| relative to the test directory. 262 // Create a directory named |dir| relative to the test directory.
266 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" 263 // Set |with_dcim_dir| to true if the created directory will have a "DCIM"
267 // subdirectory. 264 // subdirectory.
268 // Returns the full path to the created directory on success, or an empty 265 // Returns the full path to the created directory on success, or an empty
269 // path on failure. 266 // path on failure.
270 base::FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { 267 base::FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) {
271 base::FilePath return_path(scoped_temp_dir_.path()); 268 base::FilePath return_path(scoped_temp_dir_.path());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 MessageLoop message_loop_; 312 MessageLoop message_loop_;
316 content::TestBrowserThread file_thread_; 313 content::TestBrowserThread file_thread_;
317 314
318 scoped_ptr<MockRemovableStorageObserver> mock_storage_observer_; 315 scoped_ptr<MockRemovableStorageObserver> mock_storage_observer_;
319 316
320 // Temporary directory for created test data. 317 // Temporary directory for created test data.
321 base::ScopedTempDir scoped_temp_dir_; 318 base::ScopedTempDir scoped_temp_dir_;
322 // Path to the test mtab file. 319 // Path to the test mtab file.
323 base::FilePath mtab_file_; 320 base::FilePath mtab_file_;
324 321
325 scoped_refptr<RemovableDeviceNotificationsLinuxTestWrapper> notifications_; 322 scoped_refptr<TestStorageMonitorLinux> monitor_;
326 323
327 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationLinuxTest); 324 DISALLOW_COPY_AND_ASSIGN(StorageMonitorLinuxTest);
328 }; 325 };
329 326
330 // Simple test case where we attach and detach a media device. 327 // Simple test case where we attach and detach a media device.
331 TEST_F(RemovableDeviceNotificationLinuxTest, BasicAttachDetach) { 328 TEST_F(StorageMonitorLinuxTest, BasicAttachDetach) {
332 base::FilePath test_path = CreateMountPointWithDCIMDir(kMountPointA); 329 base::FilePath test_path = CreateMountPointWithDCIMDir(kMountPointA);
333 ASSERT_FALSE(test_path.empty()); 330 ASSERT_FALSE(test_path.empty());
334 MtabTestData test_data[] = { 331 MtabTestData test_data[] = {
335 MtabTestData(kDeviceDCIM2, test_path.value(), kValidFS), 332 MtabTestData(kDeviceDCIM2, test_path.value(), kValidFS),
336 MtabTestData(kDeviceFixed, kInvalidPath, kValidFS), 333 MtabTestData(kDeviceFixed, kInvalidPath, kValidFS),
337 }; 334 };
338 // Only |kDeviceDCIM2| should be attached, since |kDeviceFixed| has a bad 335 // Only |kDeviceDCIM2| should be attached, since |kDeviceFixed| has a bad
339 // path. 336 // path.
340 AppendToMtabAndRunLoop(test_data, arraysize(test_data)); 337 AppendToMtabAndRunLoop(test_data, arraysize(test_data));
341 338
342 EXPECT_EQ(1, observer().attach_calls()); 339 EXPECT_EQ(1, observer().attach_calls());
343 EXPECT_EQ(0, observer().detach_calls()); 340 EXPECT_EQ(0, observer().detach_calls());
344 EXPECT_EQ(GetDeviceId(kDeviceDCIM2), observer().last_attached().device_id); 341 EXPECT_EQ(GetDeviceId(kDeviceDCIM2), observer().last_attached().device_id);
345 EXPECT_EQ(GetDeviceNameWithSizeDetails(kDeviceDCIM2), 342 EXPECT_EQ(GetDeviceNameWithSizeDetails(kDeviceDCIM2),
346 observer().last_attached().name); 343 observer().last_attached().name);
347 EXPECT_EQ(test_path.value(), 344 EXPECT_EQ(test_path.value(),
348 observer().last_attached().location); 345 observer().last_attached().location);
349 346
350 // |kDeviceDCIM2| should be detached here. 347 // |kDeviceDCIM2| should be detached here.
351 WriteEmptyMtabAndRunLoop(); 348 WriteEmptyMtabAndRunLoop();
352 EXPECT_EQ(1, observer().attach_calls()); 349 EXPECT_EQ(1, observer().attach_calls());
353 EXPECT_EQ(1, observer().detach_calls()); 350 EXPECT_EQ(1, observer().detach_calls());
354 EXPECT_EQ(GetDeviceId(kDeviceDCIM2), observer().last_detached().device_id); 351 EXPECT_EQ(GetDeviceId(kDeviceDCIM2), observer().last_detached().device_id);
355 } 352 }
356 353
357 // Only removable devices are recognized. 354 // Only removable devices are recognized.
358 TEST_F(RemovableDeviceNotificationLinuxTest, Removable) { 355 TEST_F(StorageMonitorLinuxTest, Removable) {
359 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); 356 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA);
360 ASSERT_FALSE(test_path_a.empty()); 357 ASSERT_FALSE(test_path_a.empty());
361 MtabTestData test_data1[] = { 358 MtabTestData test_data1[] = {
362 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS), 359 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS),
363 }; 360 };
364 // |kDeviceDCIM1| should be attached as expected. 361 // |kDeviceDCIM1| should be attached as expected.
365 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); 362 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1));
366 363
367 EXPECT_EQ(1, observer().attach_calls()); 364 EXPECT_EQ(1, observer().attach_calls());
368 EXPECT_EQ(0, observer().detach_calls()); 365 EXPECT_EQ(0, observer().detach_calls());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 observer().last_attached().location); 399 observer().last_attached().location);
403 400
404 // |kDeviceNoDCIM| should be detached as expected. 401 // |kDeviceNoDCIM| should be detached as expected.
405 WriteEmptyMtabAndRunLoop(); 402 WriteEmptyMtabAndRunLoop();
406 EXPECT_EQ(2, observer().attach_calls()); 403 EXPECT_EQ(2, observer().attach_calls());
407 EXPECT_EQ(2, observer().detach_calls()); 404 EXPECT_EQ(2, observer().detach_calls());
408 EXPECT_EQ(GetDeviceId(kDeviceNoDCIM), observer().last_detached().device_id); 405 EXPECT_EQ(GetDeviceId(kDeviceNoDCIM), observer().last_detached().device_id);
409 } 406 }
410 407
411 // More complicated test case with multiple devices on multiple mount points. 408 // More complicated test case with multiple devices on multiple mount points.
412 TEST_F(RemovableDeviceNotificationLinuxTest, SwapMountPoints) { 409 TEST_F(StorageMonitorLinuxTest, SwapMountPoints) {
413 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); 410 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA);
414 base::FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); 411 base::FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB);
415 ASSERT_FALSE(test_path_a.empty()); 412 ASSERT_FALSE(test_path_a.empty());
416 ASSERT_FALSE(test_path_b.empty()); 413 ASSERT_FALSE(test_path_b.empty());
417 414
418 // Attach two devices. 415 // Attach two devices.
419 // (*'d mounts are those RemovableStorageNotifications knows about.) 416 // (*'d mounts are those RemovableStorageNotifications knows about.)
420 // kDeviceDCIM1 -> kMountPointA * 417 // kDeviceDCIM1 -> kMountPointA *
421 // kDeviceDCIM2 -> kMountPointB * 418 // kDeviceDCIM2 -> kMountPointB *
422 MtabTestData test_data1[] = { 419 MtabTestData test_data1[] = {
(...skipping 16 matching lines...) Expand all
439 EXPECT_EQ(4, observer().attach_calls()); 436 EXPECT_EQ(4, observer().attach_calls());
440 EXPECT_EQ(2, observer().detach_calls()); 437 EXPECT_EQ(2, observer().detach_calls());
441 438
442 // Detach all devices. 439 // Detach all devices.
443 WriteEmptyMtabAndRunLoop(); 440 WriteEmptyMtabAndRunLoop();
444 EXPECT_EQ(4, observer().attach_calls()); 441 EXPECT_EQ(4, observer().attach_calls());
445 EXPECT_EQ(4, observer().detach_calls()); 442 EXPECT_EQ(4, observer().detach_calls());
446 } 443 }
447 444
448 // More complicated test case with multiple devices on multiple mount points. 445 // More complicated test case with multiple devices on multiple mount points.
449 TEST_F(RemovableDeviceNotificationLinuxTest, MultiDevicesMultiMountPoints) { 446 TEST_F(StorageMonitorLinuxTest, MultiDevicesMultiMountPoints) {
450 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); 447 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA);
451 base::FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); 448 base::FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB);
452 ASSERT_FALSE(test_path_a.empty()); 449 ASSERT_FALSE(test_path_a.empty());
453 ASSERT_FALSE(test_path_b.empty()); 450 ASSERT_FALSE(test_path_b.empty());
454 451
455 // Attach two devices. 452 // Attach two devices.
456 // (*'d mounts are those RemovableStorageNotifications knows about.) 453 // (*'d mounts are those RemovableStorageNotifications knows about.)
457 // kDeviceDCIM1 -> kMountPointA * 454 // kDeviceDCIM1 -> kMountPointA *
458 // kDeviceDCIM2 -> kMountPointB * 455 // kDeviceDCIM2 -> kMountPointB *
459 MtabTestData test_data1[] = { 456 MtabTestData test_data1[] = {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); 503 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1));
507 EXPECT_EQ(5, observer().attach_calls()); 504 EXPECT_EQ(5, observer().attach_calls());
508 EXPECT_EQ(3, observer().detach_calls()); 505 EXPECT_EQ(3, observer().detach_calls());
509 506
510 // Detach all devices. 507 // Detach all devices.
511 WriteEmptyMtabAndRunLoop(); 508 WriteEmptyMtabAndRunLoop();
512 EXPECT_EQ(5, observer().attach_calls()); 509 EXPECT_EQ(5, observer().attach_calls());
513 EXPECT_EQ(5, observer().detach_calls()); 510 EXPECT_EQ(5, observer().detach_calls());
514 } 511 }
515 512
516 TEST_F(RemovableDeviceNotificationLinuxTest, 513 TEST_F(StorageMonitorLinuxTest, MultipleMountPointsWithNonDCIMDevices) {
517 MultipleMountPointsWithNonDCIMDevices) {
518 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); 514 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA);
519 base::FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); 515 base::FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB);
520 ASSERT_FALSE(test_path_a.empty()); 516 ASSERT_FALSE(test_path_a.empty());
521 ASSERT_FALSE(test_path_b.empty()); 517 ASSERT_FALSE(test_path_b.empty());
522 518
523 // Attach to one first. 519 // Attach to one first.
524 // (*'d mounts are those RemovableStorageNotifications knows about.) 520 // (*'d mounts are those RemovableStorageNotifications knows about.)
525 // kDeviceDCIM1 -> kMountPointA * 521 // kDeviceDCIM1 -> kMountPointA *
526 MtabTestData test_data1[] = { 522 MtabTestData test_data1[] = {
527 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS), 523 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); 589 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1));
594 EXPECT_EQ(4, observer().attach_calls()); 590 EXPECT_EQ(4, observer().attach_calls());
595 EXPECT_EQ(3, observer().detach_calls()); 591 EXPECT_EQ(3, observer().detach_calls());
596 592
597 // Detach all devices. 593 // Detach all devices.
598 WriteEmptyMtabAndRunLoop(); 594 WriteEmptyMtabAndRunLoop();
599 EXPECT_EQ(4, observer().attach_calls()); 595 EXPECT_EQ(4, observer().attach_calls());
600 EXPECT_EQ(4, observer().detach_calls()); 596 EXPECT_EQ(4, observer().detach_calls());
601 } 597 }
602 598
603 TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) { 599 TEST_F(StorageMonitorLinuxTest, DeviceLookUp) {
604 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); 600 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA);
605 base::FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); 601 base::FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB);
606 base::FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); 602 base::FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC);
607 ASSERT_FALSE(test_path_a.empty()); 603 ASSERT_FALSE(test_path_a.empty());
608 ASSERT_FALSE(test_path_b.empty()); 604 ASSERT_FALSE(test_path_b.empty());
609 ASSERT_FALSE(test_path_c.empty()); 605 ASSERT_FALSE(test_path_c.empty());
610 606
611 // Attach to one first. 607 // Attach to one first.
612 // (*'d mounts are those RemovableStorageNotifications knows about.) 608 // (*'d mounts are those RemovableStorageNotifications knows about.)
613 // kDeviceDCIM1 -> kMountPointA * 609 // kDeviceDCIM1 -> kMountPointA *
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_b, &device_info)); 663 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_b, &device_info));
668 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id); 664 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id);
669 665
670 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_c, &device_info)); 666 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_c, &device_info));
671 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id); 667 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id);
672 668
673 EXPECT_EQ(2, observer().attach_calls()); 669 EXPECT_EQ(2, observer().attach_calls());
674 EXPECT_EQ(1, observer().detach_calls()); 670 EXPECT_EQ(1, observer().detach_calls());
675 } 671 }
676 672
677 TEST_F(RemovableDeviceNotificationLinuxTest, DevicePartitionSize) { 673 TEST_F(StorageMonitorLinuxTest, DevicePartitionSize) {
678 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); 674 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA);
679 base::FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); 675 base::FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB);
680 ASSERT_FALSE(test_path_a.empty()); 676 ASSERT_FALSE(test_path_a.empty());
681 ASSERT_FALSE(test_path_b.empty()); 677 ASSERT_FALSE(test_path_b.empty());
682 678
683 MtabTestData test_data1[] = { 679 MtabTestData test_data1[] = {
684 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS), 680 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS),
685 MtabTestData(kDeviceNoDCIM, test_path_b.value(), kValidFS), 681 MtabTestData(kDeviceNoDCIM, test_path_b.value(), kValidFS),
686 MtabTestData(kDeviceFixed, kInvalidPath, kInvalidFS), 682 MtabTestData(kDeviceFixed, kInvalidPath, kInvalidFS),
687 }; 683 };
688 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); 684 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1));
689 EXPECT_EQ(2, observer().attach_calls()); 685 EXPECT_EQ(2, observer().attach_calls());
690 EXPECT_EQ(0, observer().detach_calls()); 686 EXPECT_EQ(0, observer().detach_calls());
691 687
692 EXPECT_EQ(GetDevicePartitionSize(kDeviceDCIM1), 688 EXPECT_EQ(GetDevicePartitionSize(kDeviceDCIM1),
693 notifier()->GetStorageSize(test_path_a.value())); 689 notifier()->GetStorageSize(test_path_a.value()));
694 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), 690 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM),
695 notifier()->GetStorageSize(test_path_b.value())); 691 notifier()->GetStorageSize(test_path_b.value()));
696 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), 692 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath),
697 notifier()->GetStorageSize(kInvalidPath)); 693 notifier()->GetStorageSize(kInvalidPath));
698 } 694 }
699 695
700 } // namespace 696 } // namespace
701 697
702 } // namespace chrome 698 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698