Chromium Code Reviews| 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/system_monitor/system_monitor.h" | |
| 15 #include "base/test/mock_devices_changed_observer.h" | |
| 16 #include "chrome/browser/system_monitor/media_storage_util.h" | 14 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 15 #include "chrome/browser/system_monitor/mock_removable_storage_observer.h" | |
| 17 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" | 16 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" |
| 18 #include "chrome/browser/system_monitor/removable_device_constants.h" | 17 #include "chrome/browser/system_monitor/removable_device_constants.h" |
| 19 #include "chrome/browser/system_monitor/test_portable_device_watcher_win.h" | 18 #include "chrome/browser/system_monitor/test_portable_device_watcher_win.h" |
| 20 #include "chrome/browser/system_monitor/test_removable_device_notifications_wind ow_win.h" | 19 #include "chrome/browser/system_monitor/test_removable_device_notifications_wind ow_win.h" |
| 21 #include "chrome/browser/system_monitor/test_volume_mount_watcher_win.h" | 20 #include "chrome/browser/system_monitor/test_volume_mount_watcher_win.h" |
| 22 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" | 21 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 24 |
| 27 namespace chrome { | 25 namespace chrome { |
| 28 namespace test { | 26 namespace test { |
| 29 | 27 |
| 30 using content::BrowserThread; | 28 using content::BrowserThread; |
| 31 | 29 |
| 32 typedef std::vector<int> DeviceIndices; | 30 typedef std::vector<int> DeviceIndices; |
| 33 | 31 |
| 34 // RemovableDeviceNotificationsWindowWinTest ----------------------------------- | 32 // RemovableDeviceNotificationsWindowWinTest ----------------------------------- |
| 35 | 33 |
| 36 class RemovableDeviceNotificationsWindowWinTest : public testing::Test { | 34 class RemovableDeviceNotificationsWindowWinTest : public testing::Test { |
| 37 public: | 35 public: |
| 38 RemovableDeviceNotificationsWindowWinTest(); | 36 RemovableDeviceNotificationsWindowWinTest(); |
| 39 virtual ~RemovableDeviceNotificationsWindowWinTest(); | 37 virtual ~RemovableDeviceNotificationsWindowWinTest(); |
| 40 | 38 |
| 41 protected: | 39 protected: |
| 42 // testing::Test: | 40 // testing::Test: |
| 43 virtual void SetUp() OVERRIDE; | 41 virtual void SetUp() OVERRIDE; |
| 44 virtual void TearDown() OVERRIDE; | 42 virtual void TearDown() OVERRIDE; |
| 45 | 43 |
| 46 void AddMassStorageDeviceAttachExpectation(const FilePath& drive); | |
| 47 void PreAttachDevices(); | 44 void PreAttachDevices(); |
| 48 | 45 |
| 49 // Runs all the pending tasks on UI thread, FILE thread and blocking thread. | 46 // Runs all the pending tasks on UI thread, FILE thread and blocking thread. |
| 50 void RunUntilIdle(); | 47 void RunUntilIdle(); |
| 51 | 48 |
| 52 void DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices); | 49 void DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices); |
| 53 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices); | 50 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices); |
| 54 | 51 |
| 55 // Injects a device attach or detach change (depending on the value of | 52 // Injects a device attach or detach change (depending on the value of |
| 56 // |test_attach|) and tests that the appropriate handler is called. | 53 // |test_attach|) and tests that the appropriate handler is called. |
| 57 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach); | 54 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach); |
| 58 | 55 |
| 59 // Gets the MTP details of the storage specified by the |storage_device_id|. | 56 // 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 | 57 // On success, returns true and fills in |pnp_device_id| and |
| 61 // |storage_object_id|. | 58 // |storage_object_id|. |
| 62 bool GetMTPStorageInfo(const std::string& storage_device_id, | 59 bool GetMTPStorageInfo(const std::string& storage_device_id, |
| 63 string16* pnp_device_id, | 60 string16* pnp_device_id, |
| 64 string16* storage_object_id); | 61 string16* storage_object_id); |
| 65 | 62 |
| 66 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_; | 63 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_; |
| 67 scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_; | 64 scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_; |
| 68 | 65 |
| 69 private: | 66 private: |
| 70 MessageLoopForUI message_loop_; | 67 MessageLoopForUI message_loop_; |
| 71 content::TestBrowserThread ui_thread_; | 68 content::TestBrowserThread ui_thread_; |
| 72 content::TestBrowserThread file_thread_; | 69 content::TestBrowserThread file_thread_; |
| 73 | 70 |
| 74 base::SystemMonitor system_monitor_; | 71 MockRemovableStorageObserver observer_; |
| 75 base::MockDevicesChangedObserver observer_; | |
| 76 }; | 72 }; |
| 77 | 73 |
| 78 RemovableDeviceNotificationsWindowWinTest:: | 74 RemovableDeviceNotificationsWindowWinTest:: |
| 79 RemovableDeviceNotificationsWindowWinTest() | 75 RemovableDeviceNotificationsWindowWinTest() |
| 80 : ui_thread_(BrowserThread::UI, &message_loop_), | 76 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 81 file_thread_(BrowserThread::FILE, &message_loop_) { | 77 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 82 } | 78 } |
| 83 | 79 |
| 84 RemovableDeviceNotificationsWindowWinTest:: | 80 RemovableDeviceNotificationsWindowWinTest:: |
| 85 ~RemovableDeviceNotificationsWindowWinTest() { | 81 ~RemovableDeviceNotificationsWindowWinTest() { |
| 86 } | 82 } |
| 87 | 83 |
| 88 void RemovableDeviceNotificationsWindowWinTest::SetUp() { | 84 void RemovableDeviceNotificationsWindowWinTest::SetUp() { |
| 89 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 85 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 90 volume_mount_watcher_ = new TestVolumeMountWatcherWin; | 86 volume_mount_watcher_ = new TestVolumeMountWatcherWin; |
| 91 window_.reset(new TestRemovableDeviceNotificationsWindowWin( | 87 window_.reset(new TestRemovableDeviceNotificationsWindowWin( |
| 92 volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin)); | 88 volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin)); |
| 93 window_->InitWithTestData(false); | 89 window_->InitWithTestData(false); |
| 94 RunUntilIdle(); | 90 RunUntilIdle(); |
| 95 system_monitor_.AddDevicesChangedObserver(&observer_); | 91 window_->AddObserver(&observer_); |
| 96 } | 92 } |
| 97 | 93 |
| 98 void RemovableDeviceNotificationsWindowWinTest::TearDown() { | 94 void RemovableDeviceNotificationsWindowWinTest::TearDown() { |
| 99 RunUntilIdle(); | 95 RunUntilIdle(); |
| 100 system_monitor_.RemoveDevicesChangedObserver(&observer_); | 96 window_->RemoveObserver(&observer_); |
| 101 } | |
| 102 | |
| 103 void RemovableDeviceNotificationsWindowWinTest:: | |
| 104 AddMassStorageDeviceAttachExpectation(const FilePath& drive) { | |
| 105 std::string unique_id; | |
| 106 string16 device_name; | |
| 107 bool removable; | |
| 108 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( | |
| 109 drive, NULL, &unique_id, &device_name, &removable)); | |
| 110 if (removable) { | |
| 111 MediaStorageUtil::Type type = | |
| 112 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | |
| 113 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | |
| 114 EXPECT_CALL(observer_, OnRemovableStorageAttached(device_id, device_name, | |
| 115 drive.value())) | |
| 116 .Times(1); | |
| 117 } | |
| 118 } | 97 } |
| 119 | 98 |
| 120 void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() { | 99 void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() { |
| 121 window_.reset(); | 100 window_.reset(); |
| 101 int expect_attach_calls = 0; | |
| 122 { | 102 { |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
Remove the scope too now that InSequence is gone
Greg Billock
2013/01/24 20:46:03
Done.
| |
| 123 testing::InSequence sequence; | |
| 124 ASSERT_TRUE(volume_mount_watcher_.get()); | 103 ASSERT_TRUE(volume_mount_watcher_.get()); |
| 125 volume_mount_watcher_->set_pre_attach_devices(true); | 104 volume_mount_watcher_->set_pre_attach_devices(true); |
| 126 std::vector<FilePath> initial_devices = | 105 std::vector<FilePath> initial_devices = |
| 127 volume_mount_watcher_->GetAttachedDevices(); | 106 volume_mount_watcher_->GetAttachedDevices(); |
| 128 for (std::vector<FilePath>::const_iterator it = initial_devices.begin(); | 107 for (std::vector<FilePath>::const_iterator it = initial_devices.begin(); |
| 129 it != initial_devices.end(); ++it) { | 108 it != initial_devices.end(); ++it) { |
| 130 AddMassStorageDeviceAttachExpectation(*it); | 109 std::string unique_id; |
| 110 string16 device_name; | |
| 111 bool removable; | |
| 112 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( | |
| 113 *it, NULL, &unique_id, &device_name, &removable)); | |
| 114 if (removable) | |
| 115 expect_attach_calls++; | |
| 131 } | 116 } |
| 132 } | 117 } |
| 133 window_.reset(new TestRemovableDeviceNotificationsWindowWin( | 118 window_.reset(new TestRemovableDeviceNotificationsWindowWin( |
| 134 volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin)); | 119 volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin)); |
| 135 window_->InitWithTestData(true); | 120 window_->InitWithTestData(true); |
| 121 | |
| 136 RunUntilIdle(); | 122 RunUntilIdle(); |
| 123 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); | |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
nit: check detach count
Greg Billock
2013/01/24 20:46:03
Done.
| |
| 137 } | 124 } |
| 138 | 125 |
| 139 void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() { | 126 void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() { |
| 140 message_loop_.RunUntilIdle(); | 127 message_loop_.RunUntilIdle(); |
| 141 } | 128 } |
| 142 | 129 |
| 143 void RemovableDeviceNotificationsWindowWinTest:: | 130 void RemovableDeviceNotificationsWindowWinTest:: |
| 144 DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices) { | 131 DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices) { |
| 145 DEV_BROADCAST_VOLUME volume_broadcast; | 132 DEV_BROADCAST_VOLUME volume_broadcast; |
| 146 volume_broadcast.dbcv_size = sizeof(volume_broadcast); | 133 volume_broadcast.dbcv_size = sizeof(volume_broadcast); |
| 147 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; | 134 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; |
| 148 volume_broadcast.dbcv_unitmask = 0x0; | 135 volume_broadcast.dbcv_unitmask = 0x0; |
| 149 volume_broadcast.dbcv_flags = 0x0; | 136 volume_broadcast.dbcv_flags = 0x0; |
| 137 int expect_attach_calls = 0; | |
| 150 { | 138 { |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
Remove the scope too now that InSequence is gone
Greg Billock
2013/01/24 20:46:03
Done.
| |
| 151 testing::InSequence sequence; | |
| 152 for (DeviceIndices::const_iterator it = device_indices.begin(); | 139 for (DeviceIndices::const_iterator it = device_indices.begin(); |
| 153 it != device_indices.end(); ++it) { | 140 it != device_indices.end(); ++it) { |
| 154 volume_broadcast.dbcv_unitmask |= 0x1 << *it; | 141 volume_broadcast.dbcv_unitmask |= 0x1 << *it; |
| 155 AddMassStorageDeviceAttachExpectation( | 142 std::string unique_id; |
| 156 VolumeMountWatcherWin::DriveNumberToFilePath(*it)); | 143 string16 device_name; |
| 144 bool removable; | |
| 145 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( | |
| 146 VolumeMountWatcherWin::DriveNumberToFilePath(*it), | |
| 147 NULL, &unique_id, &device_name, &removable)); | |
| 148 if (removable) | |
| 149 expect_attach_calls++; | |
| 157 } | 150 } |
| 158 } | 151 } |
| 159 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, | 152 window_->InjectDeviceChange(DBT_DEVICEARRIVAL, |
| 160 reinterpret_cast<DWORD>(&volume_broadcast)); | 153 reinterpret_cast<DWORD>(&volume_broadcast)); |
| 154 | |
| 161 RunUntilIdle(); | 155 RunUntilIdle(); |
| 156 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); | |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
nit: check detach count
Greg Billock
2013/01/24 20:46:03
Done.
| |
| 162 } | 157 } |
| 163 | 158 |
| 164 void RemovableDeviceNotificationsWindowWinTest:: | 159 void RemovableDeviceNotificationsWindowWinTest:: |
| 165 DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices) { | 160 DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices) { |
| 166 DEV_BROADCAST_VOLUME volume_broadcast; | 161 DEV_BROADCAST_VOLUME volume_broadcast; |
| 167 volume_broadcast.dbcv_size = sizeof(volume_broadcast); | 162 volume_broadcast.dbcv_size = sizeof(volume_broadcast); |
| 168 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; | 163 volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME; |
| 169 volume_broadcast.dbcv_unitmask = 0x0; | 164 volume_broadcast.dbcv_unitmask = 0x0; |
| 170 volume_broadcast.dbcv_flags = 0x0; | 165 volume_broadcast.dbcv_flags = 0x0; |
| 166 int expect_detach_calls = 0; | |
| 171 { | 167 { |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
Remove the scope too now that InSequence is gone
Greg Billock
2013/01/24 20:46:03
Done.
| |
| 172 testing::InSequence sequence; | |
| 173 for (DeviceIndices::const_iterator it = device_indices.begin(); | 168 for (DeviceIndices::const_iterator it = device_indices.begin(); |
| 174 it != device_indices.end(); ++it) { | 169 it != device_indices.end(); ++it) { |
| 175 volume_broadcast.dbcv_unitmask |= 0x1 << *it; | 170 volume_broadcast.dbcv_unitmask |= 0x1 << *it; |
| 176 std::string unique_id; | 171 std::string unique_id; |
| 177 bool removable; | 172 bool removable; |
| 178 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( | 173 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( |
| 179 VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, &unique_id, | 174 VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, &unique_id, |
| 180 NULL, &removable)); | 175 NULL, &removable)); |
| 181 if (removable) { | 176 if (removable) |
| 182 MediaStorageUtil::Type type = | 177 expect_detach_calls++; |
| 183 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | |
| 184 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | |
| 185 EXPECT_CALL(observer_, OnRemovableStorageDetached(device_id)).Times(1); | |
| 186 } | |
| 187 } | 178 } |
| 188 } | 179 } |
| 189 window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE, | 180 window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE, |
| 190 reinterpret_cast<DWORD>(&volume_broadcast)); | 181 reinterpret_cast<DWORD>(&volume_broadcast)); |
| 191 RunUntilIdle(); | 182 RunUntilIdle(); |
| 183 EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); | |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
nit: check attach count
Greg Billock
2013/01/24 20:46:03
Done.
| |
| 192 } | 184 } |
| 193 | 185 |
| 194 void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest( | 186 void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest( |
| 195 const string16& pnp_device_id, bool test_attach) { | 187 const string16& pnp_device_id, bool test_attach) { |
| 196 GUID guidDevInterface = GUID_NULL; | 188 GUID guidDevInterface = GUID_NULL; |
| 197 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); | 189 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); |
| 198 if (FAILED(hr)) | 190 if (FAILED(hr)) |
| 199 return; | 191 return; |
| 200 | 192 |
| 201 size_t device_id_size = pnp_device_id.size() * sizeof(char16); | 193 size_t device_id_size = pnp_device_id.size() * sizeof(char16); |
| 202 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size; | 194 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size; |
| 203 scoped_ptr_malloc<DEV_BROADCAST_DEVICEINTERFACE> dev_interface_broadcast( | 195 scoped_ptr_malloc<DEV_BROADCAST_DEVICEINTERFACE> dev_interface_broadcast( |
| 204 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size))); | 196 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size))); |
| 205 DCHECK(dev_interface_broadcast.get()); | 197 DCHECK(dev_interface_broadcast.get()); |
| 206 ZeroMemory(dev_interface_broadcast.get(), size); | 198 ZeroMemory(dev_interface_broadcast.get(), size); |
| 207 dev_interface_broadcast->dbcc_size = size; | 199 dev_interface_broadcast->dbcc_size = size; |
| 208 dev_interface_broadcast->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; | 200 dev_interface_broadcast->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; |
| 209 dev_interface_broadcast->dbcc_classguid = guidDevInterface; | 201 dev_interface_broadcast->dbcc_classguid = guidDevInterface; |
| 210 memcpy(dev_interface_broadcast->dbcc_name, pnp_device_id.data(), | 202 memcpy(dev_interface_broadcast->dbcc_name, pnp_device_id.data(), |
| 211 device_id_size); | 203 device_id_size); |
| 204 | |
| 205 int expect_attach_calls = observer_.attach_calls(); | |
| 206 int expect_detach_calls = observer_.detach_calls(); | |
| 212 { | 207 { |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
Remove the scope too now that InSequence is gone
Greg Billock
2013/01/24 20:46:03
Done.
| |
| 213 testing::InSequence sequence; | |
| 214 PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids = | 208 PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids = |
| 215 TestPortableDeviceWatcherWin::GetMTPStorageObjectIds(pnp_device_id); | 209 TestPortableDeviceWatcherWin::GetMTPStorageObjectIds(pnp_device_id); |
| 216 for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it = | 210 for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it = |
| 217 storage_object_ids.begin(); it != storage_object_ids.end(); ++it) { | 211 storage_object_ids.begin(); it != storage_object_ids.end(); ++it) { |
| 218 std::string unique_id; | 212 std::string unique_id; |
| 219 string16 name; | 213 string16 name; |
| 220 string16 location; | 214 string16 location; |
| 221 TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it, | 215 TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it, |
| 222 &location, &unique_id, | 216 &location, &unique_id, |
| 223 &name); | 217 &name); |
| 224 if (test_attach) { | 218 if (test_attach && !name.empty() && !unique_id.empty()) |
| 225 EXPECT_CALL(observer_, OnRemovableStorageAttached(unique_id, name, | 219 expect_attach_calls++; |
| 226 location)) | 220 else if (!name.empty() && !unique_id.empty()) |
| 227 .Times((name.empty() || unique_id.empty()) ? 0 : 1); | 221 expect_detach_calls++; |
| 228 } else { | |
| 229 EXPECT_CALL(observer_, OnRemovableStorageDetached(unique_id)) | |
| 230 .Times((name.empty() || unique_id.empty()) ? 0 : 1); | |
| 231 } | |
| 232 } | 222 } |
| 233 } | 223 } |
| 224 | |
| 234 window_->InjectDeviceChange( | 225 window_->InjectDeviceChange( |
| 235 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, | 226 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, |
| 236 reinterpret_cast<DWORD>(dev_interface_broadcast.get())); | 227 reinterpret_cast<DWORD>(dev_interface_broadcast.get())); |
| 228 | |
| 237 RunUntilIdle(); | 229 RunUntilIdle(); |
| 230 EXPECT_EQ(expect_attach_calls, observer_.attach_calls()); | |
| 231 EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); | |
| 238 } | 232 } |
| 239 | 233 |
| 240 bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo( | 234 bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo( |
| 241 const std::string& storage_device_id, | 235 const std::string& storage_device_id, |
| 242 string16* pnp_device_id, | 236 string16* pnp_device_id, |
| 243 string16* storage_object_id) { | 237 string16* storage_object_id) { |
| 244 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id, | 238 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id, |
| 245 pnp_device_id, | 239 pnp_device_id, |
| 246 storage_object_id); | 240 storage_object_id); |
| 247 } | 241 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 PreAttachDevices(); | 333 PreAttachDevices(); |
| 340 | 334 |
| 341 // An invalid path. | 335 // An invalid path. |
| 342 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"COM1:\\"), NULL)); | 336 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"COM1:\\"), NULL)); |
| 343 | 337 |
| 344 // An unconnected removable device. | 338 // An unconnected removable device. |
| 345 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"E:\\"), NULL)); | 339 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"E:\\"), NULL)); |
| 346 | 340 |
| 347 // A connected removable device. | 341 // A connected removable device. |
| 348 FilePath removable_device(L"F:\\"); | 342 FilePath removable_device(L"F:\\"); |
| 349 base::SystemMonitor::RemovableStorageInfo device_info; | 343 RemovableStorageNotifications::StorageInfo device_info; |
| 350 EXPECT_TRUE(window_->GetDeviceInfoForPath(removable_device, &device_info)); | 344 EXPECT_TRUE(window_->GetDeviceInfoForPath(removable_device, &device_info)); |
| 351 | 345 |
| 352 std::string unique_id; | 346 std::string unique_id; |
| 353 string16 device_name; | 347 string16 device_name; |
| 354 bool removable; | 348 bool removable; |
| 355 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( | 349 ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo( |
| 356 removable_device, NULL, &unique_id, &device_name, &removable)); | 350 removable_device, NULL, &unique_id, &device_name, &removable)); |
| 357 EXPECT_TRUE(removable); | 351 EXPECT_TRUE(removable); |
| 358 std::string device_id = MediaStorageUtil::MakeDeviceId( | 352 std::string device_id = MediaStorageUtil::MakeDeviceId( |
| 359 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, unique_id); | 353 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, unique_id); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 pnp_device_id); | 421 pnp_device_id); |
| 428 EXPECT_EQ(it->object_persistent_id, | 422 EXPECT_EQ(it->object_persistent_id, |
| 429 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( | 423 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( |
| 430 pnp_device_id, storage_object_id)); | 424 pnp_device_id, storage_object_id)); |
| 431 } | 425 } |
| 432 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); | 426 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); |
| 433 } | 427 } |
| 434 | 428 |
| 435 } // namespace test | 429 } // namespace test |
| 436 } // namespace chrome | 430 } // namespace chrome |
| OLD | NEW |