| 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 // RemovableDeviceNotificationsLinux unit tests. | 5 // RemovableDeviceNotificationsLinux unit tests. |
| 6 | 6 |
| 7 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" | 7 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" |
| 8 | 8 |
| 9 #include <mntent.h> | 9 #include <mntent.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 557 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| 558 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | 558 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); |
| 559 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); | 559 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| 560 | 560 |
| 561 // Detach all devices. | 561 // Detach all devices. |
| 562 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 562 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| 563 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | 563 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); |
| 564 WriteEmptyMtabAndRunLoop(); | 564 WriteEmptyMtabAndRunLoop(); |
| 565 } | 565 } |
| 566 | 566 |
| 567 TEST_F(RemovableDeviceNotificationLinuxTest, MountLookUp) { | |
| 568 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | |
| 569 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); | |
| 570 FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); | |
| 571 ASSERT_FALSE(test_path_a.empty()); | |
| 572 ASSERT_FALSE(test_path_b.empty()); | |
| 573 ASSERT_FALSE(test_path_c.empty()); | |
| 574 | |
| 575 // Attach to one first. (*'d mounts are those SystemMonitor knows about.) | |
| 576 // kDeviceDCIM1 -> kMountPointA * | |
| 577 // kDeviceNoDCIM -> kMountPointB * | |
| 578 // kDeviceFixed -> kMountPointC | |
| 579 MtabTestData test_data1[] = { | |
| 580 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS), | |
| 581 MtabTestData(kDeviceNoDCIM, test_path_b.value(), kValidFS), | |
| 582 MtabTestData(kDeviceFixed, test_path_c.value(), kValidFS), | |
| 583 }; | |
| 584 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(2); | |
| 585 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); | |
| 586 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); | |
| 587 | |
| 588 EXPECT_EQ(test_path_a, | |
| 589 notifier()->GetDeviceMountPoint(GetDeviceId(kDeviceDCIM1))); | |
| 590 EXPECT_EQ(test_path_b, | |
| 591 notifier()->GetDeviceMountPoint(GetDeviceId(kDeviceNoDCIM))); | |
| 592 EXPECT_EQ(test_path_c, | |
| 593 notifier()->GetDeviceMountPoint(GetDeviceId(kDeviceFixed))); | |
| 594 EXPECT_EQ(FilePath(), | |
| 595 notifier()->GetDeviceMountPoint(GetDeviceId(kInvalidDevice))); | |
| 596 | |
| 597 // Make |kDeviceDCIM1| mounted in multiple places. | |
| 598 // kDeviceDCIM1 -> kMountPointA * | |
| 599 // kDeviceDCIM1 -> kMountPointB | |
| 600 // kDeviceDCIM1 -> kMountPointC | |
| 601 MtabTestData test_data2[] = { | |
| 602 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS), | |
| 603 MtabTestData(kDeviceDCIM1, test_path_b.value(), kValidFS), | |
| 604 MtabTestData(kDeviceDCIM1, test_path_c.value(), kValidFS), | |
| 605 }; | |
| 606 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
| 607 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | |
| 608 // Add DCIM dirs. | |
| 609 CreateMountPointWithDCIMDir(kMountPointB); | |
| 610 CreateMountPointWithDCIMDir(kMountPointC); | |
| 611 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); | |
| 612 | |
| 613 EXPECT_EQ(test_path_a, | |
| 614 notifier()->GetDeviceMountPoint(GetDeviceId(kDeviceDCIM1))); | |
| 615 | |
| 616 // Unmount |kDeviceDCIM1| from |kMountPointA|. | |
| 617 // kDeviceDCIM1 -> kMountPointB * | |
| 618 // kDeviceDCIM1 -> kMountPointC | |
| 619 // Either |kMountPointB| or |kMountPointC| is a valid new default, but | |
| 620 // it turns out that it will be B. | |
| 621 MtabTestData test_data3[] = { | |
| 622 MtabTestData(kDeviceDCIM1, test_path_b.value(), kValidFS), | |
| 623 }; | |
| 624 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(1); | |
| 625 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | |
| 626 OverwriteMtabAndRunLoop(test_data3, arraysize(test_data3)); | |
| 627 | |
| 628 EXPECT_EQ(test_path_b, | |
| 629 notifier()->GetDeviceMountPoint(GetDeviceId(kDeviceDCIM1))); | |
| 630 | |
| 631 // Mount a non-removable device in multiple places. | |
| 632 // kDeviceFixed -> kMountPointA | |
| 633 // kDeviceFixed -> kMountPointB | |
| 634 // kDeviceFixed -> kMountPointC | |
| 635 MtabTestData test_data4[] = { | |
| 636 MtabTestData(kDeviceFixed, test_path_a.value(), kValidFS), | |
| 637 MtabTestData(kDeviceFixed, test_path_b.value(), kValidFS), | |
| 638 MtabTestData(kDeviceFixed, test_path_c.value(), kValidFS), | |
| 639 }; | |
| 640 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
| 641 EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(1); | |
| 642 // Remove DCIM dirs. | |
| 643 RemoveDCIMDirFromMountPoint(kMountPointA); | |
| 644 RemoveDCIMDirFromMountPoint(kMountPointB); | |
| 645 RemoveDCIMDirFromMountPoint(kMountPointC); | |
| 646 OverwriteMtabAndRunLoop(test_data4, arraysize(test_data4)); | |
| 647 | |
| 648 // Any of the mount points would be valid. | |
| 649 EXPECT_EQ(test_path_a.value(), | |
| 650 notifier()->GetDeviceMountPoint(GetDeviceId(kDeviceFixed)).value()); | |
| 651 } | |
| 652 | |
| 653 TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) { | 567 TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) { |
| 654 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 568 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
| 655 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); | 569 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); |
| 656 FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); | 570 FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); |
| 657 ASSERT_FALSE(test_path_a.empty()); | 571 ASSERT_FALSE(test_path_a.empty()); |
| 658 ASSERT_FALSE(test_path_b.empty()); | 572 ASSERT_FALSE(test_path_b.empty()); |
| 659 ASSERT_FALSE(test_path_c.empty()); | 573 ASSERT_FALSE(test_path_c.empty()); |
| 660 | 574 |
| 661 // Attach to one first. (*'d mounts are those SystemMonitor knows about.) | 575 // Attach to one first. (*'d mounts are those SystemMonitor knows about.) |
| 662 // kDeviceDCIM1 -> kMountPointA * | 576 // kDeviceDCIM1 -> kMountPointA * |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 EXPECT_TRUE(notifier()->GetDeviceInfoForPath(test_path_b, &device_info)); | 630 EXPECT_TRUE(notifier()->GetDeviceInfoForPath(test_path_b, &device_info)); |
| 717 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id); | 631 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id); |
| 718 | 632 |
| 719 EXPECT_TRUE(notifier()->GetDeviceInfoForPath(test_path_c, &device_info)); | 633 EXPECT_TRUE(notifier()->GetDeviceInfoForPath(test_path_c, &device_info)); |
| 720 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id); | 634 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id); |
| 721 } | 635 } |
| 722 | 636 |
| 723 } // namespace | 637 } // namespace |
| 724 | 638 |
| 725 } // namespace chrome | 639 } // namespace chrome |
| OLD | NEW |