OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/storage_monitor/storage_monitor_chromeos.h" | 5 #include "components/storage_monitor/storage_monitor_chromeos.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
11 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
12 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
13 #include "chromeos/disks/mock_disk_mount_manager.h" | 16 #include "chromeos/disks/mock_disk_mount_manager.h" |
14 #include "components/storage_monitor/mock_removable_storage_observer.h" | 17 #include "components/storage_monitor/mock_removable_storage_observer.h" |
15 #include "components/storage_monitor/removable_device_constants.h" | 18 #include "components/storage_monitor/removable_device_constants.h" |
16 #include "components/storage_monitor/storage_info.h" | 19 #include "components/storage_monitor/storage_info.h" |
17 #include "components/storage_monitor/test_media_transfer_protocol_manager_linux.
h" | 20 #include "components/storage_monitor/test_media_transfer_protocol_manager_linux.
h" |
18 #include "components/storage_monitor/test_storage_monitor.h" | 21 #include "components/storage_monitor/test_storage_monitor.h" |
19 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
(...skipping 17 matching lines...) Expand all Loading... |
37 const char kMountPointB[] = "mnt_b"; | 40 const char kMountPointB[] = "mnt_b"; |
38 const char kSDCardDeviceName1[] = "8.6 MB Amy_SD"; | 41 const char kSDCardDeviceName1[] = "8.6 MB Amy_SD"; |
39 const char kSDCardDeviceName2[] = "8.6 MB SD Card"; | 42 const char kSDCardDeviceName2[] = "8.6 MB SD Card"; |
40 const char kSDCardMountPoint1[] = "media/removable/Amy_SD"; | 43 const char kSDCardMountPoint1[] = "media/removable/Amy_SD"; |
41 const char kSDCardMountPoint2[] = "media/removable/SD Card"; | 44 const char kSDCardMountPoint2[] = "media/removable/SD Card"; |
42 const char kProductName[] = "Z101"; | 45 const char kProductName[] = "Z101"; |
43 const char kUniqueId1[] = "FFFF-FFFF"; | 46 const char kUniqueId1[] = "FFFF-FFFF"; |
44 const char kUniqueId2[] = "FFFF-FF0F"; | 47 const char kUniqueId2[] = "FFFF-FF0F"; |
45 const char kVendorName[] = "CompanyA"; | 48 const char kVendorName[] = "CompanyA"; |
46 | 49 |
47 uint64 kDevice1SizeInBytes = 113048; | 50 uint64_t kDevice1SizeInBytes = 113048; |
48 uint64 kDevice2SizeInBytes = 212312; | 51 uint64_t kDevice2SizeInBytes = 212312; |
49 uint64 kSDCardSizeInBytes = 9000000; | 52 uint64_t kSDCardSizeInBytes = 9000000; |
50 | 53 |
51 std::string GetDCIMDeviceId(const std::string& unique_id) { | 54 std::string GetDCIMDeviceId(const std::string& unique_id) { |
52 return StorageInfo::MakeDeviceId( | 55 return StorageInfo::MakeDeviceId( |
53 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, | 56 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, |
54 kFSUniqueIdPrefix + unique_id); | 57 kFSUniqueIdPrefix + unique_id); |
55 } | 58 } |
56 | 59 |
57 // A test version of StorageMonitorCros that exposes protected methods to tests. | 60 // A test version of StorageMonitorCros that exposes protected methods to tests. |
58 class TestStorageMonitorCros : public StorageMonitorCros { | 61 class TestStorageMonitorCros : public StorageMonitorCros { |
59 public: | 62 public: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 void SetUp() override; | 103 void SetUp() override; |
101 void TearDown() override; | 104 void TearDown() override; |
102 | 105 |
103 void MountDevice(chromeos::MountError error_code, | 106 void MountDevice(chromeos::MountError error_code, |
104 const DiskMountManager::MountPointInfo& mount_info, | 107 const DiskMountManager::MountPointInfo& mount_info, |
105 const std::string& unique_id, | 108 const std::string& unique_id, |
106 const std::string& device_label, | 109 const std::string& device_label, |
107 const std::string& vendor_name, | 110 const std::string& vendor_name, |
108 const std::string& product_name, | 111 const std::string& product_name, |
109 chromeos::DeviceType device_type, | 112 chromeos::DeviceType device_type, |
110 uint64 device_size_in_bytes); | 113 uint64_t device_size_in_bytes); |
111 | 114 |
112 void UnmountDevice(chromeos::MountError error_code, | 115 void UnmountDevice(chromeos::MountError error_code, |
113 const DiskMountManager::MountPointInfo& mount_info); | 116 const DiskMountManager::MountPointInfo& mount_info); |
114 | 117 |
115 uint64 GetDeviceStorageSize(const std::string& device_location); | 118 uint64_t GetDeviceStorageSize(const std::string& device_location); |
116 | 119 |
117 // Create a directory named |dir| relative to the test directory. | 120 // Create a directory named |dir| relative to the test directory. |
118 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 121 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
119 // subdirectory. | 122 // subdirectory. |
120 // Returns the full path to the created directory on success, or an empty | 123 // Returns the full path to the created directory on success, or an empty |
121 // path on failure. | 124 // path on failure. |
122 base::FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir); | 125 base::FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir); |
123 | 126 |
124 static void PostQuitToUIThread(); | 127 static void PostQuitToUIThread(); |
125 static void WaitForFileThread(); | 128 static void WaitForFileThread(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 189 } |
187 | 190 |
188 void StorageMonitorCrosTest::MountDevice( | 191 void StorageMonitorCrosTest::MountDevice( |
189 chromeos::MountError error_code, | 192 chromeos::MountError error_code, |
190 const DiskMountManager::MountPointInfo& mount_info, | 193 const DiskMountManager::MountPointInfo& mount_info, |
191 const std::string& unique_id, | 194 const std::string& unique_id, |
192 const std::string& device_label, | 195 const std::string& device_label, |
193 const std::string& vendor_name, | 196 const std::string& vendor_name, |
194 const std::string& product_name, | 197 const std::string& product_name, |
195 chromeos::DeviceType device_type, | 198 chromeos::DeviceType device_type, |
196 uint64 device_size_in_bytes) { | 199 uint64_t device_size_in_bytes) { |
197 if (error_code == chromeos::MOUNT_ERROR_NONE) { | 200 if (error_code == chromeos::MOUNT_ERROR_NONE) { |
198 disk_mount_manager_mock_->CreateDiskEntryForMountDevice( | 201 disk_mount_manager_mock_->CreateDiskEntryForMountDevice( |
199 mount_info, | 202 mount_info, |
200 unique_id, | 203 unique_id, |
201 device_label, | 204 device_label, |
202 vendor_name, | 205 vendor_name, |
203 product_name, | 206 product_name, |
204 device_type, | 207 device_type, |
205 device_size_in_bytes, | 208 device_size_in_bytes, |
206 false /* is_parent */, | 209 false /* is_parent */, |
207 true /* has_media */, | 210 true /* has_media */, |
208 false /* on_boot_device */, | 211 false /* on_boot_device */, |
209 true /* on_removable_device */); | 212 true /* on_removable_device */); |
210 } | 213 } |
211 monitor_->OnMountEvent(DiskMountManager::MOUNTING, error_code, mount_info); | 214 monitor_->OnMountEvent(DiskMountManager::MOUNTING, error_code, mount_info); |
212 WaitForFileThread(); | 215 WaitForFileThread(); |
213 } | 216 } |
214 | 217 |
215 void StorageMonitorCrosTest::UnmountDevice( | 218 void StorageMonitorCrosTest::UnmountDevice( |
216 chromeos::MountError error_code, | 219 chromeos::MountError error_code, |
217 const DiskMountManager::MountPointInfo& mount_info) { | 220 const DiskMountManager::MountPointInfo& mount_info) { |
218 monitor_->OnMountEvent(DiskMountManager::UNMOUNTING, error_code, mount_info); | 221 monitor_->OnMountEvent(DiskMountManager::UNMOUNTING, error_code, mount_info); |
219 if (error_code == chromeos::MOUNT_ERROR_NONE) | 222 if (error_code == chromeos::MOUNT_ERROR_NONE) |
220 disk_mount_manager_mock_->RemoveDiskEntryForMountDevice(mount_info); | 223 disk_mount_manager_mock_->RemoveDiskEntryForMountDevice(mount_info); |
221 WaitForFileThread(); | 224 WaitForFileThread(); |
222 } | 225 } |
223 | 226 |
224 uint64 StorageMonitorCrosTest::GetDeviceStorageSize( | 227 uint64_t StorageMonitorCrosTest::GetDeviceStorageSize( |
225 const std::string& device_location) { | 228 const std::string& device_location) { |
226 StorageInfo info; | 229 StorageInfo info; |
227 if (!monitor_->GetStorageInfoForPath(base::FilePath(device_location), &info)) | 230 if (!monitor_->GetStorageInfoForPath(base::FilePath(device_location), &info)) |
228 return 0; | 231 return 0; |
229 | 232 |
230 return info.total_size_in_bytes(); | 233 return info.total_size_in_bytes(); |
231 } | 234 } |
232 | 235 |
233 base::FilePath StorageMonitorCrosTest::CreateMountPoint( | 236 base::FilePath StorageMonitorCrosTest::CreateMountPoint( |
234 const std::string& dir, bool with_dcim_dir) { | 237 const std::string& dir, bool with_dcim_dir) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 base::Bind(&StorageMonitorCrosTest::EjectNotify, | 548 base::Bind(&StorageMonitorCrosTest::EjectNotify, |
546 base::Unretained(this))); | 549 base::Unretained(this))); |
547 base::RunLoop().RunUntilIdle(); | 550 base::RunLoop().RunUntilIdle(); |
548 | 551 |
549 EXPECT_EQ(StorageMonitor::EJECT_OK, status_); | 552 EXPECT_EQ(StorageMonitor::EJECT_OK, status_); |
550 } | 553 } |
551 | 554 |
552 } // namespace | 555 } // namespace |
553 | 556 |
554 } // namespace storage_monitor | 557 } // namespace storage_monitor |
OLD | NEW |