| 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..faace311826a4126127bce6c13449dba89fbd64c 100644 | 
| --- a/chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc | 
| +++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc | 
| @@ -31,9 +31,21 @@ using testing::_; | 
| 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 kDevice2Name[] = "d2"; | 
| +const char kDevice2NameWithSizeInfo[] = "19.8 GB d2"; | 
| +const char kEmptyDeviceLabel[] = ""; | 
| const char kMountPointA[] = "mnt_a"; | 
| const char kMountPointB[] = "mnt_b"; | 
| +const char kProductName[] = "Z101"; | 
| +const char kSDCardDeviceName[] = "8.6 MB SD Card"; | 
| +const char kVendorName[] = "CompanyA"; | 
| +const char kDeviceNameWithManufacturerDetails[] = "110 KB {CompanyA, Z101}"; | 
| + | 
| +uint64 kDevice1SizeInBytes = 113048; | 
| +uint64 kDevice2SizeInBytes = 21231209600; | 
| +uint64 kSDCardSizeInBytes = 9000000; | 
|  | 
| std::string GetDCIMDeviceId(const std::string& unique_id) { | 
| return chrome::MediaStorageUtil::MakeDeviceId( | 
| @@ -41,98 +53,41 @@ std::string GetDCIMDeviceId(const std::string& unique_id) { | 
| chrome::kFSUniqueIdPrefix + unique_id); | 
| } | 
|  | 
| +// Wrapper class to test RemovableDeviceNotificationsCros. | 
| class RemovableDeviceNotificationsCrosTest : public testing::Test { | 
| public: | 
| -  RemovableDeviceNotificationsCrosTest() | 
| -      : ui_thread_(BrowserThread::UI, &ui_loop_), | 
| -        file_thread_(BrowserThread::FILE) { | 
| -  } | 
| -  virtual ~RemovableDeviceNotificationsCrosTest() {} | 
| +  RemovableDeviceNotificationsCrosTest(); | 
| +  virtual ~RemovableDeviceNotificationsCrosTest(); | 
|  | 
| protected: | 
| -  virtual void SetUp() { | 
| -    ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| -    ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 
| -    file_thread_.Start(); | 
| - | 
| -    mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | 
| -    system_monitor_.AddDevicesChangedObserver( | 
| -        mock_devices_changed_observer_.get()); | 
| - | 
| -    disk_mount_manager_mock_ = new disks::MockDiskMountManager(); | 
| -    DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | 
| -    disk_mount_manager_mock_->SetupDefaultReplies(); | 
| - | 
| -    // Initialize the test subject. | 
| -    notifications_ = new RemovableDeviceNotificationsCros(); | 
| -  } | 
| - | 
| -  virtual void TearDown() { | 
| -    notifications_ = NULL; | 
| -    disk_mount_manager_mock_ = NULL; | 
| -    DiskMountManager::Shutdown(); | 
| -    system_monitor_.RemoveDevicesChangedObserver( | 
| -        mock_devices_changed_observer_.get()); | 
| -    WaitForFileThread(); | 
| -  } | 
| - | 
| -  base::MockDevicesChangedObserver& observer() { | 
| -    return *mock_devices_changed_observer_; | 
| -  } | 
| +  // testing::Test: | 
| +  virtual void SetUp() OVERRIDE; | 
| +  virtual void TearDown() OVERRIDE; | 
|  | 
| void MountDevice(MountError error_code, | 
| const DiskMountManager::MountPointInfo& mount_info, | 
| const std::string& unique_id, | 
| -                   const std::string& device_label) { | 
| -    if (error_code == MOUNT_ERROR_NONE) { | 
| -      disk_mount_manager_mock_->CreateDiskEntryForMountDevice( | 
| -        mount_info, unique_id, device_label); | 
| -    } | 
| -    notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, | 
| -                                   error_code, | 
| -                                   mount_info); | 
| -    WaitForFileThread(); | 
| -  } | 
| - | 
| +                   const std::string& device_label, | 
| +                   const std::string& vendor_name, | 
| +                   const std::string& product_name, | 
| +                   DeviceType device_type, | 
| +                   uint64 device_size_in_bytes); | 
| void UnmountDevice(MountError error_code, | 
| -                     const DiskMountManager::MountPointInfo& mount_info) { | 
| -    notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, | 
| -                                   error_code, | 
| -                                   mount_info); | 
| -    if (error_code == MOUNT_ERROR_NONE) { | 
| -      disk_mount_manager_mock_->RemoveDiskEntryForMountDevice( | 
| -          mount_info); | 
| -    } | 
| -    WaitForFileThread(); | 
| -  } | 
| +                     const DiskMountManager::MountPointInfo& mount_info); | 
| +  string16 GetDeviceStorageSizeInfo(const std::string& 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 return_path(scoped_temp_dir_.path()); | 
| -    return_path = return_path.AppendASCII(dir); | 
| -    FilePath path(return_path); | 
| -    if (with_dcim_dir) | 
| -      path = path.AppendASCII("DCIM"); | 
| -    if (!file_util::CreateDirectory(path)) | 
| -      return FilePath(); | 
| -    return return_path; | 
| -  } | 
| +  FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir); | 
|  | 
| -  static void PostQuitToUIThread() { | 
| -    BrowserThread::PostTask(BrowserThread::UI, | 
| -                            FROM_HERE, | 
| -                            MessageLoop::QuitClosure()); | 
| -  } | 
| +  static void PostQuitToUIThread(); | 
| +  static void WaitForFileThread(); | 
|  | 
| -  static void WaitForFileThread() { | 
| -    BrowserThread::PostTask(BrowserThread::FILE, | 
| -                            FROM_HERE, | 
| -                            base::Bind(&PostQuitToUIThread)); | 
| -    MessageLoop::current()->Run(); | 
| +  base::MockDevicesChangedObserver& observer() { | 
| +    return *mock_devices_changed_observer_; | 
| } | 
|  | 
| private: | 
| @@ -155,6 +110,104 @@ class RemovableDeviceNotificationsCrosTest : public testing::Test { | 
| DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCrosTest); | 
| }; | 
|  | 
| +RemovableDeviceNotificationsCrosTest::RemovableDeviceNotificationsCrosTest() | 
| +    : ui_thread_(BrowserThread::UI, &ui_loop_), | 
| +      file_thread_(BrowserThread::FILE) { | 
| +} | 
| + | 
| +RemovableDeviceNotificationsCrosTest::~RemovableDeviceNotificationsCrosTest() { | 
| +} | 
| + | 
| +void RemovableDeviceNotificationsCrosTest::SetUp() { | 
| +  ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| +  ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 
| +  file_thread_.Start(); | 
| + | 
| +  mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | 
| +  system_monitor_.AddDevicesChangedObserver( | 
| +      mock_devices_changed_observer_.get()); | 
| + | 
| +  disk_mount_manager_mock_ = new disks::MockDiskMountManager(); | 
| +  DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | 
| +  disk_mount_manager_mock_->SetupDefaultReplies(); | 
| + | 
| +  // Initialize the test subject. | 
| +  notifications_ = new RemovableDeviceNotificationsCros(); | 
| +} | 
| + | 
| +void RemovableDeviceNotificationsCrosTest::TearDown() { | 
| +  notifications_ = NULL; | 
| +  disk_mount_manager_mock_ = NULL; | 
| +  DiskMountManager::Shutdown(); | 
| +  system_monitor_.RemoveDevicesChangedObserver( | 
| +      mock_devices_changed_observer_.get()); | 
| +  WaitForFileThread(); | 
| +} | 
| + | 
| +void RemovableDeviceNotificationsCrosTest::MountDevice( | 
| +    MountError error_code, | 
| +    const DiskMountManager::MountPointInfo& mount_info, | 
| +    const std::string& unique_id, | 
| +    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, vendor_name, product_name, | 
| +        device_type, device_size_in_bytes); | 
| +  } | 
| +  notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, | 
| +                                 error_code, | 
| +                                 mount_info); | 
| +  WaitForFileThread(); | 
| +} | 
| + | 
| +void RemovableDeviceNotificationsCrosTest::UnmountDevice( | 
| +    MountError error_code, | 
| +    const DiskMountManager::MountPointInfo& mount_info) { | 
| +  notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, | 
| +                                 error_code, | 
| +                                 mount_info); | 
| +  if (error_code == MOUNT_ERROR_NONE) { | 
| +    disk_mount_manager_mock_->RemoveDiskEntryForMountDevice( | 
| +        mount_info); | 
| +  } | 
| +  WaitForFileThread(); | 
| +} | 
| + | 
| +string16 RemovableDeviceNotificationsCrosTest::GetDeviceStorageSizeInfo( | 
| +    const std::string& device_location) { | 
| +  return notifications_->GetStorageSizeInfo(device_location); | 
| +} | 
| + | 
| +FilePath RemovableDeviceNotificationsCrosTest::CreateMountPoint( | 
| +    const std::string& dir, | 
| +    bool with_dcim_dir) { | 
| +  FilePath return_path(scoped_temp_dir_.path()); | 
| +  return_path = return_path.AppendASCII(dir); | 
| +  FilePath path(return_path); | 
| +  if (with_dcim_dir) | 
| +    path = path.AppendASCII("DCIM"); | 
| +  if (!file_util::CreateDirectory(path)) | 
| +    return FilePath(); | 
| +  return return_path; | 
| +} | 
| + | 
| +// static | 
| +void RemovableDeviceNotificationsCrosTest::PostQuitToUIThread() { | 
| +  BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 
| +                          MessageLoop::QuitClosure()); | 
| +} | 
| + | 
| +// static | 
| +void RemovableDeviceNotificationsCrosTest::WaitForFileThread() { | 
| +  BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 
| +                          base::Bind(&PostQuitToUIThread)); | 
| +  MessageLoop::current()->Run(); | 
| +} | 
| + | 
| // Simple test case where we attach and detach a media device. | 
| TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { | 
| testing::Sequence mock_sequence; | 
| @@ -167,10 +220,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 +241,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 +267,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 +287,93 @@ 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(kMountPointA, true); | 
| +  ASSERT_FALSE(mount_path1.empty()); | 
| +  DiskMountManager::MountPointInfo mount_info(kSDCardDeviceName, | 
| +                                              mount_path1.value(), | 
| +                                              MOUNT_TYPE_DEVICE, | 
| +                                              disks::MOUNT_CONDITION_NONE); | 
| +  const std::string kUniqueId0 = "FFFF-FFFF"; | 
| +  EXPECT_CALL(observer(), | 
| +              OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId0), | 
| +                                         ASCIIToUTF16(kSDCardDeviceName), | 
| +                                         mount_path1.value())) | 
| +      .InSequence(mock_sequence); | 
| +  MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kSDCardDeviceName, | 
| +              kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); | 
| + | 
| +  EXPECT_CALL(observer(), | 
| +              OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | 
| +      .InSequence(mock_sequence); | 
| +  UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 
| +} | 
| + | 
| +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, GetStorageSizeInfo) { | 
| +  testing::Sequence mock_sequence; | 
| +  FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 
| +  ASSERT_FALSE(mount_path1.empty()); | 
| +  ASSERT_TRUE(GetDeviceStorageSizeInfo(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), | 
| +            GetDeviceStorageSizeInfo(mount_path1.value())); | 
| +  EXPECT_CALL(observer(), | 
| +              OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | 
| +      .InSequence(mock_sequence); | 
| +  UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 
| } | 
|  | 
| }  // namespace | 
|  |