| OLD | NEW |
| 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 // StorageMonitorWinTest ------------------------------------------------------- |
| 36 | 36 |
| 37 class RemovableDeviceNotificationsWindowWinTest : public testing::Test { | 37 class StorageMonitorWinTest : public testing::Test { |
| 38 public: | 38 public: |
| 39 RemovableDeviceNotificationsWindowWinTest(); | 39 StorageMonitorWinTest(); |
| 40 virtual ~RemovableDeviceNotificationsWindowWinTest(); | 40 virtual ~StorageMonitorWinTest(); |
| 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<TestStorageMonitorWin> monitor_; |
| 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 StorageMonitorWinTest::StorageMonitorWinTest() |
| 80 RemovableDeviceNotificationsWindowWinTest() | 80 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 81 : ui_thread_(BrowserThread::UI, &message_loop_), | 81 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 82 file_thread_(BrowserThread::FILE, &message_loop_) { | |
| 83 } | 82 } |
| 84 | 83 |
| 85 RemovableDeviceNotificationsWindowWinTest:: | 84 StorageMonitorWinTest::~StorageMonitorWinTest() { |
| 86 ~RemovableDeviceNotificationsWindowWinTest() { | |
| 87 } | 85 } |
| 88 | 86 |
| 89 void RemovableDeviceNotificationsWindowWinTest::SetUp() { | 87 void StorageMonitorWinTest::SetUp() { |
| 90 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 88 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 91 volume_mount_watcher_ = new TestVolumeMountWatcherWin; | 89 volume_mount_watcher_ = new TestVolumeMountWatcherWin; |
| 92 window_.reset(new TestRemovableDeviceNotificationsWindowWin( | 90 monitor_.reset(new TestStorageMonitorWin(volume_mount_watcher_, |
| 93 volume_mount_watcher_, new TestPortableDeviceWatcherWin)); | 91 new TestPortableDeviceWatcherWin)); |
| 94 window_->Init(); | 92 monitor_->Init(); |
| 95 RunUntilIdle(); | 93 RunUntilIdle(); |
| 96 window_->AddObserver(&observer_); | 94 monitor_->AddObserver(&observer_); |
| 97 } | 95 } |
| 98 | 96 |
| 99 void RemovableDeviceNotificationsWindowWinTest::TearDown() { | 97 void StorageMonitorWinTest::TearDown() { |
| 100 RunUntilIdle(); | 98 RunUntilIdle(); |
| 101 window_->RemoveObserver(&observer_); | 99 monitor_->RemoveObserver(&observer_); |
| 102 } | 100 } |
| 103 | 101 |
| 104 void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() { | 102 void StorageMonitorWinTest::PreAttachDevices() { |
| 105 window_.reset(); | 103 monitor_.reset(); |
| 106 volume_mount_watcher_ = new TestVolumeMountWatcherWin; | 104 volume_mount_watcher_ = new TestVolumeMountWatcherWin; |
| 107 volume_mount_watcher_->SetAttachedDevicesFake(); | 105 volume_mount_watcher_->SetAttachedDevicesFake(); |
| 108 | 106 |
| 109 int expect_attach_calls = 0; | 107 int expect_attach_calls = 0; |
| 110 std::vector<base::FilePath> initial_devices = | 108 std::vector<base::FilePath> initial_devices = |
| 111 volume_mount_watcher_->GetAttachedDevices(); | 109 volume_mount_watcher_->GetAttachedDevices(); |
| 112 for (std::vector<base::FilePath>::const_iterator it = initial_devices.begin(); | 110 for (std::vector<base::FilePath>::const_iterator it = initial_devices.begin(); |
| 113 it != initial_devices.end(); ++it) { | 111 it != initial_devices.end(); ++it) { |
| 114 std::string unique_id; | 112 std::string unique_id; |
| 115 string16 device_name; | 113 string16 device_name; |
| 116 bool removable; | 114 bool removable; |
| 117 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo( | 115 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo( |
| 118 *it, NULL, &unique_id, &device_name, &removable, NULL)); | 116 *it, NULL, &unique_id, &device_name, &removable, NULL)); |
| 119 if (removable) | 117 if (removable) |
| 120 expect_attach_calls++; | 118 expect_attach_calls++; |
| 121 } | 119 } |
| 122 | 120 |
| 123 window_.reset(new TestRemovableDeviceNotificationsWindowWin( | 121 monitor_.reset(new TestStorageMonitorWin(volume_mount_watcher_, |
| 124 volume_mount_watcher_, new TestPortableDeviceWatcherWin)); | 122 new TestPortableDeviceWatcherWin)); |
| 125 window_->AddObserver(&observer_); | 123 monitor_->AddObserver(&observer_); |
| 126 window_->Init(); | 124 monitor_->Init(); |
| 127 | 125 |
| 128 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); | 126 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); |
| 129 | 127 |
| 130 // This dance is because attachment bounces through a couple of | 128 // This dance is because attachment bounces through a couple of |
| 131 // closures, which need to be executed to finish the process. | 129 // closures, which need to be executed to finish the process. |
| 132 RunUntilIdle(); | 130 RunUntilIdle(); |
| 133 volume_mount_watcher_->FlushWorkerPoolForTesting(); | 131 volume_mount_watcher_->FlushWorkerPoolForTesting(); |
| 134 RunUntilIdle(); | 132 RunUntilIdle(); |
| 135 | 133 |
| 136 std::vector<base::FilePath> checked_devices = | 134 std::vector<base::FilePath> checked_devices = |
| 137 volume_mount_watcher_->devices_checked(); | 135 volume_mount_watcher_->devices_checked(); |
| 138 sort(checked_devices.begin(), checked_devices.end()); | 136 sort(checked_devices.begin(), checked_devices.end()); |
| 139 EXPECT_EQ(initial_devices, checked_devices); | 137 EXPECT_EQ(initial_devices, checked_devices); |
| 140 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); | 138 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); |
| 141 EXPECT_EQ(0, observer_.detach_calls()); | 139 EXPECT_EQ(0, observer_.detach_calls()); |
| 142 } | 140 } |
| 143 | 141 |
| 144 void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() { | 142 void StorageMonitorWinTest::RunUntilIdle() { |
| 145 volume_mount_watcher_->FlushWorkerPoolForTesting(); | 143 volume_mount_watcher_->FlushWorkerPoolForTesting(); |
| 146 message_loop_.RunUntilIdle(); | 144 message_loop_.RunUntilIdle(); |
| 147 } | 145 } |
| 148 | 146 |
| 149 void RemovableDeviceNotificationsWindowWinTest:: | 147 void StorageMonitorWinTest::DoMassStorageDeviceAttachedTest( |
| 150 DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices) { | 148 const DeviceIndices& device_indices) { |
| 151 DEV_BROADCAST_VOLUME volume_broadcast; | 149 DEV_BROADCAST_VOLUME volume_broadcast; |
| 152 volume_broadcast.dbcv_size = sizeof(volume_broadcast); | 150 volume_broadcast.dbcv_size = sizeof(volume_broadcast); |
| 153 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; | 151 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; |
| 154 volume_broadcast.dbcv_unitmask = 0x0; | 152 volume_broadcast.dbcv_unitmask = 0x0; |
| 155 volume_broadcast.dbcv_flags = 0x0; | 153 volume_broadcast.dbcv_flags = 0x0; |
| 156 | 154 |
| 157 int expect_attach_calls = 0; | 155 int expect_attach_calls = 0; |
| 158 for (DeviceIndices::const_iterator it = device_indices.begin(); | 156 for (DeviceIndices::const_iterator it = device_indices.begin(); |
| 159 it != device_indices.end(); ++it) { | 157 it != device_indices.end(); ++it) { |
| 160 volume_broadcast.dbcv_unitmask |= 0x1 << *it; | 158 volume_broadcast.dbcv_unitmask |= 0x1 << *it; |
| 161 bool removable; | 159 bool removable; |
| 162 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( | 160 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( |
| 163 VolumeMountWatcherWin::DriveNumberToFilePath(*it), | 161 VolumeMountWatcherWin::DriveNumberToFilePath(*it), |
| 164 NULL, NULL, NULL, &removable, NULL)); | 162 NULL, NULL, NULL, &removable, NULL)); |
| 165 if (removable) | 163 if (removable) |
| 166 expect_attach_calls++; | 164 expect_attach_calls++; |
| 167 } | 165 } |
| 168 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, | 166 monitor_->InjectDeviceChange(DBT_DEVICEARRIVAL, |
| 169 reinterpret_cast<DWORD>(&volume_broadcast)); | 167 reinterpret_cast<DWORD>(&volume_broadcast)); |
| 170 | 168 |
| 171 RunUntilIdle(); | 169 RunUntilIdle(); |
| 172 volume_mount_watcher_->FlushWorkerPoolForTesting(); | 170 volume_mount_watcher_->FlushWorkerPoolForTesting(); |
| 173 RunUntilIdle(); | 171 RunUntilIdle(); |
| 174 | 172 |
| 175 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); | 173 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); |
| 176 EXPECT_EQ(0, observer_.detach_calls()); | 174 EXPECT_EQ(0, observer_.detach_calls()); |
| 177 } | 175 } |
| 178 | 176 |
| 179 void RemovableDeviceNotificationsWindowWinTest:: | 177 void StorageMonitorWinTest::DoMassStorageDevicesDetachedTest( |
| 180 DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices) { | 178 const DeviceIndices& device_indices) { |
| 181 DEV_BROADCAST_VOLUME volume_broadcast; | 179 DEV_BROADCAST_VOLUME volume_broadcast; |
| 182 volume_broadcast.dbcv_size = sizeof(volume_broadcast); | 180 volume_broadcast.dbcv_size = sizeof(volume_broadcast); |
| 183 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; | 181 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; |
| 184 volume_broadcast.dbcv_unitmask = 0x0; | 182 volume_broadcast.dbcv_unitmask = 0x0; |
| 185 volume_broadcast.dbcv_flags = 0x0; | 183 volume_broadcast.dbcv_flags = 0x0; |
| 186 | 184 |
| 187 int pre_attach_calls = observer_.attach_calls(); | 185 int pre_attach_calls = observer_.attach_calls(); |
| 188 int expect_detach_calls = 0; | 186 int expect_detach_calls = 0; |
| 189 for (DeviceIndices::const_iterator it = device_indices.begin(); | 187 for (DeviceIndices::const_iterator it = device_indices.begin(); |
| 190 it != device_indices.end(); ++it) { | 188 it != device_indices.end(); ++it) { |
| 191 volume_broadcast.dbcv_unitmask |= 0x1 << *it; | 189 volume_broadcast.dbcv_unitmask |= 0x1 << *it; |
| 192 bool removable; | 190 bool removable; |
| 193 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo( | 191 ASSERT_TRUE(volume_mount_watcher_->GetRawDeviceInfo( |
| 194 VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, NULL, | 192 VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, NULL, |
| 195 NULL, &removable, NULL)); | 193 NULL, &removable, NULL)); |
| 196 if (removable) | 194 if (removable) |
| 197 expect_detach_calls++; | 195 expect_detach_calls++; |
| 198 } | 196 } |
| 199 window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE, | 197 monitor_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE, |
| 200 reinterpret_cast<DWORD>(&volume_broadcast)); | 198 reinterpret_cast<DWORD>(&volume_broadcast)); |
| 201 RunUntilIdle(); | 199 RunUntilIdle(); |
| 202 EXPECT_EQ(pre_attach_calls, observer_.attach_calls()); | 200 EXPECT_EQ(pre_attach_calls, observer_.attach_calls()); |
| 203 EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); | 201 EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); |
| 204 } | 202 } |
| 205 | 203 |
| 206 void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest( | 204 void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id, |
| 207 const string16& pnp_device_id, bool test_attach) { | 205 bool test_attach) { |
| 208 GUID guidDevInterface = GUID_NULL; | 206 GUID guidDevInterface = GUID_NULL; |
| 209 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); | 207 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); |
| 210 if (FAILED(hr)) | 208 if (FAILED(hr)) |
| 211 return; | 209 return; |
| 212 | 210 |
| 213 size_t device_id_size = pnp_device_id.size() * sizeof(char16); | 211 size_t device_id_size = pnp_device_id.size() * sizeof(char16); |
| 214 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size; | 212 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size; |
| 215 scoped_ptr_malloc<DEV_BROADCAST_DEVICEINTERFACE> dev_interface_broadcast( | 213 scoped_ptr_malloc<DEV_BROADCAST_DEVICEINTERFACE> dev_interface_broadcast( |
| 216 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size))); | 214 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size))); |
| 217 DCHECK(dev_interface_broadcast.get()); | 215 DCHECK(dev_interface_broadcast.get()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 233 string16 location; | 231 string16 location; |
| 234 TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it, | 232 TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it, |
| 235 &location, &unique_id, | 233 &location, &unique_id, |
| 236 &name); | 234 &name); |
| 237 if (test_attach && !name.empty() && !unique_id.empty()) | 235 if (test_attach && !name.empty() && !unique_id.empty()) |
| 238 expect_attach_calls++; | 236 expect_attach_calls++; |
| 239 else if (!name.empty() && !unique_id.empty()) | 237 else if (!name.empty() && !unique_id.empty()) |
| 240 expect_detach_calls++; | 238 expect_detach_calls++; |
| 241 } | 239 } |
| 242 | 240 |
| 243 window_->InjectDeviceChange( | 241 monitor_->InjectDeviceChange( |
| 244 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, | 242 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, |
| 245 reinterpret_cast<DWORD>(dev_interface_broadcast.get())); | 243 reinterpret_cast<DWORD>(dev_interface_broadcast.get())); |
| 246 | 244 |
| 247 RunUntilIdle(); | 245 RunUntilIdle(); |
| 248 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); | 246 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); |
| 249 EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); | 247 EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); |
| 250 } | 248 } |
| 251 | 249 |
| 252 bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo( | 250 bool StorageMonitorWinTest::GetMTPStorageInfo( |
| 253 const std::string& storage_device_id, | 251 const std::string& storage_device_id, |
| 254 string16* pnp_device_id, | 252 string16* pnp_device_id, |
| 255 string16* storage_object_id) { | 253 string16* storage_object_id) { |
| 256 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id, | 254 return monitor_->GetMTPStorageInfoFromDeviceId(storage_device_id, |
| 257 pnp_device_id, | 255 pnp_device_id, |
| 258 storage_object_id); | 256 storage_object_id); |
| 259 } | 257 } |
| 260 | 258 |
| 261 TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) { | 259 TEST_F(StorageMonitorWinTest, RandomMessage) { |
| 262 window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL); | 260 monitor_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL); |
| 263 RunUntilIdle(); | 261 RunUntilIdle(); |
| 264 } | 262 } |
| 265 | 263 |
| 266 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) { | 264 TEST_F(StorageMonitorWinTest, DevicesAttached) { |
| 267 DeviceIndices device_indices; | 265 DeviceIndices device_indices; |
| 268 device_indices.push_back(1); // B | 266 device_indices.push_back(1); // B |
| 269 device_indices.push_back(5); // F | 267 device_indices.push_back(5); // F |
| 270 device_indices.push_back(7); // H | 268 device_indices.push_back(7); // H |
| 271 device_indices.push_back(13); // N | 269 device_indices.push_back(13); // N |
| 272 DoMassStorageDeviceAttachedTest(device_indices); | 270 DoMassStorageDeviceAttachedTest(device_indices); |
| 273 | 271 |
| 274 string16 location; | 272 string16 location; |
| 275 std::string unique_id; | 273 std::string unique_id; |
| 276 string16 name; | 274 string16 name; |
| 277 bool removable; | 275 bool removable; |
| 278 EXPECT_TRUE(window_->volume_mount_watcher()->GetDeviceInfo( | 276 EXPECT_TRUE(monitor_->volume_mount_watcher()->GetDeviceInfo( |
| 279 base::FilePath(ASCIIToUTF16("F:\\")), | 277 base::FilePath(ASCIIToUTF16("F:\\")), |
| 280 &location, &unique_id, &name, &removable, NULL)); | 278 &location, &unique_id, &name, &removable, NULL)); |
| 281 EXPECT_EQ(ASCIIToUTF16("F:\\"), location); | 279 EXPECT_EQ(ASCIIToUTF16("F:\\"), location); |
| 282 EXPECT_EQ("\\\\?\\Volume{F0000000-0000-0000-0000-000000000000}\\", unique_id); | 280 EXPECT_EQ("\\\\?\\Volume{F0000000-0000-0000-0000-000000000000}\\", unique_id); |
| 283 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), name); | 281 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), name); |
| 284 | 282 |
| 285 StorageMonitor::StorageInfo info; | 283 StorageMonitor::StorageInfo info; |
| 286 EXPECT_FALSE(window_->GetStorageInfoForPath( | 284 EXPECT_FALSE(monitor_->GetStorageInfoForPath( |
| 287 base::FilePath(ASCIIToUTF16("G:\\")), &info)); | 285 base::FilePath(ASCIIToUTF16("G:\\")), &info)); |
| 288 EXPECT_TRUE(window_->GetStorageInfoForPath( | 286 EXPECT_TRUE(monitor_->GetStorageInfoForPath( |
| 289 base::FilePath(ASCIIToUTF16("F:\\")), &info)); | 287 base::FilePath(ASCIIToUTF16("F:\\")), &info)); |
| 290 StorageMonitor::StorageInfo info1; | 288 StorageMonitor::StorageInfo info1; |
| 291 EXPECT_TRUE(window_->GetStorageInfoForPath( | 289 EXPECT_TRUE(monitor_->GetStorageInfoForPath( |
| 292 base::FilePath(ASCIIToUTF16("F:\\subdir")), &info1)); | 290 base::FilePath(ASCIIToUTF16("F:\\subdir")), &info1)); |
| 293 StorageMonitor::StorageInfo info2; | 291 StorageMonitor::StorageInfo info2; |
| 294 EXPECT_TRUE(window_->GetStorageInfoForPath( | 292 EXPECT_TRUE(monitor_->GetStorageInfoForPath( |
| 295 base::FilePath(ASCIIToUTF16("F:\\subdir\\sub")), &info2)); | 293 base::FilePath(ASCIIToUTF16("F:\\subdir\\sub")), &info2)); |
| 296 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info.name); | 294 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info.name); |
| 297 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info1.name); | 295 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info1.name); |
| 298 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info2.name); | 296 EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info2.name); |
| 299 } | 297 } |
| 300 | 298 |
| 301 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedHighBoundary) { | 299 TEST_F(StorageMonitorWinTest, DevicesAttachedHighBoundary) { |
| 302 DeviceIndices device_indices; | 300 DeviceIndices device_indices; |
| 303 device_indices.push_back(25); | 301 device_indices.push_back(25); |
| 304 | 302 |
| 305 DoMassStorageDeviceAttachedTest(device_indices); | 303 DoMassStorageDeviceAttachedTest(device_indices); |
| 306 } | 304 } |
| 307 | 305 |
| 308 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedLowBoundary) { | 306 TEST_F(StorageMonitorWinTest, DevicesAttachedLowBoundary) { |
| 309 DeviceIndices device_indices; | 307 DeviceIndices device_indices; |
| 310 device_indices.push_back(0); | 308 device_indices.push_back(0); |
| 311 | 309 |
| 312 DoMassStorageDeviceAttachedTest(device_indices); | 310 DoMassStorageDeviceAttachedTest(device_indices); |
| 313 } | 311 } |
| 314 | 312 |
| 315 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedAdjacentBits) { | 313 TEST_F(StorageMonitorWinTest, DevicesAttachedAdjacentBits) { |
| 316 DeviceIndices device_indices; | 314 DeviceIndices device_indices; |
| 317 device_indices.push_back(0); | 315 device_indices.push_back(0); |
| 318 device_indices.push_back(1); | 316 device_indices.push_back(1); |
| 319 device_indices.push_back(2); | 317 device_indices.push_back(2); |
| 320 device_indices.push_back(3); | 318 device_indices.push_back(3); |
| 321 | 319 |
| 322 DoMassStorageDeviceAttachedTest(device_indices); | 320 DoMassStorageDeviceAttachedTest(device_indices); |
| 323 } | 321 } |
| 324 | 322 |
| 325 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesDetached) { | 323 TEST_F(StorageMonitorWinTest, DevicesDetached) { |
| 326 PreAttachDevices(); | 324 PreAttachDevices(); |
| 327 | 325 |
| 328 DeviceIndices device_indices; | 326 DeviceIndices device_indices; |
| 329 device_indices.push_back(1); | 327 device_indices.push_back(1); |
| 330 device_indices.push_back(5); | 328 device_indices.push_back(5); |
| 331 device_indices.push_back(7); | 329 device_indices.push_back(7); |
| 332 device_indices.push_back(13); | 330 device_indices.push_back(13); |
| 333 | 331 |
| 334 DoMassStorageDevicesDetachedTest(device_indices); | 332 DoMassStorageDevicesDetachedTest(device_indices); |
| 335 } | 333 } |
| 336 | 334 |
| 337 TEST_F(RemovableDeviceNotificationsWindowWinTest, | 335 TEST_F(StorageMonitorWinTest, DevicesDetachedHighBoundary) { |
| 338 DevicesDetachedHighBoundary) { | |
| 339 PreAttachDevices(); | 336 PreAttachDevices(); |
| 340 | 337 |
| 341 DeviceIndices device_indices; | 338 DeviceIndices device_indices; |
| 342 device_indices.push_back(25); | 339 device_indices.push_back(25); |
| 343 | 340 |
| 344 DoMassStorageDevicesDetachedTest(device_indices); | 341 DoMassStorageDevicesDetachedTest(device_indices); |
| 345 } | 342 } |
| 346 | 343 |
| 347 TEST_F(RemovableDeviceNotificationsWindowWinTest, | 344 TEST_F(StorageMonitorWinTest, DevicesDetachedLowBoundary) { |
| 348 DevicesDetachedLowBoundary) { | |
| 349 PreAttachDevices(); | 345 PreAttachDevices(); |
| 350 | 346 |
| 351 DeviceIndices device_indices; | 347 DeviceIndices device_indices; |
| 352 device_indices.push_back(0); | 348 device_indices.push_back(0); |
| 353 | 349 |
| 354 DoMassStorageDevicesDetachedTest(device_indices); | 350 DoMassStorageDevicesDetachedTest(device_indices); |
| 355 } | 351 } |
| 356 | 352 |
| 357 TEST_F(RemovableDeviceNotificationsWindowWinTest, | 353 TEST_F(StorageMonitorWinTest, DevicesDetachedAdjacentBits) { |
| 358 DevicesDetachedAdjacentBits) { | |
| 359 PreAttachDevices(); | 354 PreAttachDevices(); |
| 360 | 355 |
| 361 DeviceIndices device_indices; | 356 DeviceIndices device_indices; |
| 362 device_indices.push_back(0); | 357 device_indices.push_back(0); |
| 363 device_indices.push_back(1); | 358 device_indices.push_back(1); |
| 364 device_indices.push_back(2); | 359 device_indices.push_back(2); |
| 365 device_indices.push_back(3); | 360 device_indices.push_back(3); |
| 366 | 361 |
| 367 DoMassStorageDevicesDetachedTest(device_indices); | 362 DoMassStorageDevicesDetachedTest(device_indices); |
| 368 } | 363 } |
| 369 | 364 |
| 370 TEST_F(RemovableDeviceNotificationsWindowWinTest, | 365 TEST_F(StorageMonitorWinTest, DuplicateAttachCheckSuppressed) { |
| 371 DuplicateAttachCheckSuppressed) { | |
| 372 volume_mount_watcher_->BlockDeviceCheckForTesting(); | 366 volume_mount_watcher_->BlockDeviceCheckForTesting(); |
| 373 base::FilePath kAttachedDevicePath = | 367 base::FilePath kAttachedDevicePath = |
| 374 VolumeMountWatcherWin::DriveNumberToFilePath(8); // I: | 368 VolumeMountWatcherWin::DriveNumberToFilePath(8); // I: |
| 375 | 369 |
| 376 DEV_BROADCAST_VOLUME volume_broadcast; | 370 DEV_BROADCAST_VOLUME volume_broadcast; |
| 377 volume_broadcast.dbcv_size = sizeof(volume_broadcast); | 371 volume_broadcast.dbcv_size = sizeof(volume_broadcast); |
| 378 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; | 372 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; |
| 379 volume_broadcast.dbcv_flags = 0x0; | 373 volume_broadcast.dbcv_flags = 0x0; |
| 380 volume_broadcast.dbcv_unitmask = 0x100; // I: drive | 374 volume_broadcast.dbcv_unitmask = 0x100; // I: drive |
| 381 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, | 375 monitor_->InjectDeviceChange(DBT_DEVICEARRIVAL, |
| 382 reinterpret_cast<DWORD>(&volume_broadcast)); | 376 reinterpret_cast<DWORD>(&volume_broadcast)); |
| 383 | 377 |
| 384 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); | 378 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); |
| 385 | 379 |
| 386 // Re-attach the same volume. We haven't released the mock device check | 380 // Re-attach the same volume. We haven't released the mock device check |
| 387 // event, so there'll be pending calls in the UI thread to finish the | 381 // event, so there'll be pending calls in the UI thread to finish the |
| 388 // device check notification, blocking the duplicate device injection. | 382 // device check notification, blocking the duplicate device injection. |
| 389 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, | 383 monitor_->InjectDeviceChange(DBT_DEVICEARRIVAL, |
| 390 reinterpret_cast<DWORD>(&volume_broadcast)); | 384 reinterpret_cast<DWORD>(&volume_broadcast)); |
| 391 | 385 |
| 392 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); | 386 EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size()); |
| 393 volume_mount_watcher_->ReleaseDeviceCheck(); | 387 volume_mount_watcher_->ReleaseDeviceCheck(); |
| 394 RunUntilIdle(); | 388 RunUntilIdle(); |
| 395 volume_mount_watcher_->ReleaseDeviceCheck(); | 389 volume_mount_watcher_->ReleaseDeviceCheck(); |
| 396 | 390 |
| 397 // Now let all attach notifications finish running. We'll only get one | 391 // Now let all attach notifications finish running. We'll only get one |
| 398 // finish-attach call. | 392 // finish-attach call. |
| 399 volume_mount_watcher_->FlushWorkerPoolForTesting(); | 393 volume_mount_watcher_->FlushWorkerPoolForTesting(); |
| 400 RunUntilIdle(); | 394 RunUntilIdle(); |
| 401 | 395 |
| 402 std::vector<base::FilePath> checked_devices = | 396 std::vector<base::FilePath> checked_devices = |
| 403 volume_mount_watcher_->devices_checked(); | 397 volume_mount_watcher_->devices_checked(); |
| 404 ASSERT_EQ(1u, checked_devices.size()); | 398 ASSERT_EQ(1u, checked_devices.size()); |
| 405 EXPECT_EQ(kAttachedDevicePath, checked_devices[0]); | 399 EXPECT_EQ(kAttachedDevicePath, checked_devices[0]); |
| 406 | 400 |
| 407 // We'll receive a duplicate check now that the first check has fully cleared. | 401 // We'll receive a duplicate check now that the first check has fully cleared. |
| 408 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, | 402 monitor_->InjectDeviceChange(DBT_DEVICEARRIVAL, |
| 409 reinterpret_cast<DWORD>(&volume_broadcast)); | 403 reinterpret_cast<DWORD>(&volume_broadcast)); |
| 410 volume_mount_watcher_->FlushWorkerPoolForTesting(); | 404 volume_mount_watcher_->FlushWorkerPoolForTesting(); |
| 411 volume_mount_watcher_->ReleaseDeviceCheck(); | 405 volume_mount_watcher_->ReleaseDeviceCheck(); |
| 412 RunUntilIdle(); | 406 RunUntilIdle(); |
| 413 | 407 |
| 414 checked_devices = volume_mount_watcher_->devices_checked(); | 408 checked_devices = volume_mount_watcher_->devices_checked(); |
| 415 ASSERT_EQ(2u, checked_devices.size()); | 409 ASSERT_EQ(2u, checked_devices.size()); |
| 416 EXPECT_EQ(kAttachedDevicePath, checked_devices[0]); | 410 EXPECT_EQ(kAttachedDevicePath, checked_devices[0]); |
| 417 EXPECT_EQ(kAttachedDevicePath, checked_devices[1]); | 411 EXPECT_EQ(kAttachedDevicePath, checked_devices[1]); |
| 418 } | 412 } |
| 419 | 413 |
| 420 TEST_F(RemovableDeviceNotificationsWindowWinTest, DeviceInfoForPath) { | 414 TEST_F(StorageMonitorWinTest, DeviceInfoForPath) { |
| 421 PreAttachDevices(); | 415 PreAttachDevices(); |
| 422 | 416 |
| 423 // An invalid path. | 417 // An invalid path. |
| 424 EXPECT_FALSE(window_->GetStorageInfoForPath(base::FilePath(L"COM1:\\"), | 418 EXPECT_FALSE(monitor_->GetStorageInfoForPath(base::FilePath(L"COM1:\\"), |
| 425 NULL)); | 419 NULL)); |
| 426 | 420 |
| 427 // An unconnected removable device. | 421 // An unconnected removable device. |
| 428 EXPECT_FALSE(window_->GetStorageInfoForPath(base::FilePath(L"E:\\"), NULL)); | 422 EXPECT_FALSE(monitor_->GetStorageInfoForPath(base::FilePath(L"E:\\"), NULL)); |
| 429 | 423 |
| 430 // A connected removable device. | 424 // A connected removable device. |
| 431 base::FilePath removable_device(L"F:\\"); | 425 base::FilePath removable_device(L"F:\\"); |
| 432 StorageMonitor::StorageInfo device_info; | 426 StorageMonitor::StorageInfo device_info; |
| 433 EXPECT_TRUE(window_->GetStorageInfoForPath(removable_device, &device_info)); | 427 EXPECT_TRUE(monitor_->GetStorageInfoForPath(removable_device, &device_info)); |
| 434 | 428 |
| 435 std::string unique_id; | 429 std::string unique_id; |
| 436 string16 device_name; | 430 string16 device_name; |
| 437 string16 location; | 431 string16 location; |
| 438 bool removable; | 432 bool removable; |
| 439 uint64 total_size_in_bytes; | 433 uint64 total_size_in_bytes; |
| 440 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( | 434 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( |
| 441 removable_device, &location, &unique_id, &device_name, &removable, | 435 removable_device, &location, &unique_id, &device_name, &removable, |
| 442 &total_size_in_bytes)); | 436 &total_size_in_bytes)); |
| 443 EXPECT_TRUE(removable); | 437 EXPECT_TRUE(removable); |
| 444 std::string device_id = MediaStorageUtil::MakeDeviceId( | 438 std::string device_id = MediaStorageUtil::MakeDeviceId( |
| 445 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, unique_id); | 439 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, unique_id); |
| 446 EXPECT_EQ(device_id, device_info.device_id); | 440 EXPECT_EQ(device_id, device_info.device_id); |
| 447 EXPECT_EQ(device_name, device_info.name); | 441 EXPECT_EQ(device_name, device_info.name); |
| 448 EXPECT_EQ(removable_device.value(), device_info.location); | 442 EXPECT_EQ(removable_device.value(), device_info.location); |
| 449 EXPECT_EQ(1000000, total_size_in_bytes); | 443 EXPECT_EQ(1000000, total_size_in_bytes); |
| 450 | 444 |
| 451 // A fixed device. | 445 // A fixed device. |
| 452 base::FilePath fixed_device(L"N:\\"); | 446 base::FilePath fixed_device(L"N:\\"); |
| 453 EXPECT_TRUE(window_->GetStorageInfoForPath(fixed_device, &device_info)); | 447 EXPECT_TRUE(monitor_->GetStorageInfoForPath(fixed_device, &device_info)); |
| 454 | 448 |
| 455 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( | 449 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( |
| 456 fixed_device, &location, &unique_id, &device_name, &removable, NULL)); | 450 fixed_device, &location, &unique_id, &device_name, &removable, NULL)); |
| 457 EXPECT_FALSE(removable); | 451 EXPECT_FALSE(removable); |
| 458 device_id = MediaStorageUtil::MakeDeviceId( | 452 device_id = MediaStorageUtil::MakeDeviceId( |
| 459 MediaStorageUtil::FIXED_MASS_STORAGE, unique_id); | 453 MediaStorageUtil::FIXED_MASS_STORAGE, unique_id); |
| 460 EXPECT_EQ(device_id, device_info.device_id); | 454 EXPECT_EQ(device_id, device_info.device_id); |
| 461 EXPECT_EQ(device_name, device_info.name); | 455 EXPECT_EQ(device_name, device_info.name); |
| 462 EXPECT_EQ(fixed_device.value(), device_info.location); | 456 EXPECT_EQ(fixed_device.value(), device_info.location); |
| 463 } | 457 } |
| 464 | 458 |
| 465 // Test to verify basic MTP storage attach and detach notifications. | 459 // Test to verify basic MTP storage attach and detach notifications. |
| 466 TEST_F(RemovableDeviceNotificationsWindowWinTest, MTPDeviceBasicAttachDetach) { | 460 TEST_F(StorageMonitorWinTest, MTPDeviceBasicAttachDetach) { |
| 467 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true); | 461 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true); |
| 468 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); | 462 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); |
| 469 } | 463 } |
| 470 | 464 |
| 471 // When a MTP storage device with invalid storage label and id is | 465 // When a MTP storage device with invalid storage label and id is |
| 472 // attached/detached, there should not be any device attach/detach | 466 // attached/detached, there should not be any device attach/detach |
| 473 // notifications. | 467 // notifications. |
| 474 TEST_F(RemovableDeviceNotificationsWindowWinTest, MTPDeviceWithInvalidInfo) { | 468 TEST_F(StorageMonitorWinTest, MTPDeviceWithInvalidInfo) { |
| 475 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo, | 469 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo, |
| 476 true); | 470 true); |
| 477 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo, | 471 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo, |
| 478 false); | 472 false); |
| 479 } | 473 } |
| 480 | 474 |
| 481 // Attach a device with two data partitions. Verify that attach/detach | 475 // Attach a device with two data partitions. Verify that attach/detach |
| 482 // notifications are sent out for each removable storage. | 476 // notifications are sent out for each removable storage. |
| 483 TEST_F(RemovableDeviceNotificationsWindowWinTest, | 477 TEST_F(StorageMonitorWinTest, MTPDeviceWithMultipleStorageObjects) { |
| 484 MTPDeviceWithMultipleStorageObjects) { | |
| 485 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages, | 478 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages, |
| 486 true); | 479 true); |
| 487 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages, | 480 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages, |
| 488 false); | 481 false); |
| 489 } | 482 } |
| 490 | 483 |
| 491 TEST_F(RemovableDeviceNotificationsWindowWinTest, DriveNumberToFilePath) { | 484 TEST_F(StorageMonitorWinTest, DriveNumberToFilePath) { |
| 492 EXPECT_EQ(L"A:\\", VolumeMountWatcherWin::DriveNumberToFilePath(0).value()); | 485 EXPECT_EQ(L"A:\\", VolumeMountWatcherWin::DriveNumberToFilePath(0).value()); |
| 493 EXPECT_EQ(L"Y:\\", VolumeMountWatcherWin::DriveNumberToFilePath(24).value()); | 486 EXPECT_EQ(L"Y:\\", VolumeMountWatcherWin::DriveNumberToFilePath(24).value()); |
| 494 EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(-1).value()); | 487 EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(-1).value()); |
| 495 EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(199).value()); | 488 EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(199).value()); |
| 496 } | 489 } |
| 497 | 490 |
| 498 // Given a MTP storage persistent id, GetMTPStorageInfo() should fetch the | 491 // Given a MTP storage persistent id, GetMTPStorageInfo() should fetch the |
| 499 // device interface path and local storage object identifier. | 492 // device interface path and local storage object identifier. |
| 500 TEST_F(RemovableDeviceNotificationsWindowWinTest, | 493 TEST_F(StorageMonitorWinTest, GetMTPStorageInfoFromDeviceId) { |
| 501 GetMTPStorageInfoFromDeviceId) { | |
| 502 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true); | 494 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true); |
| 503 PortableDeviceWatcherWin::StorageObjects storage_objects = | 495 PortableDeviceWatcherWin::StorageObjects storage_objects = |
| 504 TestPortableDeviceWatcherWin::GetDeviceStorageObjects( | 496 TestPortableDeviceWatcherWin::GetDeviceStorageObjects( |
| 505 TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo); | 497 TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo); |
| 506 for (PortableDeviceWatcherWin::StorageObjects::const_iterator it = | 498 for (PortableDeviceWatcherWin::StorageObjects::const_iterator it = |
| 507 storage_objects.begin(); | 499 storage_objects.begin(); |
| 508 it != storage_objects.end(); ++it) { | 500 it != storage_objects.end(); ++it) { |
| 509 string16 pnp_device_id; | 501 string16 pnp_device_id; |
| 510 string16 storage_object_id; | 502 string16 storage_object_id; |
| 511 ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id, | 503 ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id, |
| 512 &storage_object_id)); | 504 &storage_object_id)); |
| 513 EXPECT_EQ(string16(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo), | 505 EXPECT_EQ(string16(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo), |
| 514 pnp_device_id); | 506 pnp_device_id); |
| 515 EXPECT_EQ(it->object_persistent_id, | 507 EXPECT_EQ(it->object_persistent_id, |
| 516 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( | 508 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( |
| 517 pnp_device_id, storage_object_id)); | 509 pnp_device_id, storage_object_id)); |
| 518 } | 510 } |
| 519 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); | 511 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); |
| 520 } | 512 } |
| 521 | 513 |
| 522 } // namespace test | 514 } // namespace test |
| 523 } // namespace chrome | 515 } // namespace chrome |
| OLD | NEW |