OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // TestVolumeMountWatcherWin implementation. | 5 // TestVolumeMountWatcherWin implementation. |
6 | 6 |
7 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h" | 7 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/scoped_temp_dir.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/storage_monitor/storage_info.h" | 13 #include "chrome/browser/storage_monitor/storage_info.h" |
13 | 14 |
14 namespace chrome { | 15 namespace chrome { |
15 namespace test { | 16 namespace test { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
| 20 base::FilePath GetTempRoot() { |
| 21 base::ScopedTempDir temp_dir; |
| 22 temp_dir.CreateUniqueTempDir(); |
| 23 base::FilePath temp_root = temp_dir.path(); |
| 24 while (temp_root.DirName() != temp_root) |
| 25 temp_root = temp_root.DirName(); |
| 26 return temp_root; |
| 27 } |
| 28 |
19 std::vector<base::FilePath> FakeGetSingleAttachedDevice() { | 29 std::vector<base::FilePath> FakeGetSingleAttachedDevice() { |
20 std::vector<base::FilePath> result; | 30 std::vector<base::FilePath> result; |
21 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(2)); // C | 31 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(2)); // C |
| 32 |
| 33 // Make sure we are adding the drive on which ScopedTempDir will make |
| 34 // test directories. |
| 35 base::FilePath temp_root = GetTempRoot(); |
| 36 if (temp_root != VolumeMountWatcherWin::DriveNumberToFilePath(2)) |
| 37 result.push_back(temp_root); |
| 38 |
22 return result; | 39 return result; |
23 } | 40 } |
24 | 41 |
25 std::vector<base::FilePath> FakeGetAttachedDevices() { | 42 std::vector<base::FilePath> FakeGetAttachedDevices() { |
26 std::vector<base::FilePath> result; | 43 std::vector<base::FilePath> result; |
27 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(0)); // A | 44 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(0)); // A |
28 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(1)); // B | 45 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(1)); // B |
29 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(2)); // C | 46 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(2)); // C |
30 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(3)); // D | 47 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(3)); // D |
31 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(5)); // F | 48 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(5)); // F |
(...skipping 12 matching lines...) Expand all Loading... |
44 | 61 |
45 // Truncate to root path. | 62 // Truncate to root path. |
46 base::FilePath path(device_path); | 63 base::FilePath path(device_path); |
47 if (device_path.value().length() > 3) | 64 if (device_path.value().length() > 3) |
48 path = base::FilePath(device_path.value().substr(0, 3)); | 65 path = base::FilePath(device_path.value().substr(0, 3)); |
49 if (path.value()[0] < L'A' || path.value()[0] > L'Z') | 66 if (path.value()[0] < L'A' || path.value()[0] > L'Z') |
50 return false; | 67 return false; |
51 | 68 |
52 StorageInfo::Type type = StorageInfo::FIXED_MASS_STORAGE; | 69 StorageInfo::Type type = StorageInfo::FIXED_MASS_STORAGE; |
53 if (path.value() != ASCIIToUTF16("N:\\") && | 70 if (path.value() != ASCIIToUTF16("N:\\") && |
54 path.value() != ASCIIToUTF16("C:\\")) { | 71 path.value() != ASCIIToUTF16("C:\\") && |
| 72 path.value() != GetTempRoot().value()) { |
55 type = StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; | 73 type = StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; |
56 } | 74 } |
57 std::string unique_id = | 75 std::string unique_id = |
58 "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; | 76 "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; |
59 unique_id[11] = device_path.value()[0]; | 77 unique_id[11] = device_path.value()[0]; |
60 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); | 78 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); |
61 string16 storage_label = path.Append(L" Drive").LossyDisplayName(); | 79 string16 storage_label = path.Append(L" Drive").LossyDisplayName(); |
62 *info = StorageInfo(device_id, string16(), path.value(), storage_label, | 80 *info = StorageInfo(device_id, string16(), path.value(), storage_label, |
63 string16(), string16(), 1000000); | 81 string16(), string16(), 1000000); |
64 | 82 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 149 |
132 return base::Bind(&FakeGetSingleAttachedDevice); | 150 return base::Bind(&FakeGetSingleAttachedDevice); |
133 } | 151 } |
134 | 152 |
135 void TestVolumeMountWatcherWin::ShutdownWorkerPool() { | 153 void TestVolumeMountWatcherWin::ShutdownWorkerPool() { |
136 device_info_worker_pool_->Shutdown(); | 154 device_info_worker_pool_->Shutdown(); |
137 } | 155 } |
138 | 156 |
139 } // namespace test | 157 } // namespace test |
140 } // namespace chrome | 158 } // namespace chrome |
OLD | NEW |