| 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/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/system_monitor/system_monitor.h" | |
| 15 #include "base/test/mock_devices_changed_observer.h" | |
| 16 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/system_monitor/media_storage_util.h" | 15 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 16 #include "chrome/browser/system_monitor/mock_removable_storage_observer.h" |
| 18 #include "chrome/browser/system_monitor/removable_device_constants.h" | 17 #include "chrome/browser/system_monitor/removable_device_constants.h" |
| 19 #include "chromeos/disks/mock_disk_mount_manager.h" | 18 #include "chromeos/disks/mock_disk_mount_manager.h" |
| 20 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace chromeos { | 22 namespace chromeos { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 using content::BrowserThread; | 26 using content::BrowserThread; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Create a directory named |dir| relative to the test directory. | 84 // Create a directory named |dir| relative to the test directory. |
| 86 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 85 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
| 87 // subdirectory. | 86 // subdirectory. |
| 88 // Returns the full path to the created directory on success, or an empty | 87 // Returns the full path to the created directory on success, or an empty |
| 89 // path on failure. | 88 // path on failure. |
| 90 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir); | 89 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir); |
| 91 | 90 |
| 92 static void PostQuitToUIThread(); | 91 static void PostQuitToUIThread(); |
| 93 static void WaitForFileThread(); | 92 static void WaitForFileThread(); |
| 94 | 93 |
| 95 base::MockDevicesChangedObserver& observer() { | 94 chrome::MockRemovableStorageObserver& observer() { |
| 96 return *mock_devices_changed_observer_; | 95 return *mock_storage_observer_; |
| 97 } | 96 } |
| 98 | 97 |
| 99 private: | 98 private: |
| 100 // The message loops and threads to run tests on. | 99 // The message loops and threads to run tests on. |
| 101 MessageLoop ui_loop_; | 100 MessageLoop ui_loop_; |
| 102 content::TestBrowserThread ui_thread_; | 101 content::TestBrowserThread ui_thread_; |
| 103 content::TestBrowserThread file_thread_; | 102 content::TestBrowserThread file_thread_; |
| 104 | 103 |
| 105 // Temporary directory for created test data. | 104 // Temporary directory for created test data. |
| 106 base::ScopedTempDir scoped_temp_dir_; | 105 base::ScopedTempDir scoped_temp_dir_; |
| 107 | 106 |
| 108 // Objects that talks with RemovableDeviceNotificationsCros. | 107 // Objects that talks with RemovableDeviceNotificationsCros. |
| 109 base::SystemMonitor system_monitor_; | 108 scoped_ptr<chrome::MockRemovableStorageObserver> mock_storage_observer_; |
| 110 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; | |
| 111 // Owned by DiskMountManager. | 109 // Owned by DiskMountManager. |
| 112 disks::MockDiskMountManager* disk_mount_manager_mock_; | 110 disks::MockDiskMountManager* disk_mount_manager_mock_; |
| 113 | 111 |
| 114 scoped_refptr<RemovableDeviceNotificationsCros> notifications_; | 112 scoped_refptr<RemovableDeviceNotificationsCros> notifications_; |
| 115 | 113 |
| 116 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCrosTest); | 114 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCrosTest); |
| 117 }; | 115 }; |
| 118 | 116 |
| 119 RemovableDeviceNotificationsCrosTest::RemovableDeviceNotificationsCrosTest() | 117 RemovableDeviceNotificationsCrosTest::RemovableDeviceNotificationsCrosTest() |
| 120 : ui_thread_(BrowserThread::UI, &ui_loop_), | 118 : ui_thread_(BrowserThread::UI, &ui_loop_), |
| 121 file_thread_(BrowserThread::FILE) { | 119 file_thread_(BrowserThread::FILE) { |
| 122 } | 120 } |
| 123 | 121 |
| 124 RemovableDeviceNotificationsCrosTest::~RemovableDeviceNotificationsCrosTest() { | 122 RemovableDeviceNotificationsCrosTest::~RemovableDeviceNotificationsCrosTest() { |
| 125 } | 123 } |
| 126 | 124 |
| 127 void RemovableDeviceNotificationsCrosTest::SetUp() { | 125 void RemovableDeviceNotificationsCrosTest::SetUp() { |
| 128 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 126 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 129 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 127 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
| 130 file_thread_.Start(); | 128 file_thread_.Start(); |
| 131 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | 129 mock_storage_observer_.reset(new chrome::MockRemovableStorageObserver); |
| 132 system_monitor_.AddDevicesChangedObserver( | 130 notifications_->AddObserver(mock_storage_observer_.get()); |
| 133 mock_devices_changed_observer_.get()); | |
| 134 | 131 |
| 135 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); | 132 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); |
| 136 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | 133 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); |
| 137 disk_mount_manager_mock_->SetupDefaultReplies(); | 134 disk_mount_manager_mock_->SetupDefaultReplies(); |
| 138 | 135 |
| 139 // Initialize the test subject. | 136 // Initialize the test subject. |
| 140 notifications_ = new RemovableDeviceNotificationsCros(); | 137 notifications_ = new RemovableDeviceNotificationsCros(); |
| 141 } | 138 } |
| 142 | 139 |
| 143 void RemovableDeviceNotificationsCrosTest::TearDown() { | 140 void RemovableDeviceNotificationsCrosTest::TearDown() { |
| 144 notifications_ = NULL; | 141 notifications_ = NULL; |
| 145 disk_mount_manager_mock_ = NULL; | 142 disk_mount_manager_mock_ = NULL; |
| 146 DiskMountManager::Shutdown(); | 143 DiskMountManager::Shutdown(); |
| 147 system_monitor_.RemoveDevicesChangedObserver( | 144 notifications_->RemoveObserver(mock_storage_observer_.get()); |
| 148 mock_devices_changed_observer_.get()); | |
| 149 WaitForFileThread(); | 145 WaitForFileThread(); |
| 150 } | 146 } |
| 151 | 147 |
| 152 void RemovableDeviceNotificationsCrosTest::MountDevice( | 148 void RemovableDeviceNotificationsCrosTest::MountDevice( |
| 153 MountError error_code, | 149 MountError error_code, |
| 154 const DiskMountManager::MountPointInfo& mount_info, | 150 const DiskMountManager::MountPointInfo& mount_info, |
| 155 const std::string& unique_id, | 151 const std::string& unique_id, |
| 156 const std::string& device_label, | 152 const std::string& device_label, |
| 157 const std::string& vendor_name, | 153 const std::string& vendor_name, |
| 158 const std::string& product_name, | 154 const std::string& product_name, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 201 |
| 206 // static | 202 // static |
| 207 void RemovableDeviceNotificationsCrosTest::WaitForFileThread() { | 203 void RemovableDeviceNotificationsCrosTest::WaitForFileThread() { |
| 208 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 204 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 209 base::Bind(&PostQuitToUIThread)); | 205 base::Bind(&PostQuitToUIThread)); |
| 210 MessageLoop::current()->Run(); | 206 MessageLoop::current()->Run(); |
| 211 } | 207 } |
| 212 | 208 |
| 213 // Simple test case where we attach and detach a media device. | 209 // Simple test case where we attach and detach a media device. |
| 214 TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { | 210 TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { |
| 215 testing::Sequence mock_sequence; | |
| 216 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 211 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| 217 ASSERT_FALSE(mount_path1.empty()); | 212 ASSERT_FALSE(mount_path1.empty()); |
| 218 DiskMountManager::MountPointInfo mount_info(kDevice1, | 213 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 219 mount_path1.value(), | 214 mount_path1.value(), |
| 220 MOUNT_TYPE_DEVICE, | 215 MOUNT_TYPE_DEVICE, |
| 221 disks::MOUNT_CONDITION_NONE); | 216 disks::MOUNT_CONDITION_NONE); |
| 222 EXPECT_CALL(observer(), | |
| 223 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId1), | |
| 224 ASCIIToUTF16(kDevice1NameWithSizeInfo), | |
| 225 mount_path1.value())) | |
| 226 .InSequence(mock_sequence); | |
| 227 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kDevice1Name, | 217 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kDevice1Name, |
| 228 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 218 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 219 EXPECT_EQ(1, observer().attach_calls()); |
| 220 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_attached().device_id); |
| 221 EXPECT_EQ(ASCIIToUTF16(kDevice1NameWithSizeInfo), |
| 222 observer().last_attached().name); |
| 223 EXPECT_EQ(mount_path1.value(), observer().last_attached().location); |
| 229 | 224 |
| 230 EXPECT_CALL(observer(), | |
| 231 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | |
| 232 .InSequence(mock_sequence); | |
| 233 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 225 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| 226 EXPECT_EQ(1, observer().detach_calls()); |
| 227 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_detached().device_id); |
| 234 | 228 |
| 235 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); | 229 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); |
| 236 ASSERT_FALSE(mount_path2.empty()); | 230 ASSERT_FALSE(mount_path2.empty()); |
| 237 DiskMountManager::MountPointInfo mount_info2(kDevice2, | 231 DiskMountManager::MountPointInfo mount_info2(kDevice2, |
| 238 mount_path2.value(), | 232 mount_path2.value(), |
| 239 MOUNT_TYPE_DEVICE, | 233 MOUNT_TYPE_DEVICE, |
| 240 disks::MOUNT_CONDITION_NONE); | 234 disks::MOUNT_CONDITION_NONE); |
| 241 EXPECT_CALL(observer(), | |
| 242 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId2), | |
| 243 ASCIIToUTF16(kDevice2NameWithSizeInfo), | |
| 244 mount_path2.value())) | |
| 245 .InSequence(mock_sequence); | |
| 246 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kDevice2Name, | 235 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kDevice2Name, |
| 247 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice2SizeInBytes); | 236 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice2SizeInBytes); |
| 237 EXPECT_EQ(2, observer().attach_calls()); |
| 238 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_attached().device_id); |
| 239 EXPECT_EQ(ASCIIToUTF16(kDevice2NameWithSizeInfo), |
| 240 observer().last_attached().name); |
| 241 EXPECT_EQ(mount_path2.value(), observer().last_attached().location); |
| 248 | 242 |
| 249 EXPECT_CALL(observer(), | |
| 250 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) | |
| 251 .InSequence(mock_sequence); | |
| 252 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | 243 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
| 244 EXPECT_EQ(2, observer().detach_calls()); |
| 245 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_detached().device_id); |
| 253 } | 246 } |
| 254 | 247 |
| 255 // Removable mass storage devices with no dcim folder are also recognized. | 248 // Removable mass storage devices with no dcim folder are also recognized. |
| 256 TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { | 249 TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { |
| 257 testing::Sequence mock_sequence; | 250 testing::Sequence mock_sequence; |
| 258 FilePath mount_path = CreateMountPoint(kMountPointA, false); | 251 FilePath mount_path = CreateMountPoint(kMountPointA, false); |
| 259 const std::string kUniqueId = "FFFF-FFFF"; | 252 const std::string kUniqueId = "FFFF-FFFF"; |
| 260 ASSERT_FALSE(mount_path.empty()); | 253 ASSERT_FALSE(mount_path.empty()); |
| 261 DiskMountManager::MountPointInfo mount_info(kDevice1, | 254 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 262 mount_path.value(), | 255 mount_path.value(), |
| 263 MOUNT_TYPE_DEVICE, | 256 MOUNT_TYPE_DEVICE, |
| 264 disks::MOUNT_CONDITION_NONE); | 257 disks::MOUNT_CONDITION_NONE); |
| 265 const std::string device_id = chrome::MediaStorageUtil::MakeDeviceId( | 258 const std::string device_id = chrome::MediaStorageUtil::MakeDeviceId( |
| 266 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, | 259 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, |
| 267 chrome::kFSUniqueIdPrefix + kUniqueId); | 260 chrome::kFSUniqueIdPrefix + kUniqueId); |
| 268 EXPECT_CALL(observer(), | |
| 269 OnRemovableStorageAttached(device_id, | |
| 270 ASCIIToUTF16(kDevice1NameWithSizeInfo), | |
| 271 mount_path.value())).Times(1); | |
| 272 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, | 261 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 273 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 262 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 263 EXPECT_EQ(1, observer().attach_calls()); |
| 264 EXPECT_EQ(device_id, observer().last_attached().device_id); |
| 265 EXPECT_EQ(ASCIIToUTF16(kDevice1NameWithSizeInfo), |
| 266 observer().last_attached().name); |
| 267 EXPECT_EQ(mount_path.value(), observer().last_attached().location); |
| 274 } | 268 } |
| 275 | 269 |
| 276 // Non device mounts and mount errors are ignored. | 270 // Non device mounts and mount errors are ignored. |
| 277 TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { | 271 TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { |
| 278 testing::Sequence mock_sequence; | 272 testing::Sequence mock_sequence; |
| 279 FilePath mount_path = CreateMountPoint(kMountPointA, true); | 273 FilePath mount_path = CreateMountPoint(kMountPointA, true); |
| 280 const std::string kUniqueId = "FFFF-FFFF"; | 274 const std::string kUniqueId = "FFFF-FFFF"; |
| 281 ASSERT_FALSE(mount_path.empty()); | 275 ASSERT_FALSE(mount_path.empty()); |
| 282 | 276 |
| 283 // Mount error. | 277 // Mount error. |
| 284 DiskMountManager::MountPointInfo mount_info(kDevice1, | 278 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 285 mount_path.value(), | 279 mount_path.value(), |
| 286 MOUNT_TYPE_DEVICE, | 280 MOUNT_TYPE_DEVICE, |
| 287 disks::MOUNT_CONDITION_NONE); | 281 disks::MOUNT_CONDITION_NONE); |
| 288 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
| 289 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name, | 282 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name, |
| 290 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 283 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 284 EXPECT_EQ(0, observer().attach_calls()); |
| 291 | 285 |
| 292 // Not a device | 286 // Not a device |
| 293 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; | 287 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; |
| 294 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
| 295 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, | 288 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 296 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 289 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 290 EXPECT_EQ(0, observer().attach_calls()); |
| 297 | 291 |
| 298 // Unsupported file system. | 292 // Unsupported file system. |
| 299 mount_info.mount_type = MOUNT_TYPE_DEVICE; | 293 mount_info.mount_type = MOUNT_TYPE_DEVICE; |
| 300 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; | 294 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
| 301 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
| 302 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, | 295 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 303 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 296 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 297 EXPECT_EQ(0, observer().attach_calls()); |
| 304 } | 298 } |
| 305 | 299 |
| 306 TEST_F(RemovableDeviceNotificationsCrosTest, SDCardAttachDetach) { | 300 TEST_F(RemovableDeviceNotificationsCrosTest, SDCardAttachDetach) { |
| 307 testing::Sequence mock_sequence; | |
| 308 FilePath mount_path1 = CreateMountPoint(kSDCardMountPoint1, true); | 301 FilePath mount_path1 = CreateMountPoint(kSDCardMountPoint1, true); |
| 309 ASSERT_FALSE(mount_path1.empty()); | 302 ASSERT_FALSE(mount_path1.empty()); |
| 310 DiskMountManager::MountPointInfo mount_info1(kSDCardDeviceName1, | 303 DiskMountManager::MountPointInfo mount_info1(kSDCardDeviceName1, |
| 311 mount_path1.value(), | 304 mount_path1.value(), |
| 312 MOUNT_TYPE_DEVICE, | 305 MOUNT_TYPE_DEVICE, |
| 313 disks::MOUNT_CONDITION_NONE); | 306 disks::MOUNT_CONDITION_NONE); |
| 314 EXPECT_CALL(observer(), | |
| 315 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId2), | |
| 316 ASCIIToUTF16(kSDCardDeviceName1), | |
| 317 mount_path1.value())) | |
| 318 .InSequence(mock_sequence); | |
| 319 MountDevice(MOUNT_ERROR_NONE, mount_info1, kUniqueId2, kSDCardDeviceName1, | 307 MountDevice(MOUNT_ERROR_NONE, mount_info1, kUniqueId2, kSDCardDeviceName1, |
| 320 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); | 308 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); |
| 309 EXPECT_EQ(1, observer().attach_calls()); |
| 310 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_attached().device_id); |
| 311 EXPECT_EQ(ASCIIToUTF16(kSDCardDeviceName1), |
| 312 observer().last_attached().name); |
| 313 EXPECT_EQ(mount_path1.value(), observer().last_attached().location); |
| 321 | 314 |
| 322 EXPECT_CALL(observer(), | |
| 323 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) | |
| 324 .InSequence(mock_sequence); | |
| 325 UnmountDevice(MOUNT_ERROR_NONE, mount_info1); | 315 UnmountDevice(MOUNT_ERROR_NONE, mount_info1); |
| 316 EXPECT_EQ(1, observer().detach_calls()); |
| 317 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_detached().device_id); |
| 326 | 318 |
| 327 FilePath mount_path2 = CreateMountPoint(kSDCardMountPoint2, true); | 319 FilePath mount_path2 = CreateMountPoint(kSDCardMountPoint2, true); |
| 328 ASSERT_FALSE(mount_path2.empty()); | 320 ASSERT_FALSE(mount_path2.empty()); |
| 329 DiskMountManager::MountPointInfo mount_info2(kSDCardDeviceName2, | 321 DiskMountManager::MountPointInfo mount_info2(kSDCardDeviceName2, |
| 330 mount_path2.value(), | 322 mount_path2.value(), |
| 331 MOUNT_TYPE_DEVICE, | 323 MOUNT_TYPE_DEVICE, |
| 332 disks::MOUNT_CONDITION_NONE); | 324 disks::MOUNT_CONDITION_NONE); |
| 333 EXPECT_CALL(observer(), | |
| 334 OnRemovableStorageAttached(GetDCIMDeviceId(kUniqueId2), | |
| 335 ASCIIToUTF16(kSDCardDeviceName2), | |
| 336 mount_path2.value())) | |
| 337 .InSequence(mock_sequence); | |
| 338 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kSDCardDeviceName2, | 325 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kSDCardDeviceName2, |
| 339 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); | 326 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); |
| 327 EXPECT_EQ(2, observer().attach_calls()); |
| 328 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_attached().device_id); |
| 329 EXPECT_EQ(ASCIIToUTF16(kSDCardDeviceName2), |
| 330 observer().last_attached().name); |
| 331 EXPECT_EQ(mount_path2.value(), observer().last_attached().location); |
| 340 | 332 |
| 341 EXPECT_CALL(observer(), | |
| 342 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) | |
| 343 .InSequence(mock_sequence); | |
| 344 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | 333 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
| 334 EXPECT_EQ(2, observer().detach_calls()); |
| 335 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_detached().device_id); |
| 345 } | 336 } |
| 346 | 337 |
| 347 TEST_F(RemovableDeviceNotificationsCrosTest, AttachDeviceWithEmptyLabel) { | 338 TEST_F(RemovableDeviceNotificationsCrosTest, AttachDeviceWithEmptyLabel) { |
| 348 testing::Sequence mock_sequence; | |
| 349 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 339 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| 350 ASSERT_FALSE(mount_path1.empty()); | 340 ASSERT_FALSE(mount_path1.empty()); |
| 351 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, | 341 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, |
| 352 mount_path1.value(), | 342 mount_path1.value(), |
| 353 MOUNT_TYPE_DEVICE, | 343 MOUNT_TYPE_DEVICE, |
| 354 disks::MOUNT_CONDITION_NONE); | 344 disks::MOUNT_CONDITION_NONE); |
| 355 EXPECT_CALL(observer(), OnRemovableStorageAttached( | |
| 356 GetDCIMDeviceId(kUniqueId1), | |
| 357 ASCIIToUTF16(kDeviceNameWithManufacturerDetails), | |
| 358 mount_path1.value())) | |
| 359 .InSequence(mock_sequence); | |
| 360 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kEmptyDeviceLabel, | 345 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kEmptyDeviceLabel, |
| 361 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 346 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 347 EXPECT_EQ(1, observer().attach_calls()); |
| 348 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_attached().device_id); |
| 349 EXPECT_EQ(ASCIIToUTF16(kDeviceNameWithManufacturerDetails), |
| 350 observer().last_attached().name); |
| 351 EXPECT_EQ(mount_path1.value(), observer().last_attached().location); |
| 362 | 352 |
| 363 EXPECT_CALL(observer(), | |
| 364 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | |
| 365 .InSequence(mock_sequence); | |
| 366 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 353 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| 354 EXPECT_EQ(1, observer().detach_calls()); |
| 355 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_detached().device_id); |
| 367 } | 356 } |
| 368 | 357 |
| 369 TEST_F(RemovableDeviceNotificationsCrosTest, GetStorageSize) { | 358 TEST_F(RemovableDeviceNotificationsCrosTest, GetStorageSize) { |
| 370 testing::Sequence mock_sequence; | |
| 371 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 359 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| 372 ASSERT_FALSE(mount_path1.empty()); | 360 ASSERT_FALSE(mount_path1.empty()); |
| 373 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, | 361 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, |
| 374 mount_path1.value(), | 362 mount_path1.value(), |
| 375 MOUNT_TYPE_DEVICE, | 363 MOUNT_TYPE_DEVICE, |
| 376 disks::MOUNT_CONDITION_NONE); | 364 disks::MOUNT_CONDITION_NONE); |
| 377 EXPECT_CALL(observer(), OnRemovableStorageAttached( | |
| 378 GetDCIMDeviceId(kUniqueId1), | |
| 379 ASCIIToUTF16(kDeviceNameWithManufacturerDetails), | |
| 380 mount_path1.value())) | |
| 381 .InSequence(mock_sequence); | |
| 382 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kEmptyDeviceLabel, | 365 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kEmptyDeviceLabel, |
| 383 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 366 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 367 EXPECT_EQ(1, observer().attach_calls()); |
| 368 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_attached().device_id); |
| 369 EXPECT_EQ(ASCIIToUTF16(kDeviceNameWithManufacturerDetails), |
| 370 observer().last_attached().name); |
| 371 EXPECT_EQ(mount_path1.value(), observer().last_attached().location); |
| 384 | 372 |
| 385 EXPECT_EQ(kDevice1SizeInBytes, GetDeviceStorageSize(mount_path1.value())); | 373 EXPECT_EQ(kDevice1SizeInBytes, GetDeviceStorageSize(mount_path1.value())); |
| 386 EXPECT_CALL(observer(), | |
| 387 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | |
| 388 .InSequence(mock_sequence); | |
| 389 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 374 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| 375 EXPECT_EQ(1, observer().detach_calls()); |
| 376 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_detached().device_id); |
| 390 } | 377 } |
| 391 | 378 |
| 392 } // namespace | 379 } // namespace |
| 393 | 380 |
| 394 } // namespace chrome | 381 } // namespace chromeos |
| OLD | NEW |