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/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); | |
| 132 system_monitor_.AddDevicesChangedObserver( | |
| 133 mock_devices_changed_observer_.get()); | |
| 134 | |
| 135 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); | 129 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); |
| 136 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | 130 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); |
| 137 disk_mount_manager_mock_->SetupDefaultReplies(); | 131 disk_mount_manager_mock_->SetupDefaultReplies(); |
| 138 | 132 |
| 133 mock_storage_observer_.reset(new chrome::MockRemovableStorageObserver); | |
| 134 | |
| 139 // Initialize the test subject. | 135 // Initialize the test subject. |
| 140 notifications_ = new RemovableDeviceNotificationsCros(); | 136 notifications_ = new RemovableDeviceNotificationsCros(); |
| 137 notifications_->AddObserver(mock_storage_observer_.get()); | |
| 141 } | 138 } |
| 142 | 139 |
| 143 void RemovableDeviceNotificationsCrosTest::TearDown() { | 140 void RemovableDeviceNotificationsCrosTest::TearDown() { |
| 141 notifications_->RemoveObserver(mock_storage_observer_.get()); | |
| 144 notifications_ = NULL; | 142 notifications_ = NULL; |
| 143 | |
| 145 disk_mount_manager_mock_ = NULL; | 144 disk_mount_manager_mock_ = NULL; |
| 146 DiskMountManager::Shutdown(); | 145 DiskMountManager::Shutdown(); |
| 147 system_monitor_.RemoveDevicesChangedObserver( | |
| 148 mock_devices_changed_observer_.get()); | |
| 149 WaitForFileThread(); | 146 WaitForFileThread(); |
| 150 } | 147 } |
| 151 | 148 |
| 152 void RemovableDeviceNotificationsCrosTest::MountDevice( | 149 void RemovableDeviceNotificationsCrosTest::MountDevice( |
| 153 MountError error_code, | 150 MountError error_code, |
| 154 const DiskMountManager::MountPointInfo& mount_info, | 151 const DiskMountManager::MountPointInfo& mount_info, |
| 155 const std::string& unique_id, | 152 const std::string& unique_id, |
| 156 const std::string& device_label, | 153 const std::string& device_label, |
| 157 const std::string& vendor_name, | 154 const std::string& vendor_name, |
| 158 const std::string& product_name, | 155 const std::string& product_name, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 | 202 |
| 206 // static | 203 // static |
| 207 void RemovableDeviceNotificationsCrosTest::WaitForFileThread() { | 204 void RemovableDeviceNotificationsCrosTest::WaitForFileThread() { |
| 208 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 205 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 209 base::Bind(&PostQuitToUIThread)); | 206 base::Bind(&PostQuitToUIThread)); |
| 210 MessageLoop::current()->Run(); | 207 MessageLoop::current()->Run(); |
| 211 } | 208 } |
| 212 | 209 |
| 213 // Simple test case where we attach and detach a media device. | 210 // Simple test case where we attach and detach a media device. |
| 214 TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { | 211 TEST_F(RemovableDeviceNotificationsCrosTest, BasicAttachDetach) { |
| 215 testing::Sequence mock_sequence; | |
| 216 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 212 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| 217 ASSERT_FALSE(mount_path1.empty()); | 213 ASSERT_FALSE(mount_path1.empty()); |
| 218 DiskMountManager::MountPointInfo mount_info(kDevice1, | 214 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 219 mount_path1.value(), | 215 mount_path1.value(), |
| 220 MOUNT_TYPE_DEVICE, | 216 MOUNT_TYPE_DEVICE, |
| 221 disks::MOUNT_CONDITION_NONE); | 217 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, | 218 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kDevice1Name, |
| 228 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 219 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 220 EXPECT_EQ(1, observer().attach_calls()); | |
| 221 EXPECT_EQ(0, observer().detach_calls()); | |
| 222 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_attached().device_id); | |
| 223 EXPECT_EQ(ASCIIToUTF16(kDevice1NameWithSizeInfo), | |
| 224 observer().last_attached().name); | |
| 225 EXPECT_EQ(mount_path1.value(), observer().last_attached().location); | |
| 229 | 226 |
| 230 EXPECT_CALL(observer(), | |
| 231 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | |
| 232 .InSequence(mock_sequence); | |
| 233 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 227 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| 228 EXPECT_EQ(1, observer().attach_calls()); | |
| 229 EXPECT_EQ(1, observer().detach_calls()); | |
| 230 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_detached().device_id); | |
| 234 | 231 |
| 235 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); | 232 FilePath mount_path2 = CreateMountPoint(kMountPointB, true); |
| 236 ASSERT_FALSE(mount_path2.empty()); | 233 ASSERT_FALSE(mount_path2.empty()); |
| 237 DiskMountManager::MountPointInfo mount_info2(kDevice2, | 234 DiskMountManager::MountPointInfo mount_info2(kDevice2, |
| 238 mount_path2.value(), | 235 mount_path2.value(), |
| 239 MOUNT_TYPE_DEVICE, | 236 MOUNT_TYPE_DEVICE, |
| 240 disks::MOUNT_CONDITION_NONE); | 237 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, | 238 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kDevice2Name, |
| 247 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice2SizeInBytes); | 239 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice2SizeInBytes); |
| 240 EXPECT_EQ(2, observer().attach_calls()); | |
| 241 EXPECT_EQ(1, observer().detach_calls()); | |
|
Greg Billock
2013/01/25 20:01:21
Had copy-pasted this wrong...
| |
| 242 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_attached().device_id); | |
| 243 EXPECT_EQ(ASCIIToUTF16(kDevice2NameWithSizeInfo), | |
| 244 observer().last_attached().name); | |
| 245 EXPECT_EQ(mount_path2.value(), observer().last_attached().location); | |
| 248 | 246 |
| 249 EXPECT_CALL(observer(), | |
| 250 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) | |
| 251 .InSequence(mock_sequence); | |
| 252 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | 247 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
| 248 EXPECT_EQ(2, observer().attach_calls()); | |
| 249 EXPECT_EQ(2, observer().detach_calls()); | |
| 250 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_detached().device_id); | |
| 253 } | 251 } |
| 254 | 252 |
| 255 // Removable mass storage devices with no dcim folder are also recognized. | 253 // Removable mass storage devices with no dcim folder are also recognized. |
| 256 TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { | 254 TEST_F(RemovableDeviceNotificationsCrosTest, NoDCIM) { |
| 257 testing::Sequence mock_sequence; | 255 testing::Sequence mock_sequence; |
| 258 FilePath mount_path = CreateMountPoint(kMountPointA, false); | 256 FilePath mount_path = CreateMountPoint(kMountPointA, false); |
| 259 const std::string kUniqueId = "FFFF-FFFF"; | 257 const std::string kUniqueId = "FFFF-FFFF"; |
| 260 ASSERT_FALSE(mount_path.empty()); | 258 ASSERT_FALSE(mount_path.empty()); |
| 261 DiskMountManager::MountPointInfo mount_info(kDevice1, | 259 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 262 mount_path.value(), | 260 mount_path.value(), |
| 263 MOUNT_TYPE_DEVICE, | 261 MOUNT_TYPE_DEVICE, |
| 264 disks::MOUNT_CONDITION_NONE); | 262 disks::MOUNT_CONDITION_NONE); |
| 265 const std::string device_id = chrome::MediaStorageUtil::MakeDeviceId( | 263 const std::string device_id = chrome::MediaStorageUtil::MakeDeviceId( |
| 266 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, | 264 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, |
| 267 chrome::kFSUniqueIdPrefix + kUniqueId); | 265 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, | 266 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 273 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 267 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 268 EXPECT_EQ(1, observer().attach_calls()); | |
| 269 EXPECT_EQ(0, observer().detach_calls()); | |
| 270 EXPECT_EQ(device_id, observer().last_attached().device_id); | |
| 271 EXPECT_EQ(ASCIIToUTF16(kDevice1NameWithSizeInfo), | |
| 272 observer().last_attached().name); | |
| 273 EXPECT_EQ(mount_path.value(), observer().last_attached().location); | |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Non device mounts and mount errors are ignored. | 276 // Non device mounts and mount errors are ignored. |
| 277 TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { | 277 TEST_F(RemovableDeviceNotificationsCrosTest, Ignore) { |
| 278 testing::Sequence mock_sequence; | 278 testing::Sequence mock_sequence; |
| 279 FilePath mount_path = CreateMountPoint(kMountPointA, true); | 279 FilePath mount_path = CreateMountPoint(kMountPointA, true); |
| 280 const std::string kUniqueId = "FFFF-FFFF"; | 280 const std::string kUniqueId = "FFFF-FFFF"; |
| 281 ASSERT_FALSE(mount_path.empty()); | 281 ASSERT_FALSE(mount_path.empty()); |
| 282 | 282 |
| 283 // Mount error. | 283 // Mount error. |
| 284 DiskMountManager::MountPointInfo mount_info(kDevice1, | 284 DiskMountManager::MountPointInfo mount_info(kDevice1, |
| 285 mount_path.value(), | 285 mount_path.value(), |
| 286 MOUNT_TYPE_DEVICE, | 286 MOUNT_TYPE_DEVICE, |
| 287 disks::MOUNT_CONDITION_NONE); | 287 disks::MOUNT_CONDITION_NONE); |
| 288 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
| 289 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name, | 288 MountDevice(MOUNT_ERROR_UNKNOWN, mount_info, kUniqueId, kDevice1Name, |
| 290 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 289 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 290 EXPECT_EQ(0, observer().attach_calls()); | |
| 291 EXPECT_EQ(0, observer().detach_calls()); | |
| 291 | 292 |
| 292 // Not a device | 293 // Not a device |
| 293 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; | 294 mount_info.mount_type = MOUNT_TYPE_ARCHIVE; |
| 294 EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); | |
| 295 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, | 295 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 296 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 296 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 297 EXPECT_EQ(0, observer().attach_calls()); | |
| 298 EXPECT_EQ(0, observer().detach_calls()); | |
| 297 | 299 |
| 298 // Unsupported file system. | 300 // Unsupported file system. |
| 299 mount_info.mount_type = MOUNT_TYPE_DEVICE; | 301 mount_info.mount_type = MOUNT_TYPE_DEVICE; |
| 300 mount_info.mount_condition = disks::MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; | 302 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, | 303 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId, kDevice1Name, |
| 303 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 304 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 305 EXPECT_EQ(0, observer().attach_calls()); | |
| 306 EXPECT_EQ(0, observer().detach_calls()); | |
| 304 } | 307 } |
| 305 | 308 |
| 306 TEST_F(RemovableDeviceNotificationsCrosTest, SDCardAttachDetach) { | 309 TEST_F(RemovableDeviceNotificationsCrosTest, SDCardAttachDetach) { |
| 307 testing::Sequence mock_sequence; | |
| 308 FilePath mount_path1 = CreateMountPoint(kSDCardMountPoint1, true); | 310 FilePath mount_path1 = CreateMountPoint(kSDCardMountPoint1, true); |
| 309 ASSERT_FALSE(mount_path1.empty()); | 311 ASSERT_FALSE(mount_path1.empty()); |
| 310 DiskMountManager::MountPointInfo mount_info1(kSDCardDeviceName1, | 312 DiskMountManager::MountPointInfo mount_info1(kSDCardDeviceName1, |
| 311 mount_path1.value(), | 313 mount_path1.value(), |
| 312 MOUNT_TYPE_DEVICE, | 314 MOUNT_TYPE_DEVICE, |
| 313 disks::MOUNT_CONDITION_NONE); | 315 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, | 316 MountDevice(MOUNT_ERROR_NONE, mount_info1, kUniqueId2, kSDCardDeviceName1, |
| 320 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); | 317 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); |
| 318 EXPECT_EQ(1, observer().attach_calls()); | |
| 319 EXPECT_EQ(0, observer().detach_calls()); | |
| 320 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_attached().device_id); | |
| 321 EXPECT_EQ(ASCIIToUTF16(kSDCardDeviceName1), | |
| 322 observer().last_attached().name); | |
| 323 EXPECT_EQ(mount_path1.value(), observer().last_attached().location); | |
| 321 | 324 |
| 322 EXPECT_CALL(observer(), | |
| 323 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) | |
| 324 .InSequence(mock_sequence); | |
| 325 UnmountDevice(MOUNT_ERROR_NONE, mount_info1); | 325 UnmountDevice(MOUNT_ERROR_NONE, mount_info1); |
| 326 EXPECT_EQ(1, observer().attach_calls()); | |
| 327 EXPECT_EQ(1, observer().detach_calls()); | |
| 328 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_detached().device_id); | |
| 326 | 329 |
| 327 FilePath mount_path2 = CreateMountPoint(kSDCardMountPoint2, true); | 330 FilePath mount_path2 = CreateMountPoint(kSDCardMountPoint2, true); |
| 328 ASSERT_FALSE(mount_path2.empty()); | 331 ASSERT_FALSE(mount_path2.empty()); |
| 329 DiskMountManager::MountPointInfo mount_info2(kSDCardDeviceName2, | 332 DiskMountManager::MountPointInfo mount_info2(kSDCardDeviceName2, |
| 330 mount_path2.value(), | 333 mount_path2.value(), |
| 331 MOUNT_TYPE_DEVICE, | 334 MOUNT_TYPE_DEVICE, |
| 332 disks::MOUNT_CONDITION_NONE); | 335 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, | 336 MountDevice(MOUNT_ERROR_NONE, mount_info2, kUniqueId2, kSDCardDeviceName2, |
| 339 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); | 337 kVendorName, kProductName, DEVICE_TYPE_SD, kSDCardSizeInBytes); |
| 338 EXPECT_EQ(2, observer().attach_calls()); | |
| 339 EXPECT_EQ(1, observer().detach_calls()); | |
| 340 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_attached().device_id); | |
| 341 EXPECT_EQ(ASCIIToUTF16(kSDCardDeviceName2), | |
| 342 observer().last_attached().name); | |
| 343 EXPECT_EQ(mount_path2.value(), observer().last_attached().location); | |
| 340 | 344 |
| 341 EXPECT_CALL(observer(), | |
| 342 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId2))) | |
| 343 .InSequence(mock_sequence); | |
| 344 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); | 345 UnmountDevice(MOUNT_ERROR_NONE, mount_info2); |
| 346 EXPECT_EQ(2, observer().attach_calls()); | |
| 347 EXPECT_EQ(2, observer().detach_calls()); | |
| 348 EXPECT_EQ(GetDCIMDeviceId(kUniqueId2), observer().last_detached().device_id); | |
| 345 } | 349 } |
| 346 | 350 |
| 347 TEST_F(RemovableDeviceNotificationsCrosTest, AttachDeviceWithEmptyLabel) { | 351 TEST_F(RemovableDeviceNotificationsCrosTest, AttachDeviceWithEmptyLabel) { |
| 348 testing::Sequence mock_sequence; | |
| 349 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 352 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| 350 ASSERT_FALSE(mount_path1.empty()); | 353 ASSERT_FALSE(mount_path1.empty()); |
| 351 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, | 354 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, |
| 352 mount_path1.value(), | 355 mount_path1.value(), |
| 353 MOUNT_TYPE_DEVICE, | 356 MOUNT_TYPE_DEVICE, |
| 354 disks::MOUNT_CONDITION_NONE); | 357 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, | 358 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kEmptyDeviceLabel, |
| 361 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 359 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 360 EXPECT_EQ(1, observer().attach_calls()); | |
| 361 EXPECT_EQ(0, observer().detach_calls()); | |
| 362 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_attached().device_id); | |
| 363 EXPECT_EQ(ASCIIToUTF16(kDeviceNameWithManufacturerDetails), | |
| 364 observer().last_attached().name); | |
| 365 EXPECT_EQ(mount_path1.value(), observer().last_attached().location); | |
| 362 | 366 |
| 363 EXPECT_CALL(observer(), | |
| 364 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | |
| 365 .InSequence(mock_sequence); | |
| 366 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 367 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| 368 EXPECT_EQ(1, observer().attach_calls()); | |
| 369 EXPECT_EQ(1, observer().detach_calls()); | |
| 370 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_detached().device_id); | |
| 367 } | 371 } |
| 368 | 372 |
| 369 TEST_F(RemovableDeviceNotificationsCrosTest, GetStorageSize) { | 373 TEST_F(RemovableDeviceNotificationsCrosTest, GetStorageSize) { |
| 370 testing::Sequence mock_sequence; | |
| 371 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); | 374 FilePath mount_path1 = CreateMountPoint(kMountPointA, true); |
| 372 ASSERT_FALSE(mount_path1.empty()); | 375 ASSERT_FALSE(mount_path1.empty()); |
| 373 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, | 376 DiskMountManager::MountPointInfo mount_info(kEmptyDeviceLabel, |
| 374 mount_path1.value(), | 377 mount_path1.value(), |
| 375 MOUNT_TYPE_DEVICE, | 378 MOUNT_TYPE_DEVICE, |
| 376 disks::MOUNT_CONDITION_NONE); | 379 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, | 380 MountDevice(MOUNT_ERROR_NONE, mount_info, kUniqueId1, kEmptyDeviceLabel, |
| 383 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); | 381 kVendorName, kProductName, DEVICE_TYPE_USB, kDevice1SizeInBytes); |
| 382 EXPECT_EQ(1, observer().attach_calls()); | |
| 383 EXPECT_EQ(0, observer().detach_calls()); | |
| 384 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_attached().device_id); | |
| 385 EXPECT_EQ(ASCIIToUTF16(kDeviceNameWithManufacturerDetails), | |
| 386 observer().last_attached().name); | |
| 387 EXPECT_EQ(mount_path1.value(), observer().last_attached().location); | |
| 384 | 388 |
| 385 EXPECT_EQ(kDevice1SizeInBytes, GetDeviceStorageSize(mount_path1.value())); | 389 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); | 390 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| 391 EXPECT_EQ(1, observer().attach_calls()); | |
| 392 EXPECT_EQ(1, observer().detach_calls()); | |
| 393 EXPECT_EQ(GetDCIMDeviceId(kUniqueId1), observer().last_detached().device_id); | |
| 390 } | 394 } |
| 391 | 395 |
| 392 } // namespace | 396 } // namespace |
| 393 | 397 |
| 394 } // namespace chrome | 398 } // namespace chromeos |
| OLD | NEW |