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

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

Issue 12382005: Rename RemovableDeviceNotifications=>StorageMonitor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix some includes from recent merge. Created 7 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <windows.h> 5 #include <windows.h>
6 #include <dbt.h> 6 #include <dbt.h>
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/storage_monitor/media_storage_util.h" 16 #include "chrome/browser/storage_monitor/media_storage_util.h"
17 #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h" 17 #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h"
18 #include "chrome/browser/storage_monitor/portable_device_watcher_win.h" 18 #include "chrome/browser/storage_monitor/portable_device_watcher_win.h"
19 #include "chrome/browser/storage_monitor/removable_device_constants.h" 19 #include "chrome/browser/storage_monitor/removable_device_constants.h"
20 #include "chrome/browser/storage_monitor/removable_device_notifications_window_w in.h" 20 #include "chrome/browser/storage_monitor/storage_monitor_win.h"
21 #include "chrome/browser/storage_monitor/test_portable_device_watcher_win.h" 21 #include "chrome/browser/storage_monitor/test_portable_device_watcher_win.h"
22 #include "chrome/browser/storage_monitor/test_removable_device_notifications_win dow_win.h" 22 #include "chrome/browser/storage_monitor/test_storage_monitor_win.h"
23 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h" 23 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h"
24 #include "chrome/browser/storage_monitor/volume_mount_watcher_win.h" 24 #include "chrome/browser/storage_monitor/volume_mount_watcher_win.h"
25 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 namespace chrome { 28 namespace chrome {
29 namespace test { 29 namespace test {
30 30
31 using content::BrowserThread; 31 using content::BrowserThread;
32 32
33 typedef std::vector<int> DeviceIndices; 33 typedef std::vector<int> DeviceIndices;
34 34
35 // RemovableDeviceNotificationsWindowWinTest ----------------------------------- 35 // StorageMonitorWindowWinTest -----------------------------------
36 36
37 class RemovableDeviceNotificationsWindowWinTest : public testing::Test { 37 class StorageMonitorWindowWinTest : public testing::Test {
vandebo (ex-Chrome) 2013/03/01 19:47:39 StorageMonitorWinTest
38 public: 38 public:
39 RemovableDeviceNotificationsWindowWinTest(); 39 StorageMonitorWindowWinTest();
40 virtual ~RemovableDeviceNotificationsWindowWinTest(); 40 virtual ~StorageMonitorWindowWinTest();
41 41
42 protected: 42 protected:
43 // testing::Test: 43 // testing::Test:
44 virtual void SetUp() OVERRIDE; 44 virtual void SetUp() OVERRIDE;
45 virtual void TearDown() OVERRIDE; 45 virtual void TearDown() OVERRIDE;
46 46
47 void PreAttachDevices(); 47 void PreAttachDevices();
48 48
49 // Runs all the pending tasks on UI thread, FILE thread and blocking thread. 49 // Runs all the pending tasks on UI thread, FILE thread and blocking thread.
50 void RunUntilIdle(); 50 void RunUntilIdle();
51 51
52 void DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices); 52 void DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices);
53 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices); 53 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices);
54 54
55 // Injects a device attach or detach change (depending on the value of 55 // Injects a device attach or detach change (depending on the value of
56 // |test_attach|) and tests that the appropriate handler is called. 56 // |test_attach|) and tests that the appropriate handler is called.
57 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach); 57 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach);
58 58
59 // Gets the MTP details of the storage specified by the |storage_device_id|. 59 // Gets the MTP details of the storage specified by the |storage_device_id|.
60 // On success, returns true and fills in |pnp_device_id| and 60 // On success, returns true and fills in |pnp_device_id| and
61 // |storage_object_id|. 61 // |storage_object_id|.
62 bool GetMTPStorageInfo(const std::string& storage_device_id, 62 bool GetMTPStorageInfo(const std::string& storage_device_id,
63 string16* pnp_device_id, 63 string16* pnp_device_id,
64 string16* storage_object_id); 64 string16* storage_object_id);
65 65
66 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_; 66 scoped_ptr<TestStorageMonitorWindowWin> window_;
67 67
68 // Weak pointer; owned by the device notifications class. 68 // Weak pointer; owned by the device notifications class.
69 TestVolumeMountWatcherWin* volume_mount_watcher_; 69 TestVolumeMountWatcherWin* volume_mount_watcher_;
70 70
71 MockRemovableStorageObserver observer_; 71 MockRemovableStorageObserver observer_;
72 72
73 private: 73 private:
74 MessageLoopForUI message_loop_; 74 MessageLoopForUI message_loop_;
75 content::TestBrowserThread ui_thread_; 75 content::TestBrowserThread ui_thread_;
76 content::TestBrowserThread file_thread_; 76 content::TestBrowserThread file_thread_;
77 }; 77 };
78 78
79 RemovableDeviceNotificationsWindowWinTest:: 79 StorageMonitorWindowWinTest::
80 RemovableDeviceNotificationsWindowWinTest() 80 StorageMonitorWindowWinTest()
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
81 : ui_thread_(BrowserThread::UI, &message_loop_), 81 : ui_thread_(BrowserThread::UI, &message_loop_),
82 file_thread_(BrowserThread::FILE, &message_loop_) { 82 file_thread_(BrowserThread::FILE, &message_loop_) {
83 } 83 }
84 84
85 RemovableDeviceNotificationsWindowWinTest:: 85 StorageMonitorWindowWinTest::
86 ~RemovableDeviceNotificationsWindowWinTest() { 86 ~StorageMonitorWindowWinTest() {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
87 } 87 }
88 88
89 void RemovableDeviceNotificationsWindowWinTest::SetUp() { 89 void StorageMonitorWindowWinTest::SetUp() {
90 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 90 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
91 volume_mount_watcher_ = new TestVolumeMountWatcherWin; 91 volume_mount_watcher_ = new TestVolumeMountWatcherWin;
92 window_.reset(new TestRemovableDeviceNotificationsWindowWin( 92 window_.reset(new TestStorageMonitorWindowWin(
vandebo (ex-Chrome) 2013/03/01 19:47:39 this can be indented nicer now.
93 volume_mount_watcher_, new TestPortableDeviceWatcherWin)); 93 volume_mount_watcher_, new TestPortableDeviceWatcherWin));
94 window_->Init(); 94 window_->Init();
95 RunUntilIdle(); 95 RunUntilIdle();
96 window_->AddObserver(&observer_); 96 window_->AddObserver(&observer_);
97 } 97 }
98 98
99 void RemovableDeviceNotificationsWindowWinTest::TearDown() { 99 void StorageMonitorWindowWinTest::TearDown() {
100 RunUntilIdle(); 100 RunUntilIdle();
101 window_->RemoveObserver(&observer_); 101 window_->RemoveObserver(&observer_);
102 } 102 }
103 103
104 void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() { 104 void StorageMonitorWindowWinTest::PreAttachDevices() {
105 window_.reset(); 105 window_.reset();
106 volume_mount_watcher_ = new TestVolumeMountWatcherWin; 106 volume_mount_watcher_ = new TestVolumeMountWatcherWin;
107 volume_mount_watcher_->SetAttachedDevicesFake(); 107 volume_mount_watcher_->SetAttachedDevicesFake();
108 108
109 int expect_attach_calls = 0; 109 int expect_attach_calls = 0;
110 std::vector<base::FilePath> initial_devices = 110 std::vector<base::FilePath> initial_devices =
111 volume_mount_watcher_->GetAttachedDevices(); 111 volume_mount_watcher_->GetAttachedDevices();
112 for (std::vector<base::FilePath>::const_iterator it = initial_devices.begin(); 112 for (std::vector<base::FilePath>::const_iterator it = initial_devices.begin();
113 it != initial_devices.end(); ++it) { 113 it != initial_devices.end(); ++it) {
114 std::string unique_id; 114 std::string unique_id;
115 string16 device_name; 115 string16 device_name;
116 bool removable; 116 bool removable;
117 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo( 117 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo(
118 *it, NULL, &unique_id, &device_name, &removable, NULL)); 118 *it, NULL, &unique_id, &device_name, &removable, NULL));
119 if (removable) 119 if (removable)
120 expect_attach_calls++; 120 expect_attach_calls++;
121 } 121 }
122 122
123 window_.reset(new TestRemovableDeviceNotificationsWindowWin( 123 window_.reset(new TestStorageMonitorWindowWin(
124 volume_mount_watcher_, new TestPortableDeviceWatcherWin)); 124 volume_mount_watcher_, new TestPortableDeviceWatcherWin));
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: nicer indent possible.
125 window_->AddObserver(&observer_); 125 window_->AddObserver(&observer_);
126 window_->Init(); 126 window_->Init();
127 127
128 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); 128 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size());
129 129
130 // This dance is because attachment bounces through a couple of 130 // This dance is because attachment bounces through a couple of
131 // closures, which need to be executed to finish the process. 131 // closures, which need to be executed to finish the process.
132 RunUntilIdle(); 132 RunUntilIdle();
133 volume_mount_watcher_->FlushWorkerPoolForTesting(); 133 volume_mount_watcher_->FlushWorkerPoolForTesting();
134 RunUntilIdle(); 134 RunUntilIdle();
135 135
136 std::vector<base::FilePath> checked_devices = 136 std::vector<base::FilePath> checked_devices =
137 volume_mount_watcher_->devices_checked(); 137 volume_mount_watcher_->devices_checked();
138 sort(checked_devices.begin(), checked_devices.end()); 138 sort(checked_devices.begin(), checked_devices.end());
139 EXPECT_EQ(initial_devices, checked_devices); 139 EXPECT_EQ(initial_devices, checked_devices);
140 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); 140 EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
141 EXPECT_EQ(0, observer_.detach_calls()); 141 EXPECT_EQ(0, observer_.detach_calls());
142 } 142 }
143 143
144 void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() { 144 void StorageMonitorWindowWinTest::RunUntilIdle() {
145 volume_mount_watcher_->FlushWorkerPoolForTesting(); 145 volume_mount_watcher_->FlushWorkerPoolForTesting();
146 message_loop_.RunUntilIdle(); 146 message_loop_.RunUntilIdle();
147 } 147 }
148 148
149 void RemovableDeviceNotificationsWindowWinTest:: 149 void StorageMonitorWindowWinTest::
150 DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices) { 150 DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap
151 DEV_BROADCAST_VOLUME volume_broadcast; 151 DEV_BROADCAST_VOLUME volume_broadcast;
152 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 152 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
153 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 153 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
154 volume_broadcast.dbcv_unitmask = 0x0; 154 volume_broadcast.dbcv_unitmask = 0x0;
155 volume_broadcast.dbcv_flags = 0x0; 155 volume_broadcast.dbcv_flags = 0x0;
156 156
157 int expect_attach_calls = 0; 157 int expect_attach_calls = 0;
158 for (DeviceIndices::const_iterator it = device_indices.begin(); 158 for (DeviceIndices::const_iterator it = device_indices.begin();
159 it != device_indices.end(); ++it) { 159 it != device_indices.end(); ++it) {
160 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 160 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
161 bool removable; 161 bool removable;
162 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( 162 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
163 VolumeMountWatcherWin::DriveNumberToFilePath(*it), 163 VolumeMountWatcherWin::DriveNumberToFilePath(*it),
164 NULL, NULL, NULL, &removable, NULL)); 164 NULL, NULL, NULL, &removable, NULL));
165 if (removable) 165 if (removable)
166 expect_attach_calls++; 166 expect_attach_calls++;
167 } 167 }
168 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, 168 window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
169 reinterpret_cast<DWORD>(&volume_broadcast)); 169 reinterpret_cast<DWORD>(&volume_broadcast));
170 170
171 RunUntilIdle(); 171 RunUntilIdle();
172 volume_mount_watcher_->FlushWorkerPoolForTesting(); 172 volume_mount_watcher_->FlushWorkerPoolForTesting();
173 RunUntilIdle(); 173 RunUntilIdle();
174 174
175 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); 175 EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
176 EXPECT_EQ(0, observer_.detach_calls()); 176 EXPECT_EQ(0, observer_.detach_calls());
177 } 177 }
178 178
179 void RemovableDeviceNotificationsWindowWinTest:: 179 void StorageMonitorWindowWinTest::
180 DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices) { 180 DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
181 DEV_BROADCAST_VOLUME volume_broadcast; 181 DEV_BROADCAST_VOLUME volume_broadcast;
182 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 182 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
183 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 183 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
184 volume_broadcast.dbcv_unitmask = 0x0; 184 volume_broadcast.dbcv_unitmask = 0x0;
185 volume_broadcast.dbcv_flags = 0x0; 185 volume_broadcast.dbcv_flags = 0x0;
186 186
187 int pre_attach_calls = observer_.attach_calls(); 187 int pre_attach_calls = observer_.attach_calls();
188 int expect_detach_calls = 0; 188 int expect_detach_calls = 0;
189 for (DeviceIndices::const_iterator it = device_indices.begin(); 189 for (DeviceIndices::const_iterator it = device_indices.begin();
190 it != device_indices.end(); ++it) { 190 it != device_indices.end(); ++it) {
191 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 191 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
192 bool removable; 192 bool removable;
193 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo( 193 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo(
194 VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, NULL, 194 VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, NULL,
195 NULL, &removable, NULL)); 195 NULL, &removable, NULL));
196 if (removable) 196 if (removable)
197 expect_detach_calls++; 197 expect_detach_calls++;
198 } 198 }
199 window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE, 199 window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE,
200 reinterpret_cast<DWORD>(&volume_broadcast)); 200 reinterpret_cast<DWORD>(&volume_broadcast));
201 RunUntilIdle(); 201 RunUntilIdle();
202 EXPECT_EQ(pre_attach_calls, observer_.attach_calls()); 202 EXPECT_EQ(pre_attach_calls, observer_.attach_calls());
203 EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); 203 EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
204 } 204 }
205 205
206 void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest( 206 void StorageMonitorWindowWinTest::DoMTPDeviceTest(
207 const string16& pnp_device_id, bool test_attach) { 207 const string16& pnp_device_id, bool test_attach) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
208 GUID guidDevInterface = GUID_NULL; 208 GUID guidDevInterface = GUID_NULL;
209 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); 209 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface);
210 if (FAILED(hr)) 210 if (FAILED(hr))
211 return; 211 return;
212 212
213 size_t device_id_size = pnp_device_id.size() * sizeof(char16); 213 size_t device_id_size = pnp_device_id.size() * sizeof(char16);
214 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size; 214 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size;
215 scoped_ptr_malloc<DEV_BROADCAST_DEVICEINTERFACE> dev_interface_broadcast( 215 scoped_ptr_malloc<DEV_BROADCAST_DEVICEINTERFACE> dev_interface_broadcast(
216 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size))); 216 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size)));
217 DCHECK(dev_interface_broadcast.get()); 217 DCHECK(dev_interface_broadcast.get());
(...skipping 24 matching lines...) Expand all
242 242
243 window_->InjectDeviceChange( 243 window_->InjectDeviceChange(
244 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, 244 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
245 reinterpret_cast<DWORD>(dev_interface_broadcast.get())); 245 reinterpret_cast<DWORD>(dev_interface_broadcast.get()));
246 246
247 RunUntilIdle(); 247 RunUntilIdle();
248 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); 248 EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
249 EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); 249 EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
250 } 250 }
251 251
252 bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo( 252 bool StorageMonitorWindowWinTest::GetMTPStorageInfo(
253 const std::string& storage_device_id, 253 const std::string& storage_device_id,
254 string16* pnp_device_id, 254 string16* pnp_device_id,
255 string16* storage_object_id) { 255 string16* storage_object_id) {
256 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id, 256 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id,
257 pnp_device_id, 257 pnp_device_id,
258 storage_object_id); 258 storage_object_id);
259 } 259 }
260 260
261 TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) { 261 TEST_F(StorageMonitorWindowWinTest, RandomMessage) {
262 window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL); 262 window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
263 RunUntilIdle(); 263 RunUntilIdle();
264 } 264 }
265 265
266 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) { 266 TEST_F(StorageMonitorWindowWinTest, DevicesAttached) {
267 DeviceIndices device_indices; 267 DeviceIndices device_indices;
268 device_indices.push_back(1); // B 268 device_indices.push_back(1); // B
269 device_indices.push_back(5); // F 269 device_indices.push_back(5); // F
270 device_indices.push_back(7); // H 270 device_indices.push_back(7); // H
271 device_indices.push_back(13); // N 271 device_indices.push_back(13); // N
272 DoMassStorageDeviceAttachedTest(device_indices); 272 DoMassStorageDeviceAttachedTest(device_indices);
273 273
274 string16 location; 274 string16 location;
275 std::string unique_id; 275 std::string unique_id;
276 string16 name; 276 string16 name;
(...skipping 14 matching lines...) Expand all
291 EXPECT_TRUE(window_->GetStorageInfoForPath( 291 EXPECT_TRUE(window_->GetStorageInfoForPath(
292 base::FilePath(ASCIIToUTF16("F:\\subdir")), &info1)); 292 base::FilePath(ASCIIToUTF16("F:\\subdir")), &info1));
293 StorageMonitor::StorageInfo info2; 293 StorageMonitor::StorageInfo info2;
294 EXPECT_TRUE(window_->GetStorageInfoForPath( 294 EXPECT_TRUE(window_->GetStorageInfoForPath(
295 base::FilePath(ASCIIToUTF16("F:\\subdir\\sub")), &info2)); 295 base::FilePath(ASCIIToUTF16("F:\\subdir\\sub")), &info2));
296 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info.name); 296 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info.name);
297 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info1.name); 297 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info1.name);
298 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info2.name); 298 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info2.name);
299 } 299 }
300 300
301 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedHighBoundary) { 301 TEST_F(StorageMonitorWindowWinTest, DevicesAttachedHighBoundary) {
302 DeviceIndices device_indices; 302 DeviceIndices device_indices;
303 device_indices.push_back(25); 303 device_indices.push_back(25);
304 304
305 DoMassStorageDeviceAttachedTest(device_indices); 305 DoMassStorageDeviceAttachedTest(device_indices);
306 } 306 }
307 307
308 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedLowBoundary) { 308 TEST_F(StorageMonitorWindowWinTest, DevicesAttachedLowBoundary) {
309 DeviceIndices device_indices; 309 DeviceIndices device_indices;
310 device_indices.push_back(0); 310 device_indices.push_back(0);
311 311
312 DoMassStorageDeviceAttachedTest(device_indices); 312 DoMassStorageDeviceAttachedTest(device_indices);
313 } 313 }
314 314
315 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedAdjacentBits) { 315 TEST_F(StorageMonitorWindowWinTest, DevicesAttachedAdjacentBits) {
316 DeviceIndices device_indices; 316 DeviceIndices device_indices;
317 device_indices.push_back(0); 317 device_indices.push_back(0);
318 device_indices.push_back(1); 318 device_indices.push_back(1);
319 device_indices.push_back(2); 319 device_indices.push_back(2);
320 device_indices.push_back(3); 320 device_indices.push_back(3);
321 321
322 DoMassStorageDeviceAttachedTest(device_indices); 322 DoMassStorageDeviceAttachedTest(device_indices);
323 } 323 }
324 324
325 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesDetached) { 325 TEST_F(StorageMonitorWindowWinTest, DevicesDetached) {
326 PreAttachDevices(); 326 PreAttachDevices();
327 327
328 DeviceIndices device_indices; 328 DeviceIndices device_indices;
329 device_indices.push_back(1); 329 device_indices.push_back(1);
330 device_indices.push_back(5); 330 device_indices.push_back(5);
331 device_indices.push_back(7); 331 device_indices.push_back(7);
332 device_indices.push_back(13); 332 device_indices.push_back(13);
333 333
334 DoMassStorageDevicesDetachedTest(device_indices); 334 DoMassStorageDevicesDetachedTest(device_indices);
335 } 335 }
336 336
337 TEST_F(RemovableDeviceNotificationsWindowWinTest, 337 TEST_F(StorageMonitorWindowWinTest,
338 DevicesDetachedHighBoundary) { 338 DevicesDetachedHighBoundary) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
339 PreAttachDevices(); 339 PreAttachDevices();
340 340
341 DeviceIndices device_indices; 341 DeviceIndices device_indices;
342 device_indices.push_back(25); 342 device_indices.push_back(25);
343 343
344 DoMassStorageDevicesDetachedTest(device_indices); 344 DoMassStorageDevicesDetachedTest(device_indices);
345 } 345 }
346 346
347 TEST_F(RemovableDeviceNotificationsWindowWinTest, 347 TEST_F(StorageMonitorWindowWinTest,
348 DevicesDetachedLowBoundary) { 348 DevicesDetachedLowBoundary) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
349 PreAttachDevices(); 349 PreAttachDevices();
350 350
351 DeviceIndices device_indices; 351 DeviceIndices device_indices;
352 device_indices.push_back(0); 352 device_indices.push_back(0);
353 353
354 DoMassStorageDevicesDetachedTest(device_indices); 354 DoMassStorageDevicesDetachedTest(device_indices);
355 } 355 }
356 356
357 TEST_F(RemovableDeviceNotificationsWindowWinTest, 357 TEST_F(StorageMonitorWindowWinTest,
358 DevicesDetachedAdjacentBits) { 358 DevicesDetachedAdjacentBits) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
359 PreAttachDevices(); 359 PreAttachDevices();
360 360
361 DeviceIndices device_indices; 361 DeviceIndices device_indices;
362 device_indices.push_back(0); 362 device_indices.push_back(0);
363 device_indices.push_back(1); 363 device_indices.push_back(1);
364 device_indices.push_back(2); 364 device_indices.push_back(2);
365 device_indices.push_back(3); 365 device_indices.push_back(3);
366 366
367 DoMassStorageDevicesDetachedTest(device_indices); 367 DoMassStorageDevicesDetachedTest(device_indices);
368 } 368 }
369 369
370 TEST_F(RemovableDeviceNotificationsWindowWinTest, 370 TEST_F(StorageMonitorWindowWinTest,
371 DuplicateAttachCheckSuppressed) { 371 DuplicateAttachCheckSuppressed) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
372 volume_mount_watcher_->BlockDeviceCheckForTesting(); 372 volume_mount_watcher_->BlockDeviceCheckForTesting();
373 base::FilePath kAttachedDevicePath = 373 base::FilePath kAttachedDevicePath =
374 VolumeMountWatcherWin::DriveNumberToFilePath(8); // I: 374 VolumeMountWatcherWin::DriveNumberToFilePath(8); // I:
375 375
376 DEV_BROADCAST_VOLUME volume_broadcast; 376 DEV_BROADCAST_VOLUME volume_broadcast;
377 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 377 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
378 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 378 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
379 volume_broadcast.dbcv_flags = 0x0; 379 volume_broadcast.dbcv_flags = 0x0;
380 volume_broadcast.dbcv_unitmask = 0x100; // I: drive 380 volume_broadcast.dbcv_unitmask = 0x100; // I: drive
381 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, 381 window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
(...skipping 28 matching lines...) Expand all
410 volume_mount_watcher_->FlushWorkerPoolForTesting(); 410 volume_mount_watcher_->FlushWorkerPoolForTesting();
411 volume_mount_watcher_->ReleaseDeviceCheck(); 411 volume_mount_watcher_->ReleaseDeviceCheck();
412 RunUntilIdle(); 412 RunUntilIdle();
413 413
414 checked_devices = volume_mount_watcher_->devices_checked(); 414 checked_devices = volume_mount_watcher_->devices_checked();
415 ASSERT_EQ(2u, checked_devices.size()); 415 ASSERT_EQ(2u, checked_devices.size());
416 EXPECT_EQ(kAttachedDevicePath, checked_devices[0]); 416 EXPECT_EQ(kAttachedDevicePath, checked_devices[0]);
417 EXPECT_EQ(kAttachedDevicePath, checked_devices[1]); 417 EXPECT_EQ(kAttachedDevicePath, checked_devices[1]);
418 } 418 }
419 419
420 TEST_F(RemovableDeviceNotificationsWindowWinTest, DeviceInfoForPath) { 420 TEST_F(StorageMonitorWindowWinTest, DeviceInfoForPath) {
421 PreAttachDevices(); 421 PreAttachDevices();
422 422
423 // An invalid path. 423 // An invalid path.
424 EXPECT_FALSE(window_->GetStorageInfoForPath(base::FilePath(L"COM1:\\"), 424 EXPECT_FALSE(window_->GetStorageInfoForPath(base::FilePath(L"COM1:\\"),
425 NULL)); 425 NULL));
426 426
427 // An unconnected removable device. 427 // An unconnected removable device.
428 EXPECT_FALSE(window_->GetStorageInfoForPath(base::FilePath(L"E:\\"), NULL)); 428 EXPECT_FALSE(window_->GetStorageInfoForPath(base::FilePath(L"E:\\"), NULL));
429 429
430 // A connected removable device. 430 // A connected removable device.
(...skipping 25 matching lines...) Expand all
456 fixed_device, &location, &unique_id, &device_name, &removable, NULL)); 456 fixed_device, &location, &unique_id, &device_name, &removable, NULL));
457 EXPECT_FALSE(removable); 457 EXPECT_FALSE(removable);
458 device_id = MediaStorageUtil::MakeDeviceId( 458 device_id = MediaStorageUtil::MakeDeviceId(
459 MediaStorageUtil::FIXED_MASS_STORAGE, unique_id); 459 MediaStorageUtil::FIXED_MASS_STORAGE, unique_id);
460 EXPECT_EQ(device_id, device_info.device_id); 460 EXPECT_EQ(device_id, device_info.device_id);
461 EXPECT_EQ(device_name, device_info.name); 461 EXPECT_EQ(device_name, device_info.name);
462 EXPECT_EQ(fixed_device.value(), device_info.location); 462 EXPECT_EQ(fixed_device.value(), device_info.location);
463 } 463 }
464 464
465 // Test to verify basic MTP storage attach and detach notifications. 465 // Test to verify basic MTP storage attach and detach notifications.
466 TEST_F(RemovableDeviceNotificationsWindowWinTest, MTPDeviceBasicAttachDetach) { 466 TEST_F(StorageMonitorWindowWinTest, MTPDeviceBasicAttachDetach) {
467 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true); 467 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true);
468 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); 468 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false);
469 } 469 }
470 470
471 // When a MTP storage device with invalid storage label and id is 471 // When a MTP storage device with invalid storage label and id is
472 // attached/detached, there should not be any device attach/detach 472 // attached/detached, there should not be any device attach/detach
473 // notifications. 473 // notifications.
474 TEST_F(RemovableDeviceNotificationsWindowWinTest, MTPDeviceWithInvalidInfo) { 474 TEST_F(StorageMonitorWindowWinTest, MTPDeviceWithInvalidInfo) {
475 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo, 475 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo,
476 true); 476 true);
477 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo, 477 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo,
478 false); 478 false);
479 } 479 }
480 480
481 // Attach a device with two data partitions. Verify that attach/detach 481 // Attach a device with two data partitions. Verify that attach/detach
482 // notifications are sent out for each removable storage. 482 // notifications are sent out for each removable storage.
483 TEST_F(RemovableDeviceNotificationsWindowWinTest, 483 TEST_F(StorageMonitorWindowWinTest,
484 MTPDeviceWithMultipleStorageObjects) { 484 MTPDeviceWithMultipleStorageObjects) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
485 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages, 485 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages,
486 true); 486 true);
487 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages, 487 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages,
488 false); 488 false);
489 } 489 }
490 490
491 TEST_F(RemovableDeviceNotificationsWindowWinTest, DriveNumberToFilePath) { 491 TEST_F(StorageMonitorWindowWinTest, DriveNumberToFilePath) {
492 EXPECT_EQ(L"A:\\", VolumeMountWatcherWin::DriveNumberToFilePath(0).value()); 492 EXPECT_EQ(L"A:\\", VolumeMountWatcherWin::DriveNumberToFilePath(0).value());
493 EXPECT_EQ(L"Y:\\", VolumeMountWatcherWin::DriveNumberToFilePath(24).value()); 493 EXPECT_EQ(L"Y:\\", VolumeMountWatcherWin::DriveNumberToFilePath(24).value());
494 EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(-1).value()); 494 EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(-1).value());
495 EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(199).value()); 495 EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(199).value());
496 } 496 }
497 497
498 // Given a MTP storage persistent id, GetMTPStorageInfo() should fetch the 498 // Given a MTP storage persistent id, GetMTPStorageInfo() should fetch the
499 // device interface path and local storage object identifier. 499 // device interface path and local storage object identifier.
500 TEST_F(RemovableDeviceNotificationsWindowWinTest, 500 TEST_F(StorageMonitorWindowWinTest,
501 GetMTPStorageInfoFromDeviceId) { 501 GetMTPStorageInfoFromDeviceId) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
502 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true); 502 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true);
503 PortableDeviceWatcherWin::StorageObjects storage_objects = 503 PortableDeviceWatcherWin::StorageObjects storage_objects =
504 TestPortableDeviceWatcherWin::GetDeviceStorageObjects( 504 TestPortableDeviceWatcherWin::GetDeviceStorageObjects(
505 TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo); 505 TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo);
506 for (PortableDeviceWatcherWin::StorageObjects::const_iterator it = 506 for (PortableDeviceWatcherWin::StorageObjects::const_iterator it =
507 storage_objects.begin(); 507 storage_objects.begin();
508 it != storage_objects.end(); ++it) { 508 it != storage_objects.end(); ++it) {
509 string16 pnp_device_id; 509 string16 pnp_device_id;
510 string16 storage_object_id; 510 string16 storage_object_id;
511 ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id, 511 ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id,
512 &storage_object_id)); 512 &storage_object_id));
513 EXPECT_EQ(string16(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo), 513 EXPECT_EQ(string16(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo),
514 pnp_device_id); 514 pnp_device_id);
515 EXPECT_EQ(it->object_persistent_id, 515 EXPECT_EQ(it->object_persistent_id,
516 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( 516 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId(
517 pnp_device_id, storage_object_id)); 517 pnp_device_id, storage_object_id));
518 } 518 }
519 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); 519 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false);
520 } 520 }
521 521
522 } // namespace test 522 } // namespace test
523 } // namespace chrome 523 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698