Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1146)

Side by Side Diff: chrome/browser/storage_monitor/test_volume_mount_watcher_win.cc

Issue 15767005: [MediaGalleries] Add temp dir adjustment in windows unit test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/storage_monitor/storage_monitor_win_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
19 std::vector<base::FilePath> FakeGetSingleAttachedDevice() { 20 std::vector<base::FilePath> FakeGetSingleAttachedDevice() {
20 std::vector<base::FilePath> result; 21 std::vector<base::FilePath> result;
21 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(2)); // C 22 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(2)); // C
23
24 // Make sure we are adding the drive on which ScopedTempDir will make
25 // test directories.
26 base::ScopedTempDir temp_dir;
27 temp_dir.CreateUniqueTempDir();
28 base::FilePath temp_root = temp_dir.path();
29 while (temp_root.DirName() != temp_root)
30 temp_root = temp_root.DirName();
31 if (temp_root != VolumeMountWatcherWin::DriveNumberToFilePath(2))
32 result.push_back(temp_root);
33
22 return result; 34 return result;
23 } 35 }
24 36
25 std::vector<base::FilePath> FakeGetAttachedDevices() { 37 std::vector<base::FilePath> FakeGetAttachedDevices() {
26 std::vector<base::FilePath> result; 38 std::vector<base::FilePath> result;
27 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(0)); // A 39 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(0)); // A
28 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(1)); // B 40 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(1)); // B
29 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(2)); // C 41 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(2)); // C
30 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(3)); // D 42 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(3)); // D
31 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(5)); // F 43 result.push_back(VolumeMountWatcherWin::DriveNumberToFilePath(5)); // F
(...skipping 10 matching lines...) Expand all
42 StorageInfo* info) { 54 StorageInfo* info) {
43 // Truncate to root path. 55 // Truncate to root path.
44 base::FilePath path(device_path); 56 base::FilePath path(device_path);
45 if (device_path.value().length() > 3) { 57 if (device_path.value().length() > 3) {
46 path = base::FilePath(device_path.value().substr(0, 3)); 58 path = base::FilePath(device_path.value().substr(0, 3));
47 } 59 }
48 if (path.value()[0] < L'A' || path.value()[0] > L'Z') { 60 if (path.value()[0] < L'A' || path.value()[0] > L'Z') {
49 return false; 61 return false;
50 } 62 }
51 63
64 base::ScopedTempDir temp_dir;
vandebo (ex-Chrome) 2013/05/28 16:10:43 nit: looks like this chunk could get pull into a h
Greg Billock 2013/05/29 17:23:59 Yeah, I pondered that. I'll go ahead and do it.
65 temp_dir.CreateUniqueTempDir();
66 base::FilePath temp_root = temp_dir.path();
67 while (temp_root.DirName() != temp_root)
68 temp_root = temp_root.DirName();
69
52 if (info) { 70 if (info) {
53 info->location = path.value(); 71 info->location = path.value();
54 info->total_size_in_bytes = 1000000; 72 info->total_size_in_bytes = 1000000;
55 73
56 std::string unique_id = 74 std::string unique_id =
57 "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; 75 "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\";
58 unique_id[11] = device_path.value()[0]; 76 unique_id[11] = device_path.value()[0];
59 chrome::StorageInfo::Type type = chrome::StorageInfo::FIXED_MASS_STORAGE; 77 chrome::StorageInfo::Type type = chrome::StorageInfo::FIXED_MASS_STORAGE;
60 if (path.value() != ASCIIToUTF16("N:\\") && 78 if (path.value() != ASCIIToUTF16("N:\\") &&
61 path.value() != ASCIIToUTF16("C:\\")) { 79 path.value() != ASCIIToUTF16("C:\\") &&
80 path.value() != temp_root.value()) {
62 type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; 81 type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM;
63 } 82 }
64 info->device_id = chrome::StorageInfo::MakeDeviceId(type, unique_id); 83 info->device_id = chrome::StorageInfo::MakeDeviceId(type, unique_id);
65 info->storage_label = path.Append(L" Drive").LossyDisplayName(); 84 info->storage_label = path.Append(L" Drive").LossyDisplayName();
66 } 85 }
67 86
68 return true; 87 return true;
69 } 88 }
70 89
71 } // namespace 90 } // namespace
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 156
138 return base::Bind(&FakeGetSingleAttachedDevice); 157 return base::Bind(&FakeGetSingleAttachedDevice);
139 } 158 }
140 159
141 void TestVolumeMountWatcherWin::ShutdownWorkerPool() { 160 void TestVolumeMountWatcherWin::ShutdownWorkerPool() {
142 device_info_worker_pool_->Shutdown(); 161 device_info_worker_pool_->Shutdown();
143 } 162 }
144 163
145 } // namespace test 164 } // namespace test
146 } // namespace chrome 165 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/storage_monitor/storage_monitor_win_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698