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 "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/message_loop.h" | |
| 6 #include "base/test/mock_devices_changed_observer.h" | 7 #include "base/test/mock_devices_changed_observer.h" |
| 7 #include "base/system_monitor/system_monitor.h" | 8 #include "base/system_monitor/system_monitor.h" |
|
willchan no longer on Chromium
2012/05/21 05:32:36
While you're here, please move this first as per G
Lei Zhang
2012/05/21 19:42:06
Done.
| |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 namespace base { | 12 namespace base { |
| 12 | 13 |
| 13 class PowerTest : public SystemMonitor::PowerObserver { | 14 class PowerTest : public SystemMonitor::PowerObserver { |
| 14 public: | 15 public: |
| 15 PowerTest() | 16 PowerTest() |
| 16 : battery_(false), | 17 : battery_(false), |
| 17 power_state_changes_(0), | 18 power_state_changes_(0), |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 131 |
| 131 system_monitor.ProcessMediaDeviceAttached( | 132 system_monitor.ProcessMediaDeviceAttached( |
| 132 1, "media device", FilePath(FILE_PATH_LITERAL("path"))); | 133 1, "media device", FilePath(FILE_PATH_LITERAL("path"))); |
| 133 loop.RunAllPending(); | 134 loop.RunAllPending(); |
| 134 | 135 |
| 135 system_monitor.ProcessMediaDeviceDetached(1); | 136 system_monitor.ProcessMediaDeviceDetached(1); |
| 136 system_monitor.ProcessMediaDeviceDetached(2); | 137 system_monitor.ProcessMediaDeviceDetached(2); |
| 137 loop.RunAllPending(); | 138 loop.RunAllPending(); |
| 138 } | 139 } |
| 139 | 140 |
| 141 TEST(SystemMonitor, GetAttachedMediaDevicesEmpty) { | |
| 142 // Initialize a message loop for this to run on. | |
| 143 MessageLoop loop; | |
| 144 | |
| 145 #if defined(OS_MACOSX) | |
| 146 SystemMonitor::AllocateSystemIOPorts(); | |
| 147 #endif | |
| 148 | |
| 149 SystemMonitor system_monitor; | |
| 150 | |
| 151 std::vector<SystemMonitor::MediaDeviceInfo> devices; | |
| 152 system_monitor.GetAttachedMediaDevices(&devices); | |
| 153 EXPECT_EQ(0U, devices.size()); | |
| 154 } | |
| 155 | |
| 156 TEST(SystemMonitor, GetAttachedMediaDevicesAttachDetach) { | |
| 157 // Initialize a message loop for this to run on. | |
| 158 MessageLoop loop; | |
| 159 | |
| 160 #if defined(OS_MACOSX) | |
| 161 SystemMonitor::AllocateSystemIOPorts(); | |
| 162 #endif | |
| 163 | |
| 164 SystemMonitor system_monitor; | |
| 165 | |
| 166 const SystemMonitor::DeviceIdType kDeviceId1 = 42; | |
| 167 const char kDeviceName1[] = "test"; | |
| 168 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); | |
| 169 system_monitor.ProcessMediaDeviceAttached(kDeviceId1, | |
| 170 kDeviceName1, | |
| 171 kDevicePath1); | |
| 172 loop.RunAllPending(); | |
| 173 std::vector<SystemMonitor::MediaDeviceInfo> devices; | |
| 174 system_monitor.GetAttachedMediaDevices(&devices); | |
| 175 ASSERT_EQ(1U, devices.size()); | |
| 176 EXPECT_EQ(kDeviceId1, devices[0].a); | |
| 177 EXPECT_EQ(kDeviceName1, devices[0].b); | |
| 178 EXPECT_EQ(kDevicePath1, devices[0].c); | |
| 179 | |
| 180 const SystemMonitor::DeviceIdType kDeviceId2 = 44; | |
| 181 const char kDeviceName2[] = "test2"; | |
| 182 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); | |
| 183 system_monitor.ProcessMediaDeviceAttached(kDeviceId2, | |
| 184 kDeviceName2, | |
| 185 kDevicePath2); | |
| 186 loop.RunAllPending(); | |
| 187 devices.clear(); | |
| 188 system_monitor.GetAttachedMediaDevices(&devices); | |
| 189 ASSERT_EQ(2U, devices.size()); | |
| 190 EXPECT_EQ(kDeviceId1, devices[0].a); | |
| 191 EXPECT_EQ(kDeviceName1, devices[0].b); | |
| 192 EXPECT_EQ(kDevicePath1, devices[0].c); | |
| 193 EXPECT_EQ(kDeviceId2, devices[1].a); | |
| 194 EXPECT_EQ(kDeviceName2, devices[1].b); | |
| 195 EXPECT_EQ(kDevicePath2, devices[1].c); | |
| 196 | |
| 197 system_monitor.ProcessMediaDeviceDetached(kDeviceId1); | |
| 198 loop.RunAllPending(); | |
| 199 devices.clear(); | |
| 200 system_monitor.GetAttachedMediaDevices(&devices); | |
| 201 ASSERT_EQ(1U, devices.size()); | |
| 202 EXPECT_EQ(kDeviceId2, devices[0].a); | |
| 203 EXPECT_EQ(kDeviceName2, devices[0].b); | |
| 204 EXPECT_EQ(kDevicePath2, devices[0].c); | |
| 205 | |
| 206 system_monitor.ProcessMediaDeviceDetached(kDeviceId2); | |
| 207 loop.RunAllPending(); | |
| 208 devices.clear(); | |
| 209 system_monitor.GetAttachedMediaDevices(&devices); | |
| 210 EXPECT_EQ(0U, devices.size()); | |
| 211 } | |
| 212 | |
| 140 } // namespace base | 213 } // namespace base |
| OLD | NEW |