| 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 "base/system_monitor/system_monitor.h" | 5 #include "base/system_monitor/system_monitor.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/test/mock_devices_changed_observer.h" | 9 #include "base/test/mock_devices_changed_observer.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 testing::Sequence mock_sequencer[kObservers]; | 113 testing::Sequence mock_sequencer[kObservers]; |
| 114 MockDevicesChangedObserver observers[kObservers]; | 114 MockDevicesChangedObserver observers[kObservers]; |
| 115 for (int index = 0; index < kObservers; ++index) { | 115 for (int index = 0; index < kObservers; ++index) { |
| 116 system_monitor_->AddDevicesChangedObserver(&observers[index]); | 116 system_monitor_->AddDevicesChangedObserver(&observers[index]); |
| 117 | 117 |
| 118 EXPECT_CALL(observers[index], | 118 EXPECT_CALL(observers[index], |
| 119 OnDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN)) | 119 OnDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN)) |
| 120 .Times(3) | 120 .Times(3) |
| 121 .InSequence(mock_sequencer[index]); | 121 .InSequence(mock_sequencer[index]); |
| 122 EXPECT_CALL(observers[index], OnRemovableStorageAttached(kDeviceId1, | |
| 123 kDeviceName, | |
| 124 testing::_)) | |
| 125 .InSequence(mock_sequencer[index]); | |
| 126 EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId1)) | |
| 127 .InSequence(mock_sequencer[index]); | |
| 128 EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId2)) | |
| 129 .Times(0).InSequence(mock_sequencer[index]); | |
| 130 } | 122 } |
| 131 | 123 |
| 132 system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); | 124 system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); |
| 133 message_loop_.RunUntilIdle(); | 125 message_loop_.RunUntilIdle(); |
| 134 | 126 |
| 135 system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); | 127 system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); |
| 136 system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); | 128 system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN); |
| 137 message_loop_.RunUntilIdle(); | 129 message_loop_.RunUntilIdle(); |
| 138 | |
| 139 system_monitor_->ProcessRemovableStorageAttached(kDeviceId1, | |
| 140 kDeviceName, | |
| 141 FILE_PATH_LITERAL("path")); | |
| 142 message_loop_.RunUntilIdle(); | |
| 143 | |
| 144 system_monitor_->ProcessRemovableStorageDetached(kDeviceId1); | |
| 145 system_monitor_->ProcessRemovableStorageDetached(kDeviceId2); | |
| 146 message_loop_.RunUntilIdle(); | |
| 147 } | |
| 148 | |
| 149 TEST_F(SystemMonitorTest, GetAttachedRemovableStorageEmpty) { | |
| 150 std::vector<SystemMonitor::RemovableStorageInfo> devices = | |
| 151 system_monitor_->GetAttachedRemovableStorage(); | |
| 152 EXPECT_EQ(0U, devices.size()); | |
| 153 } | |
| 154 | |
| 155 TEST_F(SystemMonitorTest, GetAttachedRemovableStorageAttachDetach) { | |
| 156 const std::string kDeviceId1 = "42"; | |
| 157 const string16 kDeviceName1 = ASCIIToUTF16("test"); | |
| 158 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); | |
| 159 system_monitor_->ProcessRemovableStorageAttached(kDeviceId1, | |
| 160 kDeviceName1, | |
| 161 kDevicePath1.value()); | |
| 162 message_loop_.RunUntilIdle(); | |
| 163 std::vector<SystemMonitor::RemovableStorageInfo> devices = | |
| 164 system_monitor_->GetAttachedRemovableStorage(); | |
| 165 ASSERT_EQ(1U, devices.size()); | |
| 166 EXPECT_EQ(kDeviceId1, devices[0].device_id); | |
| 167 EXPECT_EQ(kDeviceName1, devices[0].name); | |
| 168 EXPECT_EQ(kDevicePath1.value(), devices[0].location); | |
| 169 | |
| 170 const std::string kDeviceId2 = "44"; | |
| 171 const string16 kDeviceName2 = ASCIIToUTF16("test2"); | |
| 172 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); | |
| 173 system_monitor_->ProcessRemovableStorageAttached(kDeviceId2, | |
| 174 kDeviceName2, | |
| 175 kDevicePath2.value()); | |
| 176 message_loop_.RunUntilIdle(); | |
| 177 devices = system_monitor_->GetAttachedRemovableStorage(); | |
| 178 ASSERT_EQ(2U, devices.size()); | |
| 179 EXPECT_EQ(kDeviceId1, devices[0].device_id); | |
| 180 EXPECT_EQ(kDeviceName1, devices[0].name); | |
| 181 EXPECT_EQ(kDevicePath1.value(), devices[0].location); | |
| 182 EXPECT_EQ(kDeviceId2, devices[1].device_id); | |
| 183 EXPECT_EQ(kDeviceName2, devices[1].name); | |
| 184 EXPECT_EQ(kDevicePath2.value(), devices[1].location); | |
| 185 | |
| 186 system_monitor_->ProcessRemovableStorageDetached(kDeviceId1); | |
| 187 message_loop_.RunUntilIdle(); | |
| 188 devices = system_monitor_->GetAttachedRemovableStorage(); | |
| 189 ASSERT_EQ(1U, devices.size()); | |
| 190 EXPECT_EQ(kDeviceId2, devices[0].device_id); | |
| 191 EXPECT_EQ(kDeviceName2, devices[0].name); | |
| 192 EXPECT_EQ(kDevicePath2.value(), devices[0].location); | |
| 193 | |
| 194 system_monitor_->ProcessRemovableStorageDetached(kDeviceId2); | |
| 195 message_loop_.RunUntilIdle(); | |
| 196 devices = system_monitor_->GetAttachedRemovableStorage(); | |
| 197 EXPECT_EQ(0U, devices.size()); | |
| 198 } | 130 } |
| 199 | 131 |
| 200 } // namespace | 132 } // namespace |
| 201 | 133 |
| 202 } // namespace base | 134 } // namespace base |
| OLD | NEW |