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

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

Issue 10829384: SystemMonitor: Pull device type into the device id (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment Created 8 years, 4 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
« no previous file with comments | « base/system_monitor/system_monitor.cc ('k') | base/test/mock_devices_changed_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(base::SystemMonitor::DEVTYPE_UNKNOWN)) 119 OnDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN))
120 .Times(3) 120 .Times(3)
121 .InSequence(mock_sequencer[index]); 121 .InSequence(mock_sequencer[index]);
122 EXPECT_CALL(observers[index], 122 EXPECT_CALL(observers[index],
123 OnMediaDeviceAttached(kDeviceId1, 123 OnMediaDeviceAttached(kDeviceId1,
124 kDeviceName, 124 kDeviceName,
125 base::SystemMonitor::TYPE_PATH,
126 testing::_)) 125 testing::_))
127 .InSequence(mock_sequencer[index]); 126 .InSequence(mock_sequencer[index]);
128 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId1)) 127 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId1))
129 .InSequence(mock_sequencer[index]); 128 .InSequence(mock_sequencer[index]);
130 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId2)) 129 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId2))
131 .Times(0).InSequence(mock_sequencer[index]); 130 .Times(0).InSequence(mock_sequencer[index]);
132 } 131 }
133 132
134 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); 133 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
135 message_loop_.RunAllPending(); 134 message_loop_.RunAllPending();
136 135
137 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); 136 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
138 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); 137 system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN);
139 message_loop_.RunAllPending(); 138 message_loop_.RunAllPending();
140 139
141 system_monitor_->ProcessMediaDeviceAttached( 140 system_monitor_->ProcessMediaDeviceAttached(
142 kDeviceId1, 141 kDeviceId1,
143 kDeviceName, 142 kDeviceName,
144 base::SystemMonitor::TYPE_PATH,
145 FILE_PATH_LITERAL("path")); 143 FILE_PATH_LITERAL("path"));
146 message_loop_.RunAllPending(); 144 message_loop_.RunAllPending();
147 145
148 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); 146 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1);
149 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); 147 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
150 message_loop_.RunAllPending(); 148 message_loop_.RunAllPending();
151 } 149 }
152 150
153 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) { 151 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) {
154 std::vector<SystemMonitor::MediaDeviceInfo> devices = 152 std::vector<SystemMonitor::MediaDeviceInfo> devices =
155 system_monitor_->GetAttachedMediaDevices(); 153 system_monitor_->GetAttachedMediaDevices();
156 EXPECT_EQ(0U, devices.size()); 154 EXPECT_EQ(0U, devices.size());
157 } 155 }
158 156
159 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesAttachDetach) { 157 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesAttachDetach) {
160 const std::string kDeviceId1 = "42"; 158 const std::string kDeviceId1 = "42";
161 const string16 kDeviceName1 = ASCIIToUTF16("test"); 159 const string16 kDeviceName1 = ASCIIToUTF16("test");
162 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); 160 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
163 system_monitor_->ProcessMediaDeviceAttached(kDeviceId1, 161 system_monitor_->ProcessMediaDeviceAttached(kDeviceId1,
164 kDeviceName1, 162 kDeviceName1,
165 base::SystemMonitor::TYPE_PATH,
166 kDevicePath1.value()); 163 kDevicePath1.value());
167 message_loop_.RunAllPending(); 164 message_loop_.RunAllPending();
168 std::vector<SystemMonitor::MediaDeviceInfo> devices = 165 std::vector<SystemMonitor::MediaDeviceInfo> devices =
169 system_monitor_->GetAttachedMediaDevices(); 166 system_monitor_->GetAttachedMediaDevices();
170 ASSERT_EQ(1U, devices.size()); 167 ASSERT_EQ(1U, devices.size());
171 EXPECT_EQ(kDeviceId1, devices[0].unique_id); 168 EXPECT_EQ(kDeviceId1, devices[0].unique_id);
172 EXPECT_EQ(kDeviceName1, devices[0].name); 169 EXPECT_EQ(kDeviceName1, devices[0].name);
173 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].type);
174 EXPECT_EQ(kDevicePath1.value(), devices[0].location); 170 EXPECT_EQ(kDevicePath1.value(), devices[0].location);
175 171
176 const std::string kDeviceId2 = "44"; 172 const std::string kDeviceId2 = "44";
177 const string16 kDeviceName2 = ASCIIToUTF16("test2"); 173 const string16 kDeviceName2 = ASCIIToUTF16("test2");
178 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); 174 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar"));
179 system_monitor_->ProcessMediaDeviceAttached(kDeviceId2, 175 system_monitor_->ProcessMediaDeviceAttached(kDeviceId2,
180 kDeviceName2, 176 kDeviceName2,
181 base::SystemMonitor::TYPE_PATH,
182 kDevicePath2.value()); 177 kDevicePath2.value());
183 message_loop_.RunAllPending(); 178 message_loop_.RunAllPending();
184 devices = system_monitor_->GetAttachedMediaDevices(); 179 devices = system_monitor_->GetAttachedMediaDevices();
185 ASSERT_EQ(2U, devices.size()); 180 ASSERT_EQ(2U, devices.size());
186 EXPECT_EQ(kDeviceId1, devices[0].unique_id); 181 EXPECT_EQ(kDeviceId1, devices[0].unique_id);
187 EXPECT_EQ(kDeviceName1, devices[0].name); 182 EXPECT_EQ(kDeviceName1, devices[0].name);
188 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].type);
189 EXPECT_EQ(kDevicePath1.value(), devices[0].location); 183 EXPECT_EQ(kDevicePath1.value(), devices[0].location);
190 EXPECT_EQ(kDeviceId2, devices[1].unique_id); 184 EXPECT_EQ(kDeviceId2, devices[1].unique_id);
191 EXPECT_EQ(kDeviceName2, devices[1].name); 185 EXPECT_EQ(kDeviceName2, devices[1].name);
192 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[1].type);
193 EXPECT_EQ(kDevicePath2.value(), devices[1].location); 186 EXPECT_EQ(kDevicePath2.value(), devices[1].location);
194 187
195 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); 188 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1);
196 message_loop_.RunAllPending(); 189 message_loop_.RunAllPending();
197 devices = system_monitor_->GetAttachedMediaDevices(); 190 devices = system_monitor_->GetAttachedMediaDevices();
198 ASSERT_EQ(1U, devices.size()); 191 ASSERT_EQ(1U, devices.size());
199 EXPECT_EQ(kDeviceId2, devices[0].unique_id); 192 EXPECT_EQ(kDeviceId2, devices[0].unique_id);
200 EXPECT_EQ(kDeviceName2, devices[0].name); 193 EXPECT_EQ(kDeviceName2, devices[0].name);
201 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].type);
202 EXPECT_EQ(kDevicePath2.value(), devices[0].location); 194 EXPECT_EQ(kDevicePath2.value(), devices[0].location);
203 195
204 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); 196 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
205 message_loop_.RunAllPending(); 197 message_loop_.RunAllPending();
206 devices = system_monitor_->GetAttachedMediaDevices(); 198 devices = system_monitor_->GetAttachedMediaDevices();
207 EXPECT_EQ(0U, devices.size()); 199 EXPECT_EQ(0U, devices.size());
208 } 200 }
209 201
210 } // namespace 202 } // namespace
211 203
212 } // namespace base 204 } // namespace base
OLDNEW
« no previous file with comments | « base/system_monitor/system_monitor.cc ('k') | base/test/mock_devices_changed_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698