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

Side by Side Diff: chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Working on windows Created 7 years, 10 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
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/system_monitor/system_monitor.h"
16 #include "base/test/mock_devices_changed_observer.h"
17 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/system_monitor/media_storage_util.h" 16 #include "chrome/browser/system_monitor/media_storage_util.h"
17 #include "chrome/browser/system_monitor/mock_removable_storage_observer.h"
19 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" 18 #include "chrome/browser/system_monitor/portable_device_watcher_win.h"
20 #include "chrome/browser/system_monitor/removable_device_constants.h" 19 #include "chrome/browser/system_monitor/removable_device_constants.h"
21 #include "chrome/browser/system_monitor/test_portable_device_watcher_win.h" 20 #include "chrome/browser/system_monitor/test_portable_device_watcher_win.h"
22 #include "chrome/browser/system_monitor/test_removable_device_notifications_wind ow_win.h" 21 #include "chrome/browser/system_monitor/test_removable_device_notifications_wind ow_win.h"
23 #include "chrome/browser/system_monitor/test_volume_mount_watcher_win.h" 22 #include "chrome/browser/system_monitor/test_volume_mount_watcher_win.h"
24 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" 23 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h"
25 #include "content/public/test/test_browser_thread.h" 24 #include "content/public/test/test_browser_thread.h"
26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
28 26
29 namespace chrome { 27 namespace chrome {
30 namespace test { 28 namespace test {
31 29
32 using content::BrowserThread; 30 using content::BrowserThread;
33 31
34 typedef std::vector<int> DeviceIndices; 32 typedef std::vector<int> DeviceIndices;
35 33
36 // RemovableDeviceNotificationsWindowWinTest ----------------------------------- 34 // RemovableDeviceNotificationsWindowWinTest -----------------------------------
37 35
38 class RemovableDeviceNotificationsWindowWinTest : public testing::Test { 36 class RemovableDeviceNotificationsWindowWinTest : public testing::Test {
39 public: 37 public:
40 RemovableDeviceNotificationsWindowWinTest(); 38 RemovableDeviceNotificationsWindowWinTest();
41 virtual ~RemovableDeviceNotificationsWindowWinTest(); 39 virtual ~RemovableDeviceNotificationsWindowWinTest();
42 40
43 protected: 41 protected:
44 // testing::Test: 42 // testing::Test:
45 virtual void SetUp() OVERRIDE; 43 virtual void SetUp() OVERRIDE;
46 virtual void TearDown() OVERRIDE; 44 virtual void TearDown() OVERRIDE;
47 45
48 void AddMassStorageDeviceAttachExpectation(const FilePath& drive);
49 void PreAttachDevices(); 46 void PreAttachDevices();
50 47
51 // Runs all the pending tasks on UI thread, FILE thread and blocking thread. 48 // Runs all the pending tasks on UI thread, FILE thread and blocking thread.
52 void RunUntilIdle(); 49 void RunUntilIdle();
53 50
54 void DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices); 51 void DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices);
55 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices); 52 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices);
56 53
57 // Injects a device attach or detach change (depending on the value of 54 // Injects a device attach or detach change (depending on the value of
58 // |test_attach|) and tests that the appropriate handler is called. 55 // |test_attach|) and tests that the appropriate handler is called.
59 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach); 56 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach);
60 57
61 // Gets the MTP details of the storage specified by the |storage_device_id|. 58 // Gets the MTP details of the storage specified by the |storage_device_id|.
62 // On success, returns true and fills in |pnp_device_id| and 59 // On success, returns true and fills in |pnp_device_id| and
63 // |storage_object_id|. 60 // |storage_object_id|.
64 bool GetMTPStorageInfo(const std::string& storage_device_id, 61 bool GetMTPStorageInfo(const std::string& storage_device_id,
65 string16* pnp_device_id, 62 string16* pnp_device_id,
66 string16* storage_object_id); 63 string16* storage_object_id);
67 64
68 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_; 65 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_;
69 66
70 // Weak pointer; owned by the device notifications class. 67 // Weak pointer; owned by the device notifications class.
71 TestVolumeMountWatcherWin* volume_mount_watcher_; 68 TestVolumeMountWatcherWin* volume_mount_watcher_;
72 69
70 MockRemovableStorageObserver observer_;
71
73 private: 72 private:
74 MessageLoopForUI message_loop_; 73 MessageLoopForUI message_loop_;
75 content::TestBrowserThread ui_thread_; 74 content::TestBrowserThread ui_thread_;
76 content::TestBrowserThread file_thread_; 75 content::TestBrowserThread file_thread_;
77
78 base::SystemMonitor system_monitor_;
79 base::MockDevicesChangedObserver observer_;
80 }; 76 };
81 77
82 RemovableDeviceNotificationsWindowWinTest:: 78 RemovableDeviceNotificationsWindowWinTest::
83 RemovableDeviceNotificationsWindowWinTest() 79 RemovableDeviceNotificationsWindowWinTest()
84 : ui_thread_(BrowserThread::UI, &message_loop_), 80 : ui_thread_(BrowserThread::UI, &message_loop_),
85 file_thread_(BrowserThread::FILE, &message_loop_) { 81 file_thread_(BrowserThread::FILE, &message_loop_) {
86 } 82 }
87 83
88 RemovableDeviceNotificationsWindowWinTest:: 84 RemovableDeviceNotificationsWindowWinTest::
89 ~RemovableDeviceNotificationsWindowWinTest() { 85 ~RemovableDeviceNotificationsWindowWinTest() {
90 } 86 }
91 87
92 void RemovableDeviceNotificationsWindowWinTest::SetUp() { 88 void RemovableDeviceNotificationsWindowWinTest::SetUp() {
93 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 89 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
94 volume_mount_watcher_ = new TestVolumeMountWatcherWin; 90 volume_mount_watcher_ = new TestVolumeMountWatcherWin;
95 window_.reset(new TestRemovableDeviceNotificationsWindowWin( 91 window_.reset(new TestRemovableDeviceNotificationsWindowWin(
96 volume_mount_watcher_, new TestPortableDeviceWatcherWin)); 92 volume_mount_watcher_, new TestPortableDeviceWatcherWin));
97 window_->Init(); 93 window_->Init();
98 RunUntilIdle(); 94 RunUntilIdle();
99 system_monitor_.AddDevicesChangedObserver(&observer_); 95 window_->AddObserver(&observer_);
100 } 96 }
101 97
102 void RemovableDeviceNotificationsWindowWinTest::TearDown() { 98 void RemovableDeviceNotificationsWindowWinTest::TearDown() {
103 RunUntilIdle(); 99 RunUntilIdle();
104 system_monitor_.RemoveDevicesChangedObserver(&observer_); 100 window_->RemoveObserver(&observer_);
105 } 101 }
106 102
107 void RemovableDeviceNotificationsWindowWinTest::
108 AddMassStorageDeviceAttachExpectation(const FilePath& drive) {
109 std::string unique_id;
110 string16 device_name;
111 bool removable;
112 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo(
113 drive, NULL, &unique_id, &device_name, &removable));
114 if (removable) {
115 MediaStorageUtil::Type type =
116 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
117 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id);
118 EXPECT_CALL(observer_, OnRemovableStorageAttached(device_id, device_name,
119 drive.value()))
120 .Times(1);
121 }
122 }
123 103
124 void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() { 104 void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() {
125 window_.reset(); 105 window_.reset();
126 volume_mount_watcher_ = new TestVolumeMountWatcherWin; 106 volume_mount_watcher_ = new TestVolumeMountWatcherWin;
127 volume_mount_watcher_->SetAttachedDevicesFake(); 107 volume_mount_watcher_->SetAttachedDevicesFake();
108
109 int expect_attach_calls = 0;
128 std::vector<FilePath> initial_devices = 110 std::vector<FilePath> initial_devices =
129 volume_mount_watcher_->GetAttachedDevices(); 111 volume_mount_watcher_->GetAttachedDevices();
130 for (std::vector<FilePath>::const_iterator it = initial_devices.begin(); 112 for (std::vector<FilePath>::const_iterator it = initial_devices.begin();
131 it != initial_devices.end(); ++it) { 113 it != initial_devices.end(); ++it) {
132 AddMassStorageDeviceAttachExpectation(*it); 114 std::string unique_id;
115 string16 device_name;
116 bool removable;
117 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo(
118 *it, NULL, &unique_id, &device_name, &removable));
119 if (removable)
120 expect_attach_calls++;
133 } 121 }
134 122
135 window_.reset(new TestRemovableDeviceNotificationsWindowWin( 123 window_.reset(new TestRemovableDeviceNotificationsWindowWin(
136 volume_mount_watcher_, new TestPortableDeviceWatcherWin)); 124 volume_mount_watcher_, new TestPortableDeviceWatcherWin));
125 window_->AddObserver(&observer_);
137 window_->Init(); 126 window_->Init();
138 127
139 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); 128 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size());
140 129
141 // This dance is because attachment bounces through a couple of 130 // This dance is because attachment bounces through a couple of
142 // closures, which need to be executed to finish the process. 131 // closures, which need to be executed to finish the process.
143 RunUntilIdle(); 132 RunUntilIdle();
144 volume_mount_watcher_->FlushWorkerPoolForTesting(); 133 volume_mount_watcher_->FlushWorkerPoolForTesting();
145 RunUntilIdle(); 134 RunUntilIdle();
146 135
147 std::vector<FilePath> checked_devices = 136 std::vector<FilePath> checked_devices =
148 volume_mount_watcher_->devices_checked(); 137 volume_mount_watcher_->devices_checked();
149 sort(checked_devices.begin(), checked_devices.end()); 138 sort(checked_devices.begin(), checked_devices.end());
150 EXPECT_EQ(initial_devices, checked_devices); 139 EXPECT_EQ(initial_devices, checked_devices);
140 EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
141 EXPECT_EQ(0, observer_.detach_calls());
151 } 142 }
152 143
153 void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() { 144 void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() {
154 volume_mount_watcher_->FlushWorkerPoolForTesting(); 145 volume_mount_watcher_->FlushWorkerPoolForTesting();
155 message_loop_.RunUntilIdle(); 146 message_loop_.RunUntilIdle();
156 } 147 }
157 148
158 void RemovableDeviceNotificationsWindowWinTest:: 149 void RemovableDeviceNotificationsWindowWinTest::
159 DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices) { 150 DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices) {
160 DEV_BROADCAST_VOLUME volume_broadcast; 151 DEV_BROADCAST_VOLUME volume_broadcast;
161 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 152 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
162 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 153 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
163 volume_broadcast.dbcv_unitmask = 0x0; 154 volume_broadcast.dbcv_unitmask = 0x0;
164 volume_broadcast.dbcv_flags = 0x0; 155 volume_broadcast.dbcv_flags = 0x0;
165 { 156
166 for (DeviceIndices::const_iterator it = device_indices.begin(); 157 int expect_attach_calls = 0;
167 it != device_indices.end(); ++it) { 158 for (DeviceIndices::const_iterator it = device_indices.begin();
168 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 159 it != device_indices.end(); ++it) {
169 AddMassStorageDeviceAttachExpectation( 160 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
170 VolumeMountWatcherWin::DriveNumberToFilePath(*it)); 161 bool removable;
171 } 162 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
163 VolumeMountWatcherWin::DriveNumberToFilePath(*it),
164 NULL, NULL, NULL, &removable));
165 if (removable)
166 expect_attach_calls++;
172 } 167 }
173 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, 168 window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
174 reinterpret_cast<DWORD>(&volume_broadcast)); 169 reinterpret_cast<DWORD>(&volume_broadcast));
170
175 RunUntilIdle(); 171 RunUntilIdle();
176 volume_mount_watcher_->FlushWorkerPoolForTesting(); 172 volume_mount_watcher_->FlushWorkerPoolForTesting();
177 RunUntilIdle(); 173 RunUntilIdle();
174
175 EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
176 EXPECT_EQ(0, observer_.detach_calls());
178 } 177 }
179 178
180 void RemovableDeviceNotificationsWindowWinTest:: 179 void RemovableDeviceNotificationsWindowWinTest::
181 DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices) { 180 DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices) {
182 DEV_BROADCAST_VOLUME volume_broadcast; 181 DEV_BROADCAST_VOLUME volume_broadcast;
183 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 182 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
184 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 183 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
185 volume_broadcast.dbcv_unitmask = 0x0; 184 volume_broadcast.dbcv_unitmask = 0x0;
186 volume_broadcast.dbcv_flags = 0x0; 185 volume_broadcast.dbcv_flags = 0x0;
187 { 186
188 for (DeviceIndices::const_iterator it = device_indices.begin(); 187 int pre_attach_calls = observer_.attach_calls();
189 it != device_indices.end(); ++it) { 188 int expect_detach_calls = 0;
190 volume_broadcast.dbcv_unitmask |= 0x1 << *it; 189 for (DeviceIndices::const_iterator it = device_indices.begin();
191 std::string unique_id; 190 it != device_indices.end(); ++it) {
192 bool removable; 191 volume_broadcast.dbcv_unitmask |= 0x1 << *it;
193 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo( 192 bool removable;
194 VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, &unique_id, 193 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo(
195 NULL, &removable)); 194 VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, NULL,
196 if (removable) { 195 NULL, &removable));
197 MediaStorageUtil::Type type = 196 if (removable)
198 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; 197 expect_detach_calls++;
199 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id);
200 EXPECT_CALL(observer_, OnRemovableStorageDetached(device_id)).Times(1);
201 }
202 }
203 } 198 }
204 window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE, 199 window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE,
205 reinterpret_cast<DWORD>(&volume_broadcast)); 200 reinterpret_cast<DWORD>(&volume_broadcast));
206 RunUntilIdle(); 201 RunUntilIdle();
202 EXPECT_EQ(pre_attach_calls, observer_.attach_calls());
203 EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
207 } 204 }
208 205
209 void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest( 206 void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
210 const string16& pnp_device_id, bool test_attach) { 207 const string16& pnp_device_id, bool test_attach) {
211 GUID guidDevInterface = GUID_NULL; 208 GUID guidDevInterface = GUID_NULL;
212 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); 209 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface);
213 if (FAILED(hr)) 210 if (FAILED(hr))
214 return; 211 return;
215 212
216 size_t device_id_size = pnp_device_id.size() * sizeof(char16); 213 size_t device_id_size = pnp_device_id.size() * sizeof(char16);
217 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size; 214 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size;
218 scoped_ptr_malloc<DEV_BROADCAST_DEVICEINTERFACE> dev_interface_broadcast( 215 scoped_ptr_malloc<DEV_BROADCAST_DEVICEINTERFACE> dev_interface_broadcast(
219 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size))); 216 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size)));
220 DCHECK(dev_interface_broadcast.get()); 217 DCHECK(dev_interface_broadcast.get());
221 ZeroMemory(dev_interface_broadcast.get(), size); 218 ZeroMemory(dev_interface_broadcast.get(), size);
222 dev_interface_broadcast->dbcc_size = size; 219 dev_interface_broadcast->dbcc_size = size;
223 dev_interface_broadcast->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; 220 dev_interface_broadcast->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
224 dev_interface_broadcast->dbcc_classguid = guidDevInterface; 221 dev_interface_broadcast->dbcc_classguid = guidDevInterface;
225 memcpy(dev_interface_broadcast->dbcc_name, pnp_device_id.data(), 222 memcpy(dev_interface_broadcast->dbcc_name, pnp_device_id.data(),
226 device_id_size); 223 device_id_size);
227 { 224
228 testing::InSequence sequence; 225 int expect_attach_calls = observer_.attach_calls();
229 PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids = 226 int expect_detach_calls = observer_.detach_calls();
230 TestPortableDeviceWatcherWin::GetMTPStorageObjectIds(pnp_device_id); 227 PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids =
231 for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it = 228 TestPortableDeviceWatcherWin::GetMTPStorageObjectIds(pnp_device_id);
232 storage_object_ids.begin(); it != storage_object_ids.end(); ++it) { 229 for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it =
233 std::string unique_id; 230 storage_object_ids.begin(); it != storage_object_ids.end(); ++it) {
234 string16 name; 231 std::string unique_id;
235 string16 location; 232 string16 name;
236 TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it, 233 string16 location;
237 &location, &unique_id, 234 TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it,
238 &name); 235 &location, &unique_id,
239 if (test_attach) { 236 &name);
240 EXPECT_CALL(observer_, OnRemovableStorageAttached(unique_id, name, 237 if (test_attach && !name.empty() && !unique_id.empty())
241 location)) 238 expect_attach_calls++;
242 .Times((name.empty() || unique_id.empty()) ? 0 : 1); 239 else if (!name.empty() && !unique_id.empty())
243 } else { 240 expect_detach_calls++;
244 EXPECT_CALL(observer_, OnRemovableStorageDetached(unique_id))
245 .Times((name.empty() || unique_id.empty()) ? 0 : 1);
246 }
247 }
248 } 241 }
242
249 window_->InjectDeviceChange( 243 window_->InjectDeviceChange(
250 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, 244 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
251 reinterpret_cast<DWORD>(dev_interface_broadcast.get())); 245 reinterpret_cast<DWORD>(dev_interface_broadcast.get()));
246
252 RunUntilIdle(); 247 RunUntilIdle();
248 EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
249 EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
253 } 250 }
254 251
255 bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo( 252 bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo(
256 const std::string& storage_device_id, 253 const std::string& storage_device_id,
257 string16* pnp_device_id, 254 string16* pnp_device_id,
258 string16* storage_object_id) { 255 string16* storage_object_id) {
259 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id, 256 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id,
260 pnp_device_id, 257 pnp_device_id,
261 storage_object_id); 258 storage_object_id);
262 } 259 }
(...skipping 15 matching lines...) Expand all
278 std::string unique_id; 275 std::string unique_id;
279 string16 name; 276 string16 name;
280 bool removable; 277 bool removable;
281 EXPECT_TRUE(window_->volume_mount_watcher()->GetDeviceInfo( 278 EXPECT_TRUE(window_->volume_mount_watcher()->GetDeviceInfo(
282 FilePath(ASCIIToUTF16("F:\\")), 279 FilePath(ASCIIToUTF16("F:\\")),
283 &location, &unique_id, &name, &removable)); 280 &location, &unique_id, &name, &removable));
284 EXPECT_EQ(ASCIIToUTF16("F:\\"), location); 281 EXPECT_EQ(ASCIIToUTF16("F:\\"), location);
285 EXPECT_EQ("\\\\?\\Volume{F0000000-0000-0000-0000-000000000000}\\", unique_id); 282 EXPECT_EQ("\\\\?\\Volume{F0000000-0000-0000-0000-000000000000}\\", unique_id);
286 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), name); 283 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), name);
287 284
288 base::SystemMonitor::RemovableStorageInfo info; 285 RemovableStorageNotifications::StorageInfo info;
289 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(ASCIIToUTF16("G:\\")), 286 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(ASCIIToUTF16("G:\\")),
290 &info)); 287 &info));
291 EXPECT_TRUE(window_->GetDeviceInfoForPath(FilePath(ASCIIToUTF16("F:\\")), 288 EXPECT_TRUE(window_->GetDeviceInfoForPath(FilePath(ASCIIToUTF16("F:\\")),
292 &info)); 289 &info));
293 base::SystemMonitor::RemovableStorageInfo info1; 290 RemovableStorageNotifications::StorageInfo info1;
294 EXPECT_TRUE(window_->GetDeviceInfoForPath( 291 EXPECT_TRUE(window_->GetDeviceInfoForPath(
295 FilePath(ASCIIToUTF16("F:\\subdir")), &info1)); 292 FilePath(ASCIIToUTF16("F:\\subdir")), &info1));
296 base::SystemMonitor::RemovableStorageInfo info2; 293 RemovableStorageNotifications::StorageInfo info2;
297 EXPECT_TRUE(window_->GetDeviceInfoForPath( 294 EXPECT_TRUE(window_->GetDeviceInfoForPath(
298 FilePath(ASCIIToUTF16("F:\\subdir\\sub")), &info2)); 295 FilePath(ASCIIToUTF16("F:\\subdir\\sub")), &info2));
299 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info.name); 296 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info.name);
300 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info1.name); 297 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info1.name);
301 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info2.name); 298 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info2.name);
302 } 299 }
303 300
304 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedHighBoundary) { 301 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedHighBoundary) {
305 DeviceIndices device_indices; 302 DeviceIndices device_indices;
306 device_indices.push_back(25); 303 device_indices.push_back(25);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 device_indices.push_back(3); 365 device_indices.push_back(3);
369 366
370 DoMassStorageDevicesDetachedTest(device_indices); 367 DoMassStorageDevicesDetachedTest(device_indices);
371 } 368 }
372 369
373 TEST_F(RemovableDeviceNotificationsWindowWinTest, 370 TEST_F(RemovableDeviceNotificationsWindowWinTest,
374 DuplicateAttachCheckSuppressed) { 371 DuplicateAttachCheckSuppressed) {
375 volume_mount_watcher_->BlockDeviceCheckForTesting(); 372 volume_mount_watcher_->BlockDeviceCheckForTesting();
376 FilePath kAttachedDevicePath = 373 FilePath kAttachedDevicePath =
377 VolumeMountWatcherWin::DriveNumberToFilePath(8); // I: 374 VolumeMountWatcherWin::DriveNumberToFilePath(8); // I:
378 AddMassStorageDeviceAttachExpectation(kAttachedDevicePath);
379 375
380 DEV_BROADCAST_VOLUME volume_broadcast; 376 DEV_BROADCAST_VOLUME volume_broadcast;
381 volume_broadcast.dbcv_size = sizeof(volume_broadcast); 377 volume_broadcast.dbcv_size = sizeof(volume_broadcast);
382 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; 378 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
383 volume_broadcast.dbcv_flags = 0x0; 379 volume_broadcast.dbcv_flags = 0x0;
384 volume_broadcast.dbcv_unitmask = 0x100; // I: drive 380 volume_broadcast.dbcv_unitmask = 0x100; // I: drive
385 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, 381 window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
386 reinterpret_cast<DWORD>(&volume_broadcast)); 382 reinterpret_cast<DWORD>(&volume_broadcast));
387 383
388 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); 384 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 PreAttachDevices(); 421 PreAttachDevices();
426 422
427 // An invalid path. 423 // An invalid path.
428 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"COM1:\\"), NULL)); 424 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"COM1:\\"), NULL));
429 425
430 // An unconnected removable device. 426 // An unconnected removable device.
431 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"E:\\"), NULL)); 427 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"E:\\"), NULL));
432 428
433 // A connected removable device. 429 // A connected removable device.
434 FilePath removable_device(L"F:\\"); 430 FilePath removable_device(L"F:\\");
435 base::SystemMonitor::RemovableStorageInfo device_info; 431 RemovableStorageNotifications::StorageInfo device_info;
436 EXPECT_TRUE(window_->GetDeviceInfoForPath(removable_device, &device_info)); 432 EXPECT_TRUE(window_->GetDeviceInfoForPath(removable_device, &device_info));
437 433
438 std::string unique_id; 434 std::string unique_id;
439 string16 device_name; 435 string16 device_name;
440 string16 location; 436 string16 location;
441 bool removable; 437 bool removable;
442 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( 438 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
443 removable_device, &location, &unique_id, &device_name, &removable)); 439 removable_device, &location, &unique_id, &device_name, &removable));
444 EXPECT_TRUE(removable); 440 EXPECT_TRUE(removable);
445 std::string device_id = MediaStorageUtil::MakeDeviceId( 441 std::string device_id = MediaStorageUtil::MakeDeviceId(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 pnp_device_id); 510 pnp_device_id);
515 EXPECT_EQ(it->object_persistent_id, 511 EXPECT_EQ(it->object_persistent_id,
516 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( 512 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId(
517 pnp_device_id, storage_object_id)); 513 pnp_device_id, storage_object_id));
518 } 514 }
519 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); 515 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false);
520 } 516 }
521 517
522 } // namespace test 518 } // namespace test
523 } // namespace chrome 519 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698