Chromium Code Reviews| Index: chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc |
| diff --git a/chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc b/chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc |
| index 753854c3cbbf43e561a97fd8cb44e0dc0c39596a..1d6a0d38c3a9427ec7407cc401afe5f870b2d303 100644 |
| --- a/chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc |
| +++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc |
| @@ -28,12 +28,27 @@ using content::BrowserThread; |
| using disks::DiskMountManager; |
| using testing::_; |
| +const char kDeviceNameWithManufacturerDetails[] = "110 KB (CompanyA, Z101)"; |
| const char kDevice1[] = "/dev/d1"; |
| -const char kDevice2[] = "/dev/disk/d2"; |
| const char kDevice1Name[] = "d1"; |
| +const char kDevice1NameWithSizeInfo[] = "110 KB d1"; |
| +const char kDevice1Size[] = "110 KB"; |
| +const char kDevice2[] = "/dev/disk/d2"; |
| const char kDevice2Name[] = "d2"; |
| +const char kDevice2NameWithSizeInfo[] = "19.8 GB d2"; |
| +const char kEmptyDeviceLabel[] = ""; |
| const char kMountPointA[] = "mnt_a"; |
| const char kMountPointB[] = "mnt_b"; |
| +const char kSDCardDeviceName1[] = "8.6 MB Amy_SD"; |
| +const char kSDCardDeviceName2[] = "8.6 MB SD Card"; |
| +const char kSDCardMountPoint1[] = "/media/removable/Amy_SD"; |
| +const char kSDCardMountPoint2[] = "/media/removable/SD Card"; |
| +const char kProductName[] = "Z101"; |
| +const char kVendorName[] = "CompanyA"; |
| + |
| +uint64 kDevice1SizeInBytes = 113048; |
| +uint64 kDevice2SizeInBytes = 21231209600; |
| +uint64 kSDCardSizeInBytes = 9000000; |
| std::string GetDCIMDeviceId(const std::string& unique_id) { |
| return chrome::MediaStorageUtil::MakeDeviceId( |
| @@ -41,6 +56,7 @@ std::string GetDCIMDeviceId(const std::string& unique_id) { |
| chrome::kFSUniqueIdPrefix + unique_id); |
| } |
| +// Wrapper class to test RemovableDeviceNotificationsCros. |
| class RemovableDeviceNotificationsCrosTest : public testing::Test { |
| public: |
| RemovableDeviceNotificationsCrosTest() |
| @@ -50,7 +66,7 @@ class RemovableDeviceNotificationsCrosTest : public testing::Test { |
| virtual ~RemovableDeviceNotificationsCrosTest() {} |
| protected: |
| - virtual void SetUp() { |
| + virtual void SetUp() OVERRIDE { |
| ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
| file_thread_.Start(); |
| @@ -67,7 +83,7 @@ class RemovableDeviceNotificationsCrosTest : public testing::Test { |
| notifications_ = new RemovableDeviceNotificationsCros(); |
| } |
| - virtual void TearDown() { |
| + virtual void TearDown() OVERRIDE { |
| notifications_ = NULL; |
| disk_mount_manager_mock_ = NULL; |
| DiskMountManager::Shutdown(); |
| @@ -83,10 +99,15 @@ class RemovableDeviceNotificationsCrosTest : public testing::Test { |
| void MountDevice(MountError error_code, |
| const DiskMountManager::MountPointInfo& mount_info, |
| const std::string& unique_id, |
| - const std::string& device_label) { |
| + const std::string& device_label, |
| + const std::string& vendor_name, |
| + const std::string& product_name, |
| + DeviceType device_type, |
| + uint64 device_size_in_bytes) { |
| if (error_code == MOUNT_ERROR_NONE) { |
| disk_mount_manager_mock_->CreateDiskEntryForMountDevice( |
| - mount_info, unique_id, device_label); |
| + mount_info, unique_id, device_label, vendor_name, product_name, |
| + device_type, device_size_in_bytes); |
| } |
| notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, |
| error_code, |
| @@ -106,12 +127,17 @@ class RemovableDeviceNotificationsCrosTest : public testing::Test { |
| WaitForFileThread(); |
| } |
| + string16 GetDeviceStorageSize(const std::string& device_location) { |
| + return notifications_->GetStorageSize(device_location); |
| + } |
| + |
| // Create a directory named |dir| relative to the test directory. |
| // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
| // subdirectory. |
| // Returns the full path to the created directory on success, or an empty |
| // path on failure. |
| - FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { |
| + FilePath CreateMountPoint(const std::string& dir, |
|
Lei Zhang
2012/11/12 07:46:56
unneeded change?
kmadhusu
2012/11/12 19:56:56
Reverted.
|
| + bool with_dcim_dir) { |
| FilePath return_path(scoped_temp_dir_.path()); |
| return_path = return_path.AppendASCII(dir); |
| FilePath path(return_path); |
| @@ -123,14 +149,12 @@ class RemovableDeviceNotificationsCrosTest : public testing::Test { |
| } |
| static void PostQuitToUIThread() { |
| - BrowserThread::PostTask(BrowserThread::UI, |
| - FROM_HERE, |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| MessageLoop::QuitClosure()); |
| } |
| static void WaitForFileThread() { |
| - BrowserThread::PostTask(BrowserThread::FILE, |
| - FROM_HERE, |
| + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| base::Bind(&PostQuitToUIThread)); |
| MessageLoop::current()->Run(); |
| } |
| @@ -167,10 +191,11 @@ TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { |
| const std::string kUniqueId0 = "FFFF-FFFF"; |
| EXPECT_CALL(observer(), |
| OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId0), |
| - ASCIIToUTF16(kDevice1Name), |
| + ASCIIToUTF16(kDevice1NameWithSizeInfo), |
| mount_path1.value())) |
| .InSequence(mock_sequence); |
| - MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kDevice1Name); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kDevice1Name, |
| + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| EXPECT_CALL(observer(), |
| OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) |
| @@ -187,10 +212,11 @@ TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { |
| EXPECT_CALL(observer(), |
| OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), |
| - ASCIIToUTF16(kDevice2Name), |
| + ASCIIToUTF16(kDevice2NameWithSizeInfo), |
| mount_path2.value())) |
| .InSequence(mock_sequence); |
| - MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId1, kDevice2Name); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId1, kDevice2Name, |
| + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice2SizeInBytes); |
| EXPECT_CALL(observer(), |
| OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) |
| @@ -212,9 +238,11 @@ TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { |
| chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, |
| chrome::kFSUniqueIdPrefix + kUniqueId); |
| EXPECT_CALL(observer(), |
| - OnRemovableStorageAttached(device_id, ASCIIToUTF16(kDevice1Name), |
| + OnRemovableStorageAttached(device_id, |
| + ASCIIToUTF16(kDevice1NameWithSizeInfo), |
| mount_path.value())).Times(1); |
| - MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| } |
| // Non device mounts and mount errors are ignored. |
| @@ -230,18 +258,113 @@ TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { |
| MOUNT_TYPE_DEVICE, |
| disks::MOUNT_CONDITION_NONE); |
| EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| - MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name); |
| + MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name, |
| + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| // Not a device |
| mount_info.mount_type = MOUNT_TYPE_ARCHIVE; |
| EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| - MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| // Unsupported file system. |
| mount_info.mount_type = MOUNT_TYPE_DEVICE; |
| mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
| EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| - MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| +} |
| + |
| +TEST_F(RemovableDeviceNotificationsCrosTest, SDCardAttachDetach) { |
| + testing::Sequence mock_sequence; |
| + FilePath mount_path1 = CreateMountPoint(kSDCardMountPoint1, true); |
| + ASSERT_FALSE(mount_path1.empty()); |
| + DiskMountManager::MountPointInfo mount_info1(kSDCardDeviceName1, |
| + mount_path1.value(), |
| + MOUNT_TYPE_DEVICE, |
| + disks::MOUNT_CONDITION_NONE); |
| + const std::string kUniqueId1 = "FFFF-FFFF"; |
| + EXPECT_CALL(observer(), |
| + OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), |
| + ASCIIToUTF16(kSDCardDeviceName1), |
| + mount_path1.value())) |
| + .InSequence(mock_sequence); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info1, kUniqueId1, kSDCardDeviceName1, |
| + kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); |
| + |
| + EXPECT_CALL(observer(), |
| + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) |
| + .InSequence(mock_sequence); |
| + UnmountDevice(MOUNT_ERROR_NONE, mount_info1); |
| + |
| + FilePath mount_path2 = CreateMountPoint(kSDCardMountPoint2, true); |
| + ASSERT_FALSE(mount_path2.empty()); |
| + DiskMountManager::MountPointInfo mount_info2(kSDCardDeviceName2, |
| + mount_path2.value(), |
| + MOUNT_TYPE_DEVICE, |
| + disks::MOUNT_CONDITION_NONE); |
| + const std::string kUniqueId2 = "F0FF-FFF0"; |
| + EXPECT_CALL(observer(), |
| + OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId2), |
| + ASCIIToUTF16(kSDCardDeviceName2), |
| + mount_path2.value())) |
| + .InSequence(mock_sequence); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kSDCardDeviceName2, |
| + kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); |
| + |
| + EXPECT_CALL(observer(), |
| + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) |
| + .InSequence(mock_sequence); |
| + UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
| +} |
| + |
| +TEST_F(RemovableDeviceNotificationsCrosTest, AttachDeviceWithEmptyLabel) { |
| + testing::Sequence mock_sequence; |
| + FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| + ASSERT_FALSE(mount_path1.empty()); |
| + DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, |
| + mount_path1.value(), |
| + MOUNT_TYPE_DEVICE, |
| + disks::MOUNT_CONDITION_NONE); |
| + const std::string kUniqueId0 = "FFFF-FFFF"; |
| + EXPECT_CALL(observer(), OnRemovableStorageAttached( |
| + GetDCIMDeviceId(kUniqueId0), |
| + ASCIIToUTF16(kDeviceNameWithManufacturerDetails), |
| + mount_path1.value())) |
| + .InSequence(mock_sequence); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kEmptyDeviceLabel, |
| + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| + |
| + EXPECT_CALL(observer(), |
| + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) |
| + .InSequence(mock_sequence); |
| + UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| +} |
| + |
| +TEST_F(RemovableDeviceNotificationsCrosTest, GetStorageSize) { |
| + testing::Sequence mock_sequence; |
| + FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| + ASSERT_FALSE(mount_path1.empty()); |
| + ASSERT_TRUE(GetDeviceStorageSize(mount_path1.value()).empty()); |
| + DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, |
| + mount_path1.value(), |
| + MOUNT_TYPE_DEVICE, |
| + disks::MOUNT_CONDITION_NONE); |
| + const std::string kUniqueId0 = "FFFF-FFFF"; |
| + EXPECT_CALL(observer(), OnRemovableStorageAttached( |
| + GetDCIMDeviceId(kUniqueId0), |
| + ASCIIToUTF16(kDeviceNameWithManufacturerDetails), |
| + mount_path1.value())) |
| + .InSequence(mock_sequence); |
| + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kEmptyDeviceLabel, |
| + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| + |
| + EXPECT_EQ(ASCIIToUTF16(kDevice1Size), |
| + GetDeviceStorageSize(mount_path1.value())); |
| + EXPECT_CALL(observer(), |
| + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) |
| + .InSequence(mock_sequence); |
| + UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| } |
| } // namespace |