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 // StorageMonitorLinux unit tests. | 5 // StorageMonitorLinux unit tests. |
6 | 6 |
7 #include "components/storage_monitor/storage_monitor_linux.h" | 7 #include "components/storage_monitor/storage_monitor_linux.h" |
8 | 8 |
9 #include <mntent.h> | 9 #include <mntent.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 }; | 160 }; |
161 | 161 |
162 StorageMonitorLinuxTest() | 162 StorageMonitorLinuxTest() |
163 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} | 163 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
164 ~StorageMonitorLinuxTest() override {} | 164 ~StorageMonitorLinuxTest() override {} |
165 | 165 |
166 protected: | 166 protected: |
167 void SetUp() override { | 167 void SetUp() override { |
168 // Create and set up a temp dir with files for the test. | 168 // Create and set up a temp dir with files for the test. |
169 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 169 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
170 base::FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc"); | 170 base::FilePath test_dir = |
| 171 scoped_temp_dir_.GetPath().AppendASCII("test_etc"); |
171 ASSERT_TRUE(base::CreateDirectory(test_dir)); | 172 ASSERT_TRUE(base::CreateDirectory(test_dir)); |
172 mtab_file_ = test_dir.AppendASCII("test_mtab"); | 173 mtab_file_ = test_dir.AppendASCII("test_mtab"); |
173 MtabTestData initial_test_data[] = { | 174 MtabTestData initial_test_data[] = { |
174 MtabTestData("dummydevice", "dummydir", kInvalidFS), | 175 MtabTestData("dummydevice", "dummydir", kInvalidFS), |
175 }; | 176 }; |
176 WriteToMtab(initial_test_data, | 177 WriteToMtab(initial_test_data, |
177 arraysize(initial_test_data), | 178 arraysize(initial_test_data), |
178 true /* overwrite */); | 179 true /* overwrite */); |
179 | 180 |
180 monitor_.reset(new TestStorageMonitorLinux(mtab_file_)); | 181 monitor_.reset(new TestStorageMonitorLinux(mtab_file_)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 226 |
226 // Create a directory named |dir| relative to the test directory. | 227 // Create a directory named |dir| relative to the test directory. |
227 // It does not have a DCIM directory, so StorageMonitorLinux does not | 228 // It does not have a DCIM directory, so StorageMonitorLinux does not |
228 // recognize it as a media directory. | 229 // recognize it as a media directory. |
229 base::FilePath CreateMountPointWithoutDCIMDir(const std::string& dir) { | 230 base::FilePath CreateMountPointWithoutDCIMDir(const std::string& dir) { |
230 return CreateMountPoint(dir, false /* do not create DCIM dir */); | 231 return CreateMountPoint(dir, false /* do not create DCIM dir */); |
231 } | 232 } |
232 | 233 |
233 void RemoveDCIMDirFromMountPoint(const std::string& dir) { | 234 void RemoveDCIMDirFromMountPoint(const std::string& dir) { |
234 base::FilePath dcim = | 235 base::FilePath dcim = |
235 scoped_temp_dir_.path().AppendASCII(dir).Append(kDCIMDirectoryName); | 236 scoped_temp_dir_.GetPath().AppendASCII(dir).Append(kDCIMDirectoryName); |
236 base::DeleteFile(dcim, false); | 237 base::DeleteFile(dcim, false); |
237 } | 238 } |
238 | 239 |
239 MockRemovableStorageObserver& observer() { | 240 MockRemovableStorageObserver& observer() { |
240 return *mock_storage_observer_; | 241 return *mock_storage_observer_; |
241 } | 242 } |
242 | 243 |
243 StorageMonitor* notifier() { | 244 StorageMonitor* notifier() { |
244 return monitor_.get(); | 245 return monitor_.get(); |
245 } | 246 } |
246 | 247 |
247 uint64_t GetStorageSize(const base::FilePath& path) { | 248 uint64_t GetStorageSize(const base::FilePath& path) { |
248 StorageInfo info; | 249 StorageInfo info; |
249 if (!notifier()->GetStorageInfoForPath(path, &info)) | 250 if (!notifier()->GetStorageInfoForPath(path, &info)) |
250 return 0; | 251 return 0; |
251 | 252 |
252 return info.total_size_in_bytes(); | 253 return info.total_size_in_bytes(); |
253 } | 254 } |
254 | 255 |
255 private: | 256 private: |
256 // Create a directory named |dir| relative to the test directory. | 257 // Create a directory named |dir| relative to the test directory. |
257 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 258 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
258 // subdirectory. | 259 // subdirectory. |
259 // Returns the full path to the created directory on success, or an empty | 260 // Returns the full path to the created directory on success, or an empty |
260 // path on failure. | 261 // path on failure. |
261 base::FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { | 262 base::FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { |
262 base::FilePath return_path(scoped_temp_dir_.path()); | 263 base::FilePath return_path(scoped_temp_dir_.GetPath()); |
263 return_path = return_path.AppendASCII(dir); | 264 return_path = return_path.AppendASCII(dir); |
264 base::FilePath path(return_path); | 265 base::FilePath path(return_path); |
265 if (with_dcim_dir) | 266 if (with_dcim_dir) |
266 path = path.Append(kDCIMDirectoryName); | 267 path = path.Append(kDCIMDirectoryName); |
267 if (!base::CreateDirectory(path)) | 268 if (!base::CreateDirectory(path)) |
268 return base::FilePath(); | 269 return base::FilePath(); |
269 return return_path; | 270 return return_path; |
270 } | 271 } |
271 | 272 |
272 // Write the test mtab data to |mtab_file_|. | 273 // Write the test mtab data to |mtab_file_|. |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 GetStorageSize(test_path_a)); | 681 GetStorageSize(test_path_a)); |
681 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), | 682 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), |
682 GetStorageSize(test_path_b)); | 683 GetStorageSize(test_path_b)); |
683 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), | 684 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), |
684 GetStorageSize(base::FilePath(kInvalidPath))); | 685 GetStorageSize(base::FilePath(kInvalidPath))); |
685 } | 686 } |
686 | 687 |
687 } // namespace | 688 } // namespace |
688 | 689 |
689 } // namespace storage_monitor | 690 } // namespace storage_monitor |
OLD | NEW |