| 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"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| @@ -137,4 +138,72 @@
|
| loop.RunAllPending();
|
| }
|
|
|
| +TEST(SystemMonitor, GetMediaDevicesEmpty) {
|
| + // 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.GetMediaDevices(&devices);
|
| + EXPECT_EQ(0U, devices.size());
|
| +}
|
| +
|
| +TEST(SystemMonitor, GetMediaDevicesAttachDetach) {
|
| + // 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.GetMediaDevices(&devices);
|
| + ASSERT_EQ(1U, devices.size());
|
| + EXPECT_EQ(kDeviceName1, devices[0].first);
|
| + EXPECT_EQ(kDevicePath1, devices[0].second);
|
| +
|
| + 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.GetMediaDevices(&devices);
|
| + ASSERT_EQ(2U, devices.size());
|
| + EXPECT_EQ(kDeviceName1, devices[0].first);
|
| + EXPECT_EQ(kDevicePath1, devices[0].second);
|
| + EXPECT_EQ(kDeviceName2, devices[1].first);
|
| + EXPECT_EQ(kDevicePath2, devices[1].second);
|
| +
|
| + system_monitor.ProcessMediaDeviceDetached(kDeviceId1);
|
| + loop.RunAllPending();
|
| + devices.clear();
|
| + system_monitor.GetMediaDevices(&devices);
|
| + ASSERT_EQ(1U, devices.size());
|
| + EXPECT_EQ(kDeviceName2, devices[1].first);
|
| + EXPECT_EQ(kDevicePath2, devices[1].second);
|
| +
|
| + system_monitor.ProcessMediaDeviceDetached(kDeviceId2);
|
| + loop.RunAllPending();
|
| + devices.clear();
|
| + system_monitor.GetMediaDevices(&devices);
|
| + EXPECT_EQ(0U, devices.size());
|
| +}
|
| +
|
| } // namespace base
|
|
|