Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: base/system_monitor/system_monitor_unittest.cc

Issue 10332190: Add SystemMonitor::GetMediaDevices() (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: do this in base instead Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
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()
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, GetMediaDevicesEmpty) {
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.GetMediaDevices(&devices);
153 EXPECT_EQ(0U, devices.size());
154 }
155
156 TEST(SystemMonitor, GetMediaDevicesAttachDetach) {
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.GetMediaDevices(&devices);
175 ASSERT_EQ(1U, devices.size());
176 EXPECT_EQ(kDeviceName1, devices[0].first);
177 EXPECT_EQ(kDevicePath1, devices[0].second);
178
179 const SystemMonitor::DeviceIdType kDeviceId2 = 44;
180 const char kDeviceName2[] = "test2";
181 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar"));
182 system_monitor.ProcessMediaDeviceAttached(kDeviceId2,
183 kDeviceName2,
184 kDevicePath2);
185 loop.RunAllPending();
186 devices.clear();
187 system_monitor.GetMediaDevices(&devices);
188 ASSERT_EQ(2U, devices.size());
189 EXPECT_EQ(kDeviceName1, devices[0].first);
190 EXPECT_EQ(kDevicePath1, devices[0].second);
191 EXPECT_EQ(kDeviceName2, devices[1].first);
192 EXPECT_EQ(kDevicePath2, devices[1].second);
193
194 system_monitor.ProcessMediaDeviceDetached(kDeviceId1);
195 loop.RunAllPending();
196 devices.clear();
197 system_monitor.GetMediaDevices(&devices);
198 ASSERT_EQ(1U, devices.size());
199 EXPECT_EQ(kDeviceName2, devices[1].first);
200 EXPECT_EQ(kDevicePath2, devices[1].second);
201
202 system_monitor.ProcessMediaDeviceDetached(kDeviceId2);
203 loop.RunAllPending();
204 devices.clear();
205 system_monitor.GetMediaDevices(&devices);
206 EXPECT_EQ(0U, devices.size());
207 }
208
140 } // namespace base 209 } // namespace base
OLDNEW
« base/system_monitor/system_monitor.h ('K') | « base/system_monitor/system_monitor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698