| 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/storage_monitor/removable_device_notifications_linux.h" | 7 #include "chrome/browser/storage_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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 8773 }, | 62 8773 }, |
| 63 { kDeviceDCIM3, "VendorModelSerial:::WEM319X792", "TEST_USB_MODEL_3", | 63 { kDeviceDCIM3, "VendorModelSerial:::WEM319X792", "TEST_USB_MODEL_3", |
| 64 MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, 22837 }, | 64 MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, 22837 }, |
| 65 { kDeviceNoDCIM, "UUID:ABCD-1234", "TEST_USB_MODEL_4", | 65 { kDeviceNoDCIM, "UUID:ABCD-1234", "TEST_USB_MODEL_4", |
| 66 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, 512 }, | 66 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, 512 }, |
| 67 { kDeviceFixed, "UUID:743A-2349", "743A-2349", | 67 { kDeviceFixed, "UUID:743A-2349", "743A-2349", |
| 68 MediaStorageUtil::FIXED_MASS_STORAGE, 17282 }, | 68 MediaStorageUtil::FIXED_MASS_STORAGE, 17282 }, |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 void GetDeviceInfo(const base::FilePath& device_path, | 71 void GetDeviceInfo(const base::FilePath& device_path, |
| 72 std::string* id, | 72 const base::FilePath& mount_point, |
| 73 std::string* device_id, |
| 73 string16* name, | 74 string16* name, |
| 74 bool* removable, | 75 bool* removable, |
| 75 uint64* partition_size_in_bytes) { | 76 uint64* partition_size_in_bytes, |
| 77 string16* out_volume_label, |
| 78 string16* out_vendor_name, |
| 79 string16* out_model_name) { |
| 76 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { | 80 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { |
| 77 if (device_path.value() == kTestDeviceData[i].device_path) { | 81 if (device_path.value() == kTestDeviceData[i].device_path) { |
| 78 if (id) | |
| 79 *id = kTestDeviceData[i].unique_id; | |
| 80 if (name) | 82 if (name) |
| 81 *name = ASCIIToUTF16(kTestDeviceData[i].device_name); | 83 *name = ASCIIToUTF16(kTestDeviceData[i].device_name); |
| 84 MediaStorageUtil::Type type = kTestDeviceData[i].type; |
| 82 if (removable) { | 85 if (removable) { |
| 83 MediaStorageUtil::Type type = kTestDeviceData[i].type; | |
| 84 *removable = | 86 *removable = |
| 85 (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM) || | 87 (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM) || |
| 86 (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); | 88 (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 87 } | 89 } |
| 90 if (device_id) { |
| 91 *device_id = |
| 92 MediaStorageUtil::MakeDeviceId(type, kTestDeviceData[i].unique_id); |
| 93 } |
| 88 if (partition_size_in_bytes) | 94 if (partition_size_in_bytes) |
| 89 *partition_size_in_bytes = kTestDeviceData[i].partition_size_in_bytes; | 95 *partition_size_in_bytes = kTestDeviceData[i].partition_size_in_bytes; |
| 96 if (out_volume_label) |
| 97 *out_volume_label = ASCIIToUTF16("volume label"); |
| 98 if (out_vendor_name) |
| 99 *out_vendor_name = ASCIIToUTF16("vendor name"); |
| 100 if (out_model_name) |
| 101 *out_model_name = ASCIIToUTF16("model name"); |
| 90 return; | 102 return; |
| 91 } | 103 } |
| 92 } | 104 } |
| 93 NOTREACHED(); | 105 NOTREACHED(); |
| 94 } | 106 } |
| 95 | 107 |
| 96 uint64 GetDevicePartitionSize(const std::string& device) { | 108 uint64 GetDevicePartitionSize(const std::string& device) { |
| 97 for (size_t i = 0; i < arraysize(kTestDeviceData); ++i) { | 109 for (size_t i = 0; i < arraysize(kTestDeviceData); ++i) { |
| 98 if (device == kTestDeviceData[i].device_path) | 110 if (device == kTestDeviceData[i].device_path) |
| 99 return kTestDeviceData[i].partition_size_in_bytes; | 111 return kTestDeviceData[i].partition_size_in_bytes; |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 614 |
| 603 TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) { | 615 TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) { |
| 604 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 616 base::FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
| 605 base::FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); | 617 base::FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); |
| 606 base::FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); | 618 base::FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); |
| 607 ASSERT_FALSE(test_path_a.empty()); | 619 ASSERT_FALSE(test_path_a.empty()); |
| 608 ASSERT_FALSE(test_path_b.empty()); | 620 ASSERT_FALSE(test_path_b.empty()); |
| 609 ASSERT_FALSE(test_path_c.empty()); | 621 ASSERT_FALSE(test_path_c.empty()); |
| 610 | 622 |
| 611 // Attach to one first. | 623 // Attach to one first. |
| 612 // (*'d mounts are those RemovableStorageNotifications knows about.) | 624 // (starred mounts are those RemovableStorageNotifications knows about.) |
| 613 // kDeviceDCIM1 -> kMountPointA * | 625 // kDeviceDCIM1 -> kMountPointA * |
| 614 // kDeviceNoDCIM -> kMountPointB * | 626 // kDeviceNoDCIM -> kMountPointB * |
| 615 // kDeviceFixed -> kMountPointC | 627 // kDeviceFixed -> kMountPointC |
| 616 MtabTestData test_data1[] = { | 628 MtabTestData test_data1[] = { |
| 617 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS), | 629 MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS), |
| 618 MtabTestData(kDeviceNoDCIM, test_path_b.value(), kValidFS), | 630 MtabTestData(kDeviceNoDCIM, test_path_b.value(), kValidFS), |
| 619 MtabTestData(kDeviceFixed, test_path_c.value(), kValidFS), | 631 MtabTestData(kDeviceFixed, test_path_c.value(), kValidFS), |
| 620 }; | 632 }; |
| 621 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); | 633 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| 622 EXPECT_EQ(2, observer().attach_calls()); | 634 EXPECT_EQ(2, observer().attach_calls()); |
| 623 EXPECT_EQ(0, observer().detach_calls()); | 635 EXPECT_EQ(0, observer().detach_calls()); |
| 624 | 636 |
| 625 StorageMonitor::StorageInfo device_info; | 637 StorageMonitor::StorageInfo device_info; |
| 626 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_a, &device_info)); | 638 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_a, &device_info)); |
| 627 EXPECT_EQ(GetDeviceId(kDeviceDCIM1), device_info.device_id); | 639 EXPECT_EQ(GetDeviceId(kDeviceDCIM1), device_info.device_id); |
| 628 EXPECT_EQ(test_path_a.value(), device_info.location); | 640 EXPECT_EQ(test_path_a.value(), device_info.location); |
| 629 EXPECT_EQ(GetDeviceName(kDeviceDCIM1), device_info.name); | 641 EXPECT_EQ(GetDeviceName(kDeviceDCIM1), device_info.name); |
| 642 EXPECT_EQ(88788ULL, device_info.total_size_in_bytes); |
| 643 EXPECT_EQ(ASCIIToUTF16("volume label"), device_info.storage_label); |
| 644 EXPECT_EQ(ASCIIToUTF16("vendor name"), device_info.vendor_name); |
| 645 EXPECT_EQ(ASCIIToUTF16("model name"), device_info.model_name); |
| 630 | 646 |
| 631 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_b, &device_info)); | 647 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_b, &device_info)); |
| 632 EXPECT_EQ(GetDeviceId(kDeviceNoDCIM), device_info.device_id); | 648 EXPECT_EQ(GetDeviceId(kDeviceNoDCIM), device_info.device_id); |
| 633 EXPECT_EQ(test_path_b.value(), device_info.location); | 649 EXPECT_EQ(test_path_b.value(), device_info.location); |
| 634 EXPECT_EQ(GetDeviceName(kDeviceNoDCIM), device_info.name); | 650 EXPECT_EQ(GetDeviceName(kDeviceNoDCIM), device_info.name); |
| 635 | 651 |
| 636 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_c, &device_info)); | 652 EXPECT_TRUE(notifier()->GetStorageInfoForPath(test_path_c, &device_info)); |
| 637 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id); | 653 EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id); |
| 638 EXPECT_EQ(test_path_c.value(), device_info.location); | 654 EXPECT_EQ(test_path_c.value(), device_info.location); |
| 639 EXPECT_EQ(GetDeviceName(kDeviceFixed), device_info.name); | 655 EXPECT_EQ(GetDeviceName(kDeviceFixed), device_info.name); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 notifier()->GetStorageSize(test_path_a.value())); | 709 notifier()->GetStorageSize(test_path_a.value())); |
| 694 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), | 710 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), |
| 695 notifier()->GetStorageSize(test_path_b.value())); | 711 notifier()->GetStorageSize(test_path_b.value())); |
| 696 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), | 712 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), |
| 697 notifier()->GetStorageSize(kInvalidPath)); | 713 notifier()->GetStorageSize(kInvalidPath)); |
| 698 } | 714 } |
| 699 | 715 |
| 700 } // namespace | 716 } // namespace |
| 701 | 717 |
| 702 } // namespace chrome | 718 } // namespace chrome |
| OLD | NEW |