Chromium Code Reviews| 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 // chromeos::RemovableDeviceNotificationsCros unit tests. | 5 // chromeos::RemovableDeviceNotificationsCros unit tests. |
| 6 | 6 |
| 7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos. h" | 7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos. h" |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using disks::DiskMountManager; | 28 using disks::DiskMountManager; |
| 29 using testing::_; | 29 using testing::_; |
| 30 | 30 |
| 31 const char kDevice1[] = "/dev/d1"; | 31 const char kDevice1[] = "/dev/d1"; |
| 32 const char kDevice2[] = "/dev/disk/d2"; | 32 const char kDevice2[] = "/dev/disk/d2"; |
| 33 const char kDevice1Name[] = "d1"; | 33 const char kDevice1Name[] = "d1"; |
| 34 const char kDevice1NameWithSizeInfo[] = "2KB d1"; | |
| 35 const char kDevice1Size[] = "2KB"; | |
| 34 const char kDevice2Name[] = "d2"; | 36 const char kDevice2Name[] = "d2"; |
| 37 const char kDevice2NameWithSizeInfo[] = "19GB d2"; | |
| 38 const char kEmptyDeviceLabel[] = ""; | |
| 35 const char kMountPointA[] = "mnt_a"; | 39 const char kMountPointA[] = "mnt_a"; |
| 36 const char kMountPointB[] = "mnt_b"; | 40 const char kMountPointB[] = "mnt_b"; |
| 41 const char kProductName[] = "Z101"; | |
| 42 const char kSDCardDeviceName[] = "8MB SD Card"; | |
| 43 const char kVendorName[] = "CompanyA"; | |
| 44 const char kDeviceNameWithManufacturerDetails[] = "2KB {CompanyA, Z101}"; | |
| 45 | |
| 46 uint64 kDevice1SizeInBytes = 2048; | |
| 47 uint64 kDevice2SizeInBytes = 21231209600; | |
| 48 uint64 kSDCardSizeInBytes = 9000000; | |
| 37 | 49 |
| 38 std::string GetDCIMDeviceId(const std::string& unique_id) { | 50 std::string GetDCIMDeviceId(const std::string& unique_id) { |
| 39 return chrome::MediaStorageUtil::MakeDeviceId( | 51 return chrome::MediaStorageUtil::MakeDeviceId( |
| 40 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, | 52 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, |
| 41 chrome::kFSUniqueIdPrefix + unique_id); | 53 chrome::kFSUniqueIdPrefix + unique_id); |
| 42 } | 54 } |
| 43 | 55 |
| 56 // Wrapper class to test RemovableDeviceNotificationsCros. | |
| 44 class RemovableDeviceNotificationsCrosTest : public testing::Test { | 57 class RemovableDeviceNotificationsCrosTest : public testing::Test { |
| 45 public: | 58 public: |
| 46 RemovableDeviceNotificationsCrosTest() | 59 RemovableDeviceNotificationsCrosTest(); |
| 47 : ui_thread_(BrowserThread::UI, &ui_loop_), | 60 virtual ~RemovableDeviceNotificationsCrosTest(); |
| 48 file_thread_(BrowserThread::FILE) { | |
|
kmadhusu
2012/11/08 03:57:25
Moved the function definitions out of the class de
Lei Zhang
2012/11/09 01:12:18
It would be nice if you can do this in a different
kmadhusu
2012/11/09 21:59:40
Done.
| |
| 49 } | |
| 50 virtual ~RemovableDeviceNotificationsCrosTest() {} | |
| 51 | 61 |
| 52 protected: | 62 protected: |
| 53 virtual void SetUp() { | 63 // testing::Test: |
| 54 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 64 virtual void SetUp() OVERRIDE; |
| 55 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 65 virtual void TearDown() OVERRIDE; |
| 56 file_thread_.Start(); | |
| 57 | |
| 58 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | |
| 59 system_monitor_.AddDevicesChangedObserver( | |
| 60 mock_devices_changed_observer_.get()); | |
| 61 | |
| 62 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); | |
| 63 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | |
| 64 disk_mount_manager_mock_->SetupDefaultReplies(); | |
| 65 | |
| 66 // Initialize the test subject. | |
| 67 notifications_ = new RemovableDeviceNotificationsCros(); | |
| 68 } | |
| 69 | |
| 70 virtual void TearDown() { | |
| 71 notifications_ = NULL; | |
| 72 disk_mount_manager_mock_ = NULL; | |
| 73 DiskMountManager::Shutdown(); | |
| 74 system_monitor_.RemoveDevicesChangedObserver( | |
| 75 mock_devices_changed_observer_.get()); | |
| 76 WaitForFileThread(); | |
| 77 } | |
| 78 | |
| 79 base::MockDevicesChangedObserver& observer() { | |
| 80 return *mock_devices_changed_observer_; | |
| 81 } | |
| 82 | 66 |
| 83 void MountDevice(MountError error_code, | 67 void MountDevice(MountError error_code, |
| 84 const DiskMountManager::MountPointInfo& mount_info, | 68 const DiskMountManager::MountPointInfo& mount_info, |
| 85 const std::string& unique_id, | 69 const std::string& unique_id, |
| 86 const std::string& device_label) { | 70 const std::string& device_label, |
| 87 if (error_code == MOUNT_ERROR_NONE) { | 71 const std::string& vendor_name, |
| 88 disk_mount_manager_mock_->CreateDiskEntryForMountDevice( | 72 const std::string& product_name, |
| 89 mount_info, unique_id, device_label); | 73 DeviceType device_type, |
| 90 } | 74 uint64 device_size_in_bytes); |
| 91 notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, | |
| 92 error_code, | |
| 93 mount_info); | |
| 94 WaitForFileThread(); | |
| 95 } | |
| 96 | |
| 97 void UnmountDevice(MountError error_code, | 75 void UnmountDevice(MountError error_code, |
| 98 const DiskMountManager::MountPointInfo& mount_info) { | 76 const DiskMountManager::MountPointInfo& mount_info); |
| 99 notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, | 77 string16 GetDeviceStorageSizeInfo(const std::string& device_location); |
| 100 error_code, | |
| 101 mount_info); | |
| 102 if (error_code == MOUNT_ERROR_NONE) { | |
| 103 disk_mount_manager_mock_->RemoveDiskEntryForMountDevice( | |
| 104 mount_info); | |
| 105 } | |
| 106 WaitForFileThread(); | |
| 107 } | |
| 108 | 78 |
| 109 // Create a directory named |dir| relative to the test directory. | 79 // Create a directory named |dir| relative to the test directory. |
| 110 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 80 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
| 111 // subdirectory. | 81 // subdirectory. |
| 112 // Returns the full path to the created directory on success, or an empty | 82 // Returns the full path to the created directory on success, or an empty |
| 113 // path on failure. | 83 // path on failure. |
| 114 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { | 84 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir); |
| 115 FilePath return_path(scoped_temp_dir_.path()); | |
| 116 return_path = return_path.AppendASCII(dir); | |
| 117 FilePath path(return_path); | |
| 118 if (with_dcim_dir) | |
| 119 path = path.AppendASCII("DCIM"); | |
| 120 if (!file_util::CreateDirectory(path)) | |
| 121 return FilePath(); | |
| 122 return return_path; | |
| 123 } | |
| 124 | 85 |
| 125 static void PostQuitToUIThread() { | 86 static void PostQuitToUIThread(); |
| 126 BrowserThread::PostTask(BrowserThread::UI, | 87 static void WaitForFileThread(); |
| 127 FROM_HERE, | |
| 128 MessageLoop::QuitClosure()); | |
| 129 } | |
| 130 | 88 |
| 131 static void WaitForFileThread() { | 89 base::MockDevicesChangedObserver& observer() { |
| 132 BrowserThread::PostTask(BrowserThread::FILE, | 90 return *mock_devices_changed_observer_; |
| 133 FROM_HERE, | |
| 134 base::Bind(&PostQuitToUIThread)); | |
| 135 MessageLoop::current()->Run(); | |
| 136 } | 91 } |
| 137 | 92 |
| 138 private: | 93 private: |
| 139 // The message loops and threads to run tests on. | 94 // The message loops and threads to run tests on. |
| 140 MessageLoop ui_loop_; | 95 MessageLoop ui_loop_; |
| 141 content::TestBrowserThread ui_thread_; | 96 content::TestBrowserThread ui_thread_; |
| 142 content::TestBrowserThread file_thread_; | 97 content::TestBrowserThread file_thread_; |
| 143 | 98 |
| 144 // Temporary directory for created test data. | 99 // Temporary directory for created test data. |
| 145 ScopedTempDir scoped_temp_dir_; | 100 ScopedTempDir scoped_temp_dir_; |
| 146 | 101 |
| 147 // Objects that talks with RemovableDeviceNotificationsCros. | 102 // Objects that talks with RemovableDeviceNotificationsCros. |
| 148 base::SystemMonitor system_monitor_; | 103 base::SystemMonitor system_monitor_; |
| 149 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; | 104 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; |
| 150 // Owned by DiskMountManager. | 105 // Owned by DiskMountManager. |
| 151 disks::MockDiskMountManager* disk_mount_manager_mock_; | 106 disks::MockDiskMountManager* disk_mount_manager_mock_; |
| 152 | 107 |
| 153 scoped_refptr<RemovableDeviceNotificationsCros> notifications_; | 108 scoped_refptr<RemovableDeviceNotificationsCros> notifications_; |
| 154 | 109 |
| 155 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCrosTest); | 110 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCrosTest); |
| 156 }; | 111 }; |
| 157 | 112 |
| 113 RemovableDeviceNotificationsCrosTest::RemovableDeviceNotificationsCrosTest() | |
| 114 : ui_thread_(BrowserThread::UI, &ui_loop_), | |
| 115 file_thread_(BrowserThread::FILE) { | |
| 116 } | |
| 117 | |
| 118 RemovableDeviceNotificationsCrosTest::~RemovableDeviceNotificationsCrosTest() { | |
| 119 } | |
| 120 | |
| 121 void RemovableDeviceNotificationsCrosTest::SetUp() { | |
| 122 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 123 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | |
| 124 file_thread_.Start(); | |
| 125 | |
| 126 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | |
| 127 system_monitor_.AddDevicesChangedObserver( | |
| 128 mock_devices_changed_observer_.get()); | |
| 129 | |
| 130 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); | |
| 131 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | |
| 132 disk_mount_manager_mock_->SetupDefaultReplies(); | |
| 133 | |
| 134 // Initialize the test subject. | |
| 135 notifications_ = new RemovableDeviceNotificationsCros(); | |
| 136 } | |
| 137 | |
| 138 void RemovableDeviceNotificationsCrosTest::TearDown() { | |
| 139 notifications_ = NULL; | |
| 140 disk_mount_manager_mock_ = NULL; | |
| 141 DiskMountManager::Shutdown(); | |
| 142 system_monitor_.RemoveDevicesChangedObserver( | |
| 143 mock_devices_changed_observer_.get()); | |
| 144 WaitForFileThread(); | |
| 145 } | |
| 146 | |
| 147 void RemovableDeviceNotificationsCrosTest::MountDevice( | |
| 148 MountError error_code, | |
| 149 const DiskMountManager::MountPointInfo& mount_info, | |
| 150 const std::string& unique_id, | |
| 151 const std::string& device_label, | |
| 152 const std::string& vendor_name, | |
| 153 const std::string& product_name, | |
| 154 DeviceType device_type, | |
| 155 uint64 device_size_in_bytes) { | |
| 156 if (error_code == MOUNT_ERROR_NONE) { | |
| 157 disk_mount_manager_mock_->CreateDiskEntryForMountDevice( | |
| 158 mount_info, unique_id, device_label, vendor_name, product_name, | |
| 159 device_type, device_size_in_bytes); | |
| 160 } | |
| 161 notifications_->MountCompleted(disks::DiskMountManager::MOUNTING, | |
| 162 error_code, | |
| 163 mount_info); | |
| 164 WaitForFileThread(); | |
| 165 } | |
| 166 | |
| 167 void RemovableDeviceNotificationsCrosTest::UnmountDevice( | |
| 168 MountError error_code, | |
| 169 const DiskMountManager::MountPointInfo& mount_info) { | |
| 170 notifications_->MountCompleted(disks::DiskMountManager::UNMOUNTING, | |
| 171 error_code, | |
| 172 mount_info); | |
| 173 if (error_code == MOUNT_ERROR_NONE) { | |
| 174 disk_mount_manager_mock_->RemoveDiskEntryForMountDevice( | |
| 175 mount_info); | |
| 176 } | |
| 177 WaitForFileThread(); | |
| 178 } | |
| 179 | |
| 180 string16 RemovableDeviceNotificationsCrosTest::GetDeviceStorageSizeInfo( | |
| 181 const std::string& device_location) { | |
| 182 return notifications_->GetStorageSizeInfo(device_location); | |
| 183 } | |
| 184 | |
| 185 FilePath RemovableDeviceNotificationsCrosTest::CreateMountPoint( | |
| 186 const std::string& dir, | |
| 187 bool with_dcim_dir) { | |
| 188 FilePath return_path(scoped_temp_dir_.path()); | |
| 189 return_path = return_path.AppendASCII(dir); | |
| 190 FilePath path(return_path); | |
| 191 if (with_dcim_dir) | |
| 192 path = path.AppendASCII("DCIM"); | |
| 193 if (!file_util::CreateDirectory(path)) | |
| 194 return FilePath(); | |
| 195 return return_path; | |
| 196 } | |
| 197 | |
| 198 // static | |
| 199 void RemovableDeviceNotificationsCrosTest::PostQuitToUIThread() { | |
| 200 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 201 MessageLoop::QuitClosure()); | |
| 202 } | |
| 203 | |
| 204 // static | |
| 205 void RemovableDeviceNotificationsCrosTest::WaitForFileThread() { | |
| 206 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 207 base::Bind(&PostQuitToUIThread)); | |
| 208 MessageLoop::current()->Run(); | |
| 209 } | |
| 210 | |
| 158 // Simple test case where we attach and detach a media device. | 211 // Simple test case where we attach and detach a media device. |
| 159 TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { | 212 TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { |
| 160 testing::Sequence mock_sequence; | 213 testing::Sequence mock_sequence; |
| 161 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 214 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| 162 ASSERT_FALSE(mount_path1.empty()); | 215 ASSERT_FALSE(mount_path1.empty()); |
| 163 DiskMountManager::MountPointInfo mount_info(kDevice1, | 216 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 164 mount_path1.value(), | 217 mount_path1.value(), |
| 165 MOUNT_TYPE_DEVICE, | 218 MOUNT_TYPE_DEVICE, |
| 166 disks::MOUNT_CONDITION_NONE); | 219 disks::MOUNT_CONDITION_NONE); |
| 167 const std::string kUniqueId0 = "FFFF-FFFF"; | 220 const std::string kUniqueId0 = "FFFF-FFFF"; |
| 168 EXPECT_CALL(observer(), | 221 EXPECT_CALL(observer(), |
| 169 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId0), | 222 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId0), |
| 170 ASCIIToUTF16(kDevice1Name), | 223 ASCIIToUTF16(kDevice1NameWithSizeInfo), |
| 171 mount_path1.value())) | 224 mount_path1.value())) |
| 172 .InSequence(mock_sequence); | 225 .InSequence(mock_sequence); |
| 173 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kDevice1Name); | 226 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kDevice1Name, |
| 227 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
| 174 | 228 |
| 175 EXPECT_CALL(observer(), | 229 EXPECT_CALL(observer(), |
| 176 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | 230 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) |
| 177 .InSequence(mock_sequence); | 231 .InSequence(mock_sequence); |
| 178 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 232 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| 179 | 233 |
| 180 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); | 234 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); |
| 181 ASSERT_FALSE(mount_path2.empty()); | 235 ASSERT_FALSE(mount_path2.empty()); |
| 182 DiskMountManager::MountPointInfo mount_info2(kDevice2, | 236 DiskMountManager::MountPointInfo mount_info2(kDevice2, |
| 183 mount_path2.value(), | 237 mount_path2.value(), |
| 184 MOUNT_TYPE_DEVICE, | 238 MOUNT_TYPE_DEVICE, |
| 185 disks::MOUNT_CONDITION_NONE); | 239 disks::MOUNT_CONDITION_NONE); |
| 186 const std::string kUniqueId1 = "FFF0-FFF0"; | 240 const std::string kUniqueId1 = "FFF0-FFF0"; |
| 187 | 241 |
| 188 EXPECT_CALL(observer(), | 242 EXPECT_CALL(observer(), |
| 189 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), | 243 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), |
| 190 ASCIIToUTF16(kDevice2Name), | 244 ASCIIToUTF16(kDevice2NameWithSizeInfo), |
| 191 mount_path2.value())) | 245 mount_path2.value())) |
| 192 .InSequence(mock_sequence); | 246 .InSequence(mock_sequence); |
| 193 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId1, kDevice2Name); | 247 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId1, kDevice2Name, |
| 248 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice2SizeInBytes); | |
| 194 | 249 |
| 195 EXPECT_CALL(observer(), | 250 EXPECT_CALL(observer(), |
| 196 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | 251 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) |
| 197 .InSequence(mock_sequence); | 252 .InSequence(mock_sequence); |
| 198 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | 253 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
| 199 } | 254 } |
| 200 | 255 |
| 201 // Removable mass storage devices with no dcim folder are also recognized. | 256 // Removable mass storage devices with no dcim folder are also recognized. |
| 202 TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { | 257 TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { |
| 203 testing::Sequence mock_sequence; | 258 testing::Sequence mock_sequence; |
| 204 FilePath mount_path = CreateMountPoint(kMountPointA, false); | 259 FilePath mount_path = CreateMountPoint(kMountPointA, false); |
| 205 const std::string kUniqueId = "FFFF-FFFF"; | 260 const std::string kUniqueId = "FFFF-FFFF"; |
| 206 ASSERT_FALSE(mount_path.empty()); | 261 ASSERT_FALSE(mount_path.empty()); |
| 207 DiskMountManager::MountPointInfo mount_info(kDevice1, | 262 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 208 mount_path.value(), | 263 mount_path.value(), |
| 209 MOUNT_TYPE_DEVICE, | 264 MOUNT_TYPE_DEVICE, |
| 210 disks::MOUNT_CONDITION_NONE); | 265 disks::MOUNT_CONDITION_NONE); |
| 211 const std::string device_id = chrome::MediaStorageUtil::MakeDeviceId( | 266 const std::string device_id = chrome::MediaStorageUtil::MakeDeviceId( |
| 212 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, | 267 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, |
| 213 chrome::kFSUniqueIdPrefix + kUniqueId); | 268 chrome::kFSUniqueIdPrefix + kUniqueId); |
| 214 EXPECT_CALL(observer(), | 269 EXPECT_CALL(observer(), |
| 215 OnRemovableStorageAttached(device_id, ASCIIToUTF16(kDevice1Name), | 270 OnRemovableStorageAttached(device_id, |
| 271 ASCIIToUTF16(kDevice1NameWithSizeInfo), | |
| 216 mount_path.value())).Times(1); | 272 mount_path.value())).Times(1); |
| 217 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); | 273 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 274 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
| 218 } | 275 } |
| 219 | 276 |
| 220 // Non device mounts and mount errors are ignored. | 277 // Non device mounts and mount errors are ignored. |
| 221 TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { | 278 TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { |
| 222 testing::Sequence mock_sequence; | 279 testing::Sequence mock_sequence; |
| 223 FilePath mount_path = CreateMountPoint(kMountPointA, true); | 280 FilePath mount_path = CreateMountPoint(kMountPointA, true); |
| 224 const std::string kUniqueId = "FFFF-FFFF"; | 281 const std::string kUniqueId = "FFFF-FFFF"; |
| 225 ASSERT_FALSE(mount_path.empty()); | 282 ASSERT_FALSE(mount_path.empty()); |
| 226 | 283 |
| 227 // Mount error. | 284 // Mount error. |
| 228 DiskMountManager::MountPointInfo mount_info(kDevice1, | 285 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 229 mount_path.value(), | 286 mount_path.value(), |
| 230 MOUNT_TYPE_DEVICE, | 287 MOUNT_TYPE_DEVICE, |
| 231 disks::MOUNT_CONDITION_NONE); | 288 disks::MOUNT_CONDITION_NONE); |
| 232 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 289 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| 233 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name); | 290 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name, |
| 291 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
| 234 | 292 |
| 235 // Not a device | 293 // Not a device |
| 236 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; | 294 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; |
| 237 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 295 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| 238 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); | 296 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 297 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
| 239 | 298 |
| 240 // Unsupported file system. | 299 // Unsupported file system. |
| 241 mount_info.mount_type = MOUNT_TYPE_DEVICE; | 300 mount_info.mount_type = MOUNT_TYPE_DEVICE; |
| 242 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; | 301 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
| 243 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | 302 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| 244 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name); | 303 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 304 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
| 305 } | |
| 306 | |
| 307 TEST_F(RemovableDeviceNotificationsCrosTest, SDCardAttachDetach) { | |
| 308 testing::Sequence mock_sequence; | |
| 309 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | |
| 310 ASSERT_FALSE(mount_path1.empty()); | |
| 311 DiskMountManager::MountPointInfo mount_info(kSDCardDeviceName, | |
| 312 mount_path1.value(), | |
| 313 MOUNT_TYPE_DEVICE, | |
| 314 disks::MOUNT_CONDITION_NONE); | |
| 315 const std::string kUniqueId0 = "FFFF-FFFF"; | |
| 316 EXPECT_CALL(observer(), | |
| 317 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId0), | |
| 318 ASCIIToUTF16(kSDCardDeviceName), | |
| 319 mount_path1.value())) | |
| 320 .InSequence(mock_sequence); | |
| 321 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kSDCardDeviceName, | |
| 322 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); | |
| 323 | |
| 324 EXPECT_CALL(observer(), | |
| 325 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | |
| 326 .InSequence(mock_sequence); | |
| 327 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | |
| 328 } | |
| 329 | |
| 330 TEST_F(RemovableDeviceNotificationsCrosTest, AttachDeviceWithEmptyLabel) { | |
| 331 testing::Sequence mock_sequence; | |
| 332 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | |
| 333 ASSERT_FALSE(mount_path1.empty()); | |
| 334 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, | |
| 335 mount_path1.value(), | |
| 336 MOUNT_TYPE_DEVICE, | |
| 337 disks::MOUNT_CONDITION_NONE); | |
| 338 const std::string kUniqueId0 = "FFFF-FFFF"; | |
| 339 EXPECT_CALL(observer(), OnRemovableStorageAttached( | |
| 340 GetDCIMDeviceId(kUniqueId0), | |
| 341 ASCIIToUTF16(kDeviceNameWithManufacturerDetails), | |
| 342 mount_path1.value())) | |
| 343 .InSequence(mock_sequence); | |
| 344 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kEmptyDeviceLabel, | |
| 345 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
| 346 | |
| 347 EXPECT_CALL(observer(), | |
| 348 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | |
| 349 .InSequence(mock_sequence); | |
| 350 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | |
| 351 } | |
| 352 | |
| 353 TEST_F(RemovableDeviceNotificationsCrosTest, GetStorageSizeInfo) { | |
| 354 testing::Sequence mock_sequence; | |
| 355 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | |
| 356 ASSERT_FALSE(mount_path1.empty()); | |
| 357 ASSERT_TRUE(GetDeviceStorageSizeInfo(mount_path1.value()).empty()); | |
| 358 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, | |
| 359 mount_path1.value(), | |
| 360 MOUNT_TYPE_DEVICE, | |
| 361 disks::MOUNT_CONDITION_NONE); | |
| 362 const std::string kUniqueId0 = "FFFF-FFFF"; | |
| 363 EXPECT_CALL(observer(), OnRemovableStorageAttached( | |
| 364 GetDCIMDeviceId(kUniqueId0), | |
| 365 ASCIIToUTF16(kDeviceNameWithManufacturerDetails), | |
| 366 mount_path1.value())) | |
| 367 .InSequence(mock_sequence); | |
| 368 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId0, kEmptyDeviceLabel, | |
| 369 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | |
| 370 | |
| 371 EXPECT_EQ(ASCIIToUTF16(kDevice1Size), | |
| 372 GetDeviceStorageSizeInfo(mount_path1.value())); | |
| 373 EXPECT_CALL(observer(), | |
| 374 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId0))) | |
| 375 .InSequence(mock_sequence); | |
| 376 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | |
| 245 } | 377 } |
| 246 | 378 |
| 247 } // namespace | 379 } // namespace |
| 248 | 380 |
| 249 } // namespace chrome | 381 } // namespace chrome |
| OLD | NEW |