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> |
| 11 #include <stdint.h> |
10 #include <stdio.h> | 12 #include <stdio.h> |
11 | 13 |
12 #include <string> | 14 #include <string> |
13 | 15 |
14 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
15 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
16 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
18 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
19 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
20 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
21 #include "components/storage_monitor/mock_removable_storage_observer.h" | 24 #include "components/storage_monitor/mock_removable_storage_observer.h" |
22 #include "components/storage_monitor/removable_device_constants.h" | 25 #include "components/storage_monitor/removable_device_constants.h" |
23 #include "components/storage_monitor/storage_info.h" | 26 #include "components/storage_monitor/storage_info.h" |
24 #include "components/storage_monitor/storage_monitor.h" | 27 #include "components/storage_monitor/storage_monitor.h" |
25 #include "components/storage_monitor/test_media_transfer_protocol_manager_linux.
h" | 28 #include "components/storage_monitor/test_media_transfer_protocol_manager_linux.
h" |
26 #include "components/storage_monitor/test_storage_monitor.h" | 29 #include "components/storage_monitor/test_storage_monitor.h" |
(...skipping 18 matching lines...) Expand all Loading... |
45 const char kInvalidDevice[] = "invalid_device"; | 48 const char kInvalidDevice[] = "invalid_device"; |
46 | 49 |
47 const char kMountPointA[] = "mnt_a"; | 50 const char kMountPointA[] = "mnt_a"; |
48 const char kMountPointB[] = "mnt_b"; | 51 const char kMountPointB[] = "mnt_b"; |
49 const char kMountPointC[] = "mnt_c"; | 52 const char kMountPointC[] = "mnt_c"; |
50 | 53 |
51 struct TestDeviceData { | 54 struct TestDeviceData { |
52 const char* device_path; | 55 const char* device_path; |
53 const char* unique_id; | 56 const char* unique_id; |
54 StorageInfo::Type type; | 57 StorageInfo::Type type; |
55 uint64 partition_size_in_bytes; | 58 uint64_t partition_size_in_bytes; |
56 }; | 59 }; |
57 | 60 |
58 const TestDeviceData kTestDeviceData[] = { | 61 const TestDeviceData kTestDeviceData[] = { |
59 { kDeviceDCIM1, "UUID:FFF0-000F", | 62 { kDeviceDCIM1, "UUID:FFF0-000F", |
60 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, 88788 }, | 63 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, 88788 }, |
61 { kDeviceDCIM2, "VendorModelSerial:ComName:Model2010:8989", | 64 { kDeviceDCIM2, "VendorModelSerial:ComName:Model2010:8989", |
62 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, | 65 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, |
63 8773 }, | 66 8773 }, |
64 { kDeviceDCIM3, "VendorModelSerial:::WEM319X792", | 67 { kDeviceDCIM3, "VendorModelSerial:::WEM319X792", |
65 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, 22837 }, | 68 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, 22837 }, |
(...skipping 24 matching lines...) Expand all Loading... |
90 storage_info.reset(new StorageInfo( | 93 storage_info.reset(new StorageInfo( |
91 StorageInfo::MakeDeviceId(type, kTestDeviceData[i].unique_id), | 94 StorageInfo::MakeDeviceId(type, kTestDeviceData[i].unique_id), |
92 mount_point.value(), | 95 mount_point.value(), |
93 base::ASCIIToUTF16("volume label"), | 96 base::ASCIIToUTF16("volume label"), |
94 base::ASCIIToUTF16("vendor name"), | 97 base::ASCIIToUTF16("vendor name"), |
95 base::ASCIIToUTF16("model name"), | 98 base::ASCIIToUTF16("model name"), |
96 kTestDeviceData[i].partition_size_in_bytes)); | 99 kTestDeviceData[i].partition_size_in_bytes)); |
97 return storage_info.Pass(); | 100 return storage_info.Pass(); |
98 } | 101 } |
99 | 102 |
100 uint64 GetDevicePartitionSize(const std::string& device) { | 103 uint64_t GetDevicePartitionSize(const std::string& device) { |
101 for (size_t i = 0; i < arraysize(kTestDeviceData); ++i) { | 104 for (size_t i = 0; i < arraysize(kTestDeviceData); ++i) { |
102 if (device == kTestDeviceData[i].device_path) | 105 if (device == kTestDeviceData[i].device_path) |
103 return kTestDeviceData[i].partition_size_in_bytes; | 106 return kTestDeviceData[i].partition_size_in_bytes; |
104 } | 107 } |
105 return 0; | 108 return 0; |
106 } | 109 } |
107 | 110 |
108 std::string GetDeviceId(const std::string& device) { | 111 std::string GetDeviceId(const std::string& device) { |
109 for (size_t i = 0; i < arraysize(kTestDeviceData); ++i) { | 112 for (size_t i = 0; i < arraysize(kTestDeviceData); ++i) { |
110 if (device == kTestDeviceData[i].device_path) { | 113 if (device == kTestDeviceData[i].device_path) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 237 } |
235 | 238 |
236 MockRemovableStorageObserver& observer() { | 239 MockRemovableStorageObserver& observer() { |
237 return *mock_storage_observer_; | 240 return *mock_storage_observer_; |
238 } | 241 } |
239 | 242 |
240 StorageMonitor* notifier() { | 243 StorageMonitor* notifier() { |
241 return monitor_.get(); | 244 return monitor_.get(); |
242 } | 245 } |
243 | 246 |
244 uint64 GetStorageSize(const base::FilePath& path) { | 247 uint64_t GetStorageSize(const base::FilePath& path) { |
245 StorageInfo info; | 248 StorageInfo info; |
246 if (!notifier()->GetStorageInfoForPath(path, &info)) | 249 if (!notifier()->GetStorageInfoForPath(path, &info)) |
247 return 0; | 250 return 0; |
248 | 251 |
249 return info.total_size_in_bytes(); | 252 return info.total_size_in_bytes(); |
250 } | 253 } |
251 | 254 |
252 private: | 255 private: |
253 // Create a directory named |dir| relative to the test directory. | 256 // Create a directory named |dir| relative to the test directory. |
254 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 257 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 GetStorageSize(test_path_a)); | 680 GetStorageSize(test_path_a)); |
678 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), | 681 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), |
679 GetStorageSize(test_path_b)); | 682 GetStorageSize(test_path_b)); |
680 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), | 683 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), |
681 GetStorageSize(base::FilePath(kInvalidPath))); | 684 GetStorageSize(base::FilePath(kInvalidPath))); |
682 } | 685 } |
683 | 686 |
684 } // namespace | 687 } // namespace |
685 | 688 |
686 } // namespace storage_monitor | 689 } // namespace storage_monitor |
OLD | NEW |