Index: base/system_monitor/system_monitor_unittest.cc |
=================================================================== |
--- base/system_monitor/system_monitor_unittest.cc (revision 137731) |
+++ base/system_monitor/system_monitor_unittest.cc (working copy) |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
#include "base/file_path.h" |
+#include "base/message_loop.h" |
#include "base/test/mock_devices_changed_observer.h" |
#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.
|
#include "testing/gmock/include/gmock/gmock.h" |
@@ -137,4 +138,76 @@ |
loop.RunAllPending(); |
} |
+TEST(SystemMonitor, GetAttachedMediaDevicesEmpty) { |
+ // Initialize a message loop for this to run on. |
+ MessageLoop loop; |
+ |
+#if defined(OS_MACOSX) |
+ SystemMonitor::AllocateSystemIOPorts(); |
+#endif |
+ |
+ SystemMonitor system_monitor; |
+ |
+ std::vector<SystemMonitor::MediaDeviceInfo> devices; |
+ system_monitor.GetAttachedMediaDevices(&devices); |
+ EXPECT_EQ(0U, devices.size()); |
+} |
+ |
+TEST(SystemMonitor, GetAttachedMediaDevicesAttachDetach) { |
+ // Initialize a message loop for this to run on. |
+ MessageLoop loop; |
+ |
+#if defined(OS_MACOSX) |
+ SystemMonitor::AllocateSystemIOPorts(); |
+#endif |
+ |
+ SystemMonitor system_monitor; |
+ |
+ const SystemMonitor::DeviceIdType kDeviceId1 = 42; |
+ const char kDeviceName1[] = "test"; |
+ const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); |
+ system_monitor.ProcessMediaDeviceAttached(kDeviceId1, |
+ kDeviceName1, |
+ kDevicePath1); |
+ loop.RunAllPending(); |
+ std::vector<SystemMonitor::MediaDeviceInfo> devices; |
+ system_monitor.GetAttachedMediaDevices(&devices); |
+ ASSERT_EQ(1U, devices.size()); |
+ EXPECT_EQ(kDeviceId1, devices[0].a); |
+ EXPECT_EQ(kDeviceName1, devices[0].b); |
+ EXPECT_EQ(kDevicePath1, devices[0].c); |
+ |
+ const SystemMonitor::DeviceIdType kDeviceId2 = 44; |
+ const char kDeviceName2[] = "test2"; |
+ const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); |
+ system_monitor.ProcessMediaDeviceAttached(kDeviceId2, |
+ kDeviceName2, |
+ kDevicePath2); |
+ loop.RunAllPending(); |
+ devices.clear(); |
+ system_monitor.GetAttachedMediaDevices(&devices); |
+ ASSERT_EQ(2U, devices.size()); |
+ EXPECT_EQ(kDeviceId1, devices[0].a); |
+ EXPECT_EQ(kDeviceName1, devices[0].b); |
+ EXPECT_EQ(kDevicePath1, devices[0].c); |
+ EXPECT_EQ(kDeviceId2, devices[1].a); |
+ EXPECT_EQ(kDeviceName2, devices[1].b); |
+ EXPECT_EQ(kDevicePath2, devices[1].c); |
+ |
+ system_monitor.ProcessMediaDeviceDetached(kDeviceId1); |
+ loop.RunAllPending(); |
+ devices.clear(); |
+ system_monitor.GetAttachedMediaDevices(&devices); |
+ ASSERT_EQ(1U, devices.size()); |
+ EXPECT_EQ(kDeviceId2, devices[0].a); |
+ EXPECT_EQ(kDeviceName2, devices[0].b); |
+ EXPECT_EQ(kDevicePath2, devices[0].c); |
+ |
+ system_monitor.ProcessMediaDeviceDetached(kDeviceId2); |
+ loop.RunAllPending(); |
+ devices.clear(); |
+ system_monitor.GetAttachedMediaDevices(&devices); |
+ EXPECT_EQ(0U, devices.size()); |
+} |
+ |
} // namespace base |