diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 05:27:43 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 05:27:43 +0000 |
commit | 3f005c228392762826a6ab1aaafe6dd31d31518d (patch) | |
tree | 38a84dbd97389cd2bf47912feb9df3358976afe7 /chrome | |
parent | 643d544c3d07c78eef785ff5741ad5be54b99b6c (diff) | |
download | chromium_src-3f005c228392762826a6ab1aaafe6dd31d31518d.zip chromium_src-3f005c228392762826a6ab1aaafe6dd31d31518d.tar.gz chromium_src-3f005c228392762826a6ab1aaafe6dd31d31518d.tar.bz2 |
[Media Gallery][ChromeOS] Improve device media gallery names.
(1) When a SD card is attached, report a more generic string like "SD card" on the media permissions dialog.
(2) When the attached device is not a SD card or when a sub folder of the device is selected as a media gallery, report the gallery name in the following format:
<Device_storage_size> <Selected_sub_folder_gallery_name> <Volume_Name> <(Vendor_Name, Model_Name)>
Sample gallery names:
(1) 1GB TEST_USB
(2) 4GB DCIM - RED_USB
(3) 8KB PHOTOS - (TESTCOMPANY, A101)
(4) 4GB SD Card
(5) 16MB SD Card
BUG=159671,158600
TEST=none
Review URL: https://chromiumcodereview.appspot.com/11366144
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167606 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
6 files changed, 259 insertions, 68 deletions
diff --git a/chrome/browser/system_monitor/media_device_notifications_utils.cc b/chrome/browser/system_monitor/media_device_notifications_utils.cc index 4054c2d..79f3c0a 100644 --- a/chrome/browser/system_monitor/media_device_notifications_utils.cc +++ b/chrome/browser/system_monitor/media_device_notifications_utils.cc @@ -6,8 +6,10 @@ #include "base/file_util.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/system_monitor/removable_device_constants.h" #include "content/public/browser/browser_thread.h" +#include "ui/base/text/bytes_formatting.h" namespace chrome { @@ -25,4 +27,27 @@ bool IsMediaDevice(const FilePath::StringType& mount_point) { return true; } +string16 GetFullProductName(const std::string& vendor_name, + const std::string& model_name) { + if (vendor_name.empty() && model_name.empty()) + return string16(); + + std::string product_name; + if (vendor_name.empty()) + product_name = model_name; + else if (model_name.empty()) + product_name = vendor_name; + else + product_name = vendor_name + ", " + model_name; + return IsStringUTF8(product_name) ? + UTF8ToUTF16("(" + product_name + ")") : string16(); +} + +string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes, + const string16& name) { + DCHECK(!name.empty()); + return (storage_size_in_bytes == 0) ? + name : ui::FormatBytes(storage_size_in_bytes) + ASCIIToUTF16(" ") + name; +} + } // namespace chrome diff --git a/chrome/browser/system_monitor/media_device_notifications_utils.h b/chrome/browser/system_monitor/media_device_notifications_utils.h index 46980b1..23c1a90 100644 --- a/chrome/browser/system_monitor/media_device_notifications_utils.h +++ b/chrome/browser/system_monitor/media_device_notifications_utils.h @@ -8,6 +8,7 @@ #define CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_DEVICE_NOTIFICATIONS_UTILS_H_ #include "base/file_path.h" +#include "base/string16.h" namespace chrome { @@ -18,6 +19,15 @@ namespace chrome { // TODO(vandebo) Try to figure out how Mac OS X decides this. bool IsMediaDevice(const FilePath::StringType& mount_point); +// Constructs the device product name from |vendor_name| and |model_name|. +string16 GetFullProductName(const std::string& vendor_name, + const std::string& model_name); + +// Constructs the display name for device from |storage_size_in_bytes| and +// |name|. +string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes, + const string16& name); + } // namespace chrome #endif // CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_DEVICE_NOTIFICATIONS_UTILS_H_ diff --git a/chrome/browser/system_monitor/media_storage_util.cc b/chrome/browser/system_monitor/media_storage_util.cc index e7f39cd..1344d806 100644 --- a/chrome/browser/system_monitor/media_storage_util.cc +++ b/chrome/browser/system_monitor/media_storage_util.cc @@ -14,6 +14,7 @@ #include "base/metrics/histogram.h" #include "base/system_monitor/system_monitor.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/system_monitor/media_device_notifications_utils.h" #include "content/public/browser/browser_thread.h" #if defined(OS_CHROMEOS) @@ -256,20 +257,29 @@ bool MediaStorageUtil::GetDeviceInfoFromPath(const FilePath& path, if (found_device && IsRemovableDevice(device_info.device_id)) { if (device_id) *device_id = device_info.device_id; - if (device_name) + + FilePath sub_folder_path; + if (device_name || relative_path) { + bool success = FilePath(device_info.location) + .AppendRelativePath(path, &sub_folder_path); + DCHECK(success); + } + + if (device_name) { +#if defined(OS_CHROMEOS) + *device_name = GetDisplayNameForDevice( + notifier->GetStorageSize(device_info.location), + sub_folder_path.value().empty() ? + device_info.name : + sub_folder_path.BaseName().LossyDisplayName() + + ASCIIToUTF16(" - ") + device_info.name); +#else *device_name = device_info.name; - if (relative_path) { - *relative_path = FilePath(); - FilePath mount_point(device_info.location); - bool success = mount_point.AppendRelativePath(path, relative_path); -#if defined(OS_POSIX) - if (!relative_path->value().empty() && device_name) { - *device_name += ASCIIToUTF16(" (") + - relative_path->BaseName().LossyDisplayName() + ASCIIToUTF16(")"); - } #endif - DCHECK(success); } + + if (relative_path) + *relative_path = sub_folder_path; return true; } diff --git a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc index c8b90e9..6b06fb1 100644 --- a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc +++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc @@ -10,6 +10,7 @@ #include "base/logging.h" #include "base/stl_util.h" #include "base/string_number_conversions.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/system_monitor/media_device_notifications_utils.h" #include "chrome/browser/system_monitor/media_storage_util.h" @@ -22,23 +23,27 @@ using base::SystemMonitor; namespace { -// Construct a device name using label or manufacturer (vendor and product) name -// details. +// Constructs a device name using label or manufacturer (vendor and product) +// name details. string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { - std::string device_name = disk.device_label(); - if (device_name.empty()) { - device_name = disk.vendor_name(); - const std::string& product_name = disk.product_name(); - if (!product_name.empty()) { - if (!device_name.empty()) - device_name += " "; - device_name += product_name; - } + if (disk.device_type() == DEVICE_TYPE_SD) { + // Mount path of an SD card will be one of the following: + // (1) /media/removable/<volume_label> + // (2) /media/removable/SD Card + // If the volume label is available, mount path will be (1) else (2). + FilePath mount_point(disk.mount_path()); + const string16 display_name(mount_point.BaseName().LossyDisplayName()); + if (!display_name.empty()) + return display_name; } - return UTF8ToUTF16(device_name); + + const std::string& device_label = disk.device_label(); + if (!device_label.empty() && IsStringUTF8(device_label)) + return UTF8ToUTF16(device_label); + return chrome::GetFullProductName(disk.vendor_name(), disk.product_name()); } -// Construct a device id using uuid or manufacturer (vendor and product) id +// Constructs a device id using uuid or manufacturer (vendor and product) id // details. std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) { std::string uuid = disk.fs_uuid(); @@ -61,10 +66,11 @@ static RemovableDeviceNotificationsCros* g_removable_device_notifications_chromeos = NULL; // Returns true if the requested device is valid, else false. On success, fills -// in |unique_id| and |device_label| -bool GetDeviceInfo(const std::string& source_path, std::string* unique_id, - string16* device_label) { - // Get the media device uuid and label if exists. +// in |unique_id|, |device_label| and |storage_size_in_bytes|. +bool GetDeviceInfo(const std::string& source_path, + std::string* unique_id, + string16* device_label, + uint64* storage_size_in_bytes) { const disks::DiskMountManager::Disk* disk = disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path); if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN) @@ -75,12 +81,14 @@ bool GetDeviceInfo(const std::string& source_path, std::string* unique_id, if (device_label) *device_label = GetDeviceName(*disk); + + if (storage_size_in_bytes) + *storage_size_in_bytes = disk->total_size_in_bytes(); return true; } } // namespace -using chrome::MediaStorageUtil; using content::BrowserThread; RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { @@ -164,7 +172,7 @@ void RemovableDeviceNotificationsCros::MountCompleted( if (it == mount_map_.end()) return; SystemMonitor::Get()->ProcessRemovableStorageDetached( - it->second.device_id); + it->second.storage_info.device_id); mount_map_.erase(it); break; } @@ -188,10 +196,17 @@ bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath( return false; if (device_info) - *device_info = info_it->second; + *device_info = info_it->second.storage_info; return true; } +uint64 RemovableDeviceNotificationsCros::GetStorageSize( + const std::string& device_location) const { + MountMap::const_iterator info_it = mount_map_.find(device_location); + return (info_it != mount_map_.end()) ? + info_it->second.storage_size_in_bytes : 0; +} + void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread( const disks::DiskMountManager::MountPointInfo& mount_info) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); @@ -218,28 +233,34 @@ void RemovableDeviceNotificationsCros::AddMountedPathOnUIThread( // Get the media device uuid and label if exists. std::string unique_id; string16 device_label; - if (!GetDeviceInfo(mount_info.source_path, &unique_id, &device_label)) + uint64 storage_size_in_bytes; + if (!GetDeviceInfo(mount_info.source_path, &unique_id, &device_label, + &storage_size_in_bytes)) return; // Keep track of device uuid and label, to see how often we receive empty // values. - MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, device_label); + chrome::MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, + device_label); if (unique_id.empty() || device_label.empty()) return; - MediaStorageUtil::Type type = has_dcim ? - MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : - MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; + chrome::MediaStorageUtil::Type type = has_dcim ? + chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : + chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, unique_id); - SystemMonitor::RemovableStorageInfo info(device_id, device_label, - mount_info.mount_path); - mount_map_.insert(std::make_pair(mount_info.mount_path, info)); + StorageObjectInfo object_info = { + base::SystemMonitor::RemovableStorageInfo(device_id, device_label, + mount_info.mount_path), + storage_size_in_bytes + }; + mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); SystemMonitor::Get()->ProcessRemovableStorageAttached( device_id, - device_label, + chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), mount_info.mount_path); } -} // namespace chrome +} // namespace chromeos diff --git a/chrome/browser/system_monitor/removable_device_notifications_chromeos.h b/chrome/browser/system_monitor/removable_device_notifications_chromeos.h index a767e85..9f6d716 100644 --- a/chrome/browser/system_monitor/removable_device_notifications_chromeos.h +++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos.h @@ -60,12 +60,23 @@ class RemovableDeviceNotificationsCros const FilePath& path, base::SystemMonitor::RemovableStorageInfo* device_info) const; + // Returns the storage size of the device present at |location|. If the + // device information is unavailable, returns zero. + uint64 GetStorageSize(const std::string& location) const; + private: + struct StorageObjectInfo { + // Basic details {storage device name, location and identifier}. + base::SystemMonitor::RemovableStorageInfo storage_info; + + // Device storage size. + uint64 storage_size_in_bytes; + }; + friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>; // Mapping of mount path to removable mass storage info. - typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> - MountMap; + typedef std::map<std::string, StorageObjectInfo> MountMap; // Private to avoid code deleting the object. virtual ~RemovableDeviceNotificationsCros(); 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 29abf36..eb1e50b 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,28 @@ 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 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 kUniqueId1[] = "FFFF-FFFF"; +const char kUniqueId2[] = "FFFF-FF0F"; +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 +57,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 +67,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 +84,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 +100,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,6 +128,10 @@ class RemovableDeviceNotificationsCrosTest : public testing::Test { WaitForFileThread(); } + uint64 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. @@ -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(); } @@ -164,16 +188,16 @@ TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { mount_path1.value(), MOUNT_TYPE_DEVICE, disks::MOUNT_CONDITION_NONE); - const std::string kUniqueId0 = "FFFF-FFFF"; EXPECT_CALL(observer(), - OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId0), - ASCIIToUTF16(kDevice1Name), + OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), + ASCIIToUTF16(kDevice1NameWithSizeInfo), mount_path1.value())) .InSequence(mock_sequence); - MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kDevice1Name); + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kDevice1Name, + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); EXPECT_CALL(observer(), - OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) .InSequence(mock_sequence); UnmountDevice(MOUNT_ERROR_NONE, mount_info); @@ -183,17 +207,16 @@ TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { mount_path2.value(), MOUNT_TYPE_DEVICE, disks::MOUNT_CONDITION_NONE); - const std::string kUniqueId1 = "FFF0-FFF0"; - EXPECT_CALL(observer(), - OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), - ASCIIToUTF16(kDevice2Name), + OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId2), + ASCIIToUTF16(kDevice2NameWithSizeInfo), mount_path2.value())) .InSequence(mock_sequence); - MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId1, kDevice2Name); + MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kDevice2Name, + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice2SizeInBytes); EXPECT_CALL(observer(), - OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) .InSequence(mock_sequence); UnmountDevice(MOUNT_ERROR_NONE, mount_info2); } @@ -212,9 +235,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 +255,107 @@ 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); + EXPECT_CALL(observer(), + OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId2), + ASCIIToUTF16(kSDCardDeviceName1), + mount_path1.value())) + .InSequence(mock_sequence); + MountDevice(MOUNT_ERROR_NONE, mount_info1, kUniqueId2, kSDCardDeviceName1, + kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); + + EXPECT_CALL(observer(), + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) + .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); + 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); + EXPECT_CALL(observer(), OnRemovableStorageAttached( + GetDCIMDeviceId(kUniqueId1), + ASCIIToUTF16(kDeviceNameWithManufacturerDetails), + mount_path1.value())) + .InSequence(mock_sequence); + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kEmptyDeviceLabel, + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); + + EXPECT_CALL(observer(), + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) + .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()); + DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, + mount_path1.value(), + MOUNT_TYPE_DEVICE, + disks::MOUNT_CONDITION_NONE); + EXPECT_CALL(observer(), OnRemovableStorageAttached( + GetDCIMDeviceId(kUniqueId1), + ASCIIToUTF16(kDeviceNameWithManufacturerDetails), + mount_path1.value())) + .InSequence(mock_sequence); + MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kEmptyDeviceLabel, + kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); + + EXPECT_EQ(kDevice1SizeInBytes, GetDeviceStorageSize(mount_path1.value())); + EXPECT_CALL(observer(), + OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) + .InSequence(mock_sequence); + UnmountDevice(MOUNT_ERROR_NONE, mount_info); } } // namespace |