| Index: chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc
|
| diff --git a/chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc b/chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc
|
| index fc1b8379ab4d931cb0b314774cc01eec3f0b2a20..8d773f7eece7cb34b932678b7a4d8e1bdf502d38 100644
|
| --- a/chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc
|
| +++ b/chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc
|
| @@ -22,6 +22,7 @@
|
| #include "chrome/browser/system_monitor/media_storage_util.h"
|
| #include "content/public/test/test_browser_thread.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/base/text/bytes_formatting.h"
|
|
|
| namespace chrome {
|
|
|
| @@ -53,23 +54,27 @@ struct TestDeviceData {
|
| const char* unique_id;
|
| const char* device_name;
|
| MediaStorageUtil::Type type;
|
| + uint64 device_storage_size_in_bytes;
|
| };
|
|
|
| const TestDeviceData kTestDeviceData[] = {
|
| {kDeviceDCIM1, "UUID:FFF0-000F", "TEST_USB_MODEL_1",
|
| - MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM},
|
| + MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, 88997788},
|
| {kDeviceDCIM2, "VendorModelSerial:ComName:Model2010:8989", "TEST_USB_MODEL_2",
|
| - MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM},
|
| + MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, 8773},
|
| {kDeviceDCIM3, "VendorModelSerial:::WEM319X792", "TEST_USB_MODEL_3",
|
| - MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM},
|
| + MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, 22377892837},
|
| {kDeviceNoDCIM, "UUID:ABCD-1234", "TEST_USB_MODEL_4",
|
| - MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM},
|
| - {kDeviceFixed, "UUID:743A91FD2349", "TEST_USB_MODEL_5",
|
| - MediaStorageUtil::FIXED_MASS_STORAGE},
|
| + MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, 512},
|
| + {kDeviceFixed, "UUID:743A-2349", "743A-2349",
|
| + MediaStorageUtil::FIXED_MASS_STORAGE, 172892},
|
| };
|
|
|
| -void GetDeviceInfo(const FilePath& device_path, std::string* id,
|
| - string16* name, bool* removable) {
|
| +void GetDeviceInfo(const FilePath& device_path,
|
| + std::string* id,
|
| + string16* name,
|
| + bool* removable,
|
| + string16* device_size) {
|
| for (size_t i = 0; i < arraysize(kTestDeviceData); i++) {
|
| if (device_path.value() == kTestDeviceData[i].device_path) {
|
| if (id)
|
| @@ -82,6 +87,10 @@ void GetDeviceInfo(const FilePath& device_path, std::string* id,
|
| (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM) ||
|
| (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM);
|
| }
|
| + if (device_size) {
|
| + *device_size = ui::FormatBytes(
|
| + kTestDeviceData[i].device_storage_size_in_bytes);
|
| + }
|
| return;
|
| }
|
| }
|
| @@ -101,6 +110,17 @@ std::string GetDeviceId(const std::string& device) {
|
| }
|
| return std::string();
|
| }
|
| +
|
| +string16 GetDeviceNameWithSizeDetails(const std::string& device) {
|
| + for (size_t i = 0; i < arraysize(kTestDeviceData); i++) {
|
| + if (device == kTestDeviceData[i].device_path) {
|
| + return ui::FormatBytes(kTestDeviceData[i].device_storage_size_in_bytes) +
|
| + ASCIIToUTF16(std::string(" ") + kTestDeviceData[i].device_name);
|
| + }
|
| + }
|
| + return string16();
|
| +}
|
| +
|
| string16 GetDeviceName(const std::string& device) {
|
| for (size_t i = 0; i < arraysize(kTestDeviceData); i++) {
|
| if (device == kTestDeviceData[i].device_path)
|
| @@ -109,6 +129,14 @@ string16 GetDeviceName(const std::string& device) {
|
| return string16();
|
| }
|
|
|
| +string16 GetDeviceStorageSize(const std::string& device) {
|
| + for (size_t i = 0; i < arraysize(kTestDeviceData); i++) {
|
| + if (device == kTestDeviceData[i].device_path)
|
| + return ui::FormatBytes(kTestDeviceData[i].device_storage_size_in_bytes);
|
| + }
|
| + return string16();
|
| +}
|
| +
|
| class RemovableDeviceNotificationsLinuxTestWrapper
|
| : public RemovableDeviceNotificationsLinux {
|
| public:
|
| @@ -316,9 +344,10 @@ TEST_F(RemovableDeviceNotificationLinuxTest, BasicAttachDetach) {
|
| // Only |kDeviceDCIM2| should be attached, since |kDeviceFixed| has a bad
|
| // path.
|
| EXPECT_CALL(observer(),
|
| - OnRemovableStorageAttached(GetDeviceId(kDeviceDCIM2),
|
| - GetDeviceName(kDeviceDCIM2),
|
| - test_path.value()))
|
| + OnRemovableStorageAttached(
|
| + GetDeviceId(kDeviceDCIM2),
|
| + GetDeviceNameWithSizeDetails(kDeviceDCIM2),
|
| + test_path.value()))
|
| .InSequence(mock_sequence);
|
| AppendToMtabAndRunLoop(test_data, arraysize(test_data));
|
|
|
| @@ -338,9 +367,10 @@ TEST_F(RemovableDeviceNotificationLinuxTest, Removable) {
|
| };
|
| // |kDeviceDCIM1| should be attached as expected.
|
| EXPECT_CALL(observer(),
|
| - OnRemovableStorageAttached(GetDeviceId(kDeviceDCIM1),
|
| - GetDeviceName(kDeviceDCIM1),
|
| - test_path_a.value()))
|
| + OnRemovableStorageAttached(
|
| + GetDeviceId(kDeviceDCIM1),
|
| + GetDeviceNameWithSizeDetails(kDeviceDCIM1),
|
| + test_path_a.value()))
|
| .InSequence(mock_sequence);
|
| AppendToMtabAndRunLoop(test_data1, arraysize(test_data1));
|
|
|
| @@ -359,9 +389,10 @@ TEST_F(RemovableDeviceNotificationLinuxTest, Removable) {
|
|
|
| // |kDeviceNoDCIM| should be attached as expected.
|
| EXPECT_CALL(observer(),
|
| - OnRemovableStorageAttached(GetDeviceId(kDeviceNoDCIM),
|
| - GetDeviceName(kDeviceNoDCIM),
|
| - test_path_b.value()))
|
| + OnRemovableStorageAttached(
|
| + GetDeviceId(kDeviceNoDCIM),
|
| + GetDeviceNameWithSizeDetails(kDeviceNoDCIM),
|
| + test_path_b.value()))
|
| .InSequence(mock_sequence);
|
| MtabTestData test_data3[] = {
|
| MtabTestData(kDeviceNoDCIM, test_path_b.value(), kValidFS),
|
| @@ -634,6 +665,29 @@ TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) {
|
| EXPECT_EQ(GetDeviceId(kDeviceFixed), device_info.device_id);
|
| }
|
|
|
| +TEST_F(RemovableDeviceNotificationLinuxTest, DeviceStorageSizeInfo) {
|
| + FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA);
|
| + FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB);
|
| + ASSERT_FALSE(test_path_a.empty());
|
| + ASSERT_FALSE(test_path_b.empty());
|
| +
|
| + MtabTestData test_data1[] = {
|
| + MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS),
|
| + MtabTestData(kDeviceNoDCIM, test_path_b.value(), kValidFS),
|
| + MtabTestData(kDeviceFixed, kInvalidPath, kInvalidFS),
|
| + };
|
| + EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(2);
|
| + EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0);
|
| + AppendToMtabAndRunLoop(test_data1, arraysize(test_data1));
|
| +
|
| + EXPECT_EQ(GetDeviceStorageSize(kDeviceDCIM1),
|
| + notifier()->GetStorageSize(test_path_a.value()));
|
| + EXPECT_EQ(GetDeviceStorageSize(kDeviceNoDCIM),
|
| + notifier()->GetStorageSize(test_path_b.value()));
|
| + EXPECT_EQ(string16(),
|
| + notifier()->GetStorageSize(kInvalidPath));
|
| +}
|
| +
|
| } // namespace
|
|
|
| } // namespace chrome
|
|
|