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/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 "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 class PowerTest : public SystemMonitor::PowerObserver { | 18 class PowerTest : public SystemMonitor::PowerObserver { |
18 public: | 19 public: |
19 PowerTest() | 20 PowerTest() |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 EXPECT_EQ(test[0].resumes(), 1); | 102 EXPECT_EQ(test[0].resumes(), 1); |
102 | 103 |
103 // Send a duplicate resume notification. This should be suppressed. | 104 // Send a duplicate resume notification. This should be suppressed. |
104 system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT); | 105 system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT); |
105 message_loop_.RunAllPending(); | 106 message_loop_.RunAllPending(); |
106 EXPECT_EQ(test[0].resumes(), 1); | 107 EXPECT_EQ(test[0].resumes(), 1); |
107 } | 108 } |
108 | 109 |
109 TEST_F(SystemMonitorTest, DeviceChangeNotifications) { | 110 TEST_F(SystemMonitorTest, DeviceChangeNotifications) { |
110 const int kObservers = 5; | 111 const int kObservers = 5; |
| 112 const string16 kDeviceName = ASCIIToUTF16("media device"); |
| 113 const std::string kDeviceId1 = "1"; |
| 114 const std::string kDeviceId2 = "2"; |
111 | 115 |
112 testing::Sequence mock_sequencer[kObservers]; | 116 testing::Sequence mock_sequencer[kObservers]; |
113 MockDevicesChangedObserver observers[kObservers]; | 117 MockDevicesChangedObserver observers[kObservers]; |
114 for (int index = 0; index < kObservers; ++index) { | 118 for (int index = 0; index < kObservers; ++index) { |
115 system_monitor_->AddDevicesChangedObserver(&observers[index]); | 119 system_monitor_->AddDevicesChangedObserver(&observers[index]); |
116 | 120 |
117 EXPECT_CALL(observers[index], OnDevicesChanged()) | 121 EXPECT_CALL(observers[index], OnDevicesChanged()) |
118 .Times(3) | 122 .Times(3) |
119 .InSequence(mock_sequencer[index]); | 123 .InSequence(mock_sequencer[index]); |
120 EXPECT_CALL(observers[index], OnMediaDeviceAttached(1, "media device", | 124 EXPECT_CALL(observers[index], |
121 testing::_)) | 125 OnMediaDeviceAttached(kDeviceId1, |
| 126 kDeviceName, |
| 127 base::SystemMonitor::TYPE_PATH, |
| 128 testing::_)) |
122 .InSequence(mock_sequencer[index]); | 129 .InSequence(mock_sequencer[index]); |
123 EXPECT_CALL(observers[index], OnMediaDeviceDetached(1)) | 130 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId1)) |
124 .InSequence(mock_sequencer[index]); | 131 .InSequence(mock_sequencer[index]); |
125 EXPECT_CALL(observers[index], OnMediaDeviceDetached(2)) | 132 EXPECT_CALL(observers[index], OnMediaDeviceDetached(kDeviceId2)) |
126 .InSequence(mock_sequencer[index]); | 133 .InSequence(mock_sequencer[index]); |
127 } | 134 } |
128 | 135 |
129 system_monitor_->ProcessDevicesChanged(); | 136 system_monitor_->ProcessDevicesChanged(); |
130 message_loop_.RunAllPending(); | 137 message_loop_.RunAllPending(); |
131 | 138 |
132 system_monitor_->ProcessDevicesChanged(); | 139 system_monitor_->ProcessDevicesChanged(); |
133 system_monitor_->ProcessDevicesChanged(); | 140 system_monitor_->ProcessDevicesChanged(); |
134 message_loop_.RunAllPending(); | 141 message_loop_.RunAllPending(); |
135 | 142 |
136 system_monitor_->ProcessMediaDeviceAttached( | 143 system_monitor_->ProcessMediaDeviceAttached( |
137 1, "media device", FilePath(FILE_PATH_LITERAL("path"))); | 144 kDeviceId1, |
| 145 kDeviceName, |
| 146 base::SystemMonitor::TYPE_PATH, |
| 147 FILE_PATH_LITERAL("path")); |
138 message_loop_.RunAllPending(); | 148 message_loop_.RunAllPending(); |
139 | 149 |
140 system_monitor_->ProcessMediaDeviceDetached(1); | 150 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); |
141 system_monitor_->ProcessMediaDeviceDetached(2); | 151 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); |
142 message_loop_.RunAllPending(); | 152 message_loop_.RunAllPending(); |
143 } | 153 } |
144 | 154 |
145 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) { | 155 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) { |
146 std::vector<SystemMonitor::MediaDeviceInfo> devices = | 156 std::vector<SystemMonitor::MediaDeviceInfo> devices = |
147 system_monitor_->GetAttachedMediaDevices(); | 157 system_monitor_->GetAttachedMediaDevices(); |
148 EXPECT_EQ(0U, devices.size()); | 158 EXPECT_EQ(0U, devices.size()); |
149 } | 159 } |
150 | 160 |
151 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesAttachDetach) { | 161 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesAttachDetach) { |
152 const SystemMonitor::DeviceIdType kDeviceId1 = 42; | 162 const std::string kDeviceId1 = "42"; |
153 const char kDeviceName1[] = "test"; | 163 const string16 kDeviceName1 = ASCIIToUTF16("test"); |
154 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); | 164 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); |
155 system_monitor_->ProcessMediaDeviceAttached(kDeviceId1, | 165 system_monitor_->ProcessMediaDeviceAttached(kDeviceId1, |
156 kDeviceName1, | 166 kDeviceName1, |
157 kDevicePath1); | 167 base::SystemMonitor::TYPE_PATH, |
| 168 kDevicePath1.value()); |
158 message_loop_.RunAllPending(); | 169 message_loop_.RunAllPending(); |
159 std::vector<SystemMonitor::MediaDeviceInfo> devices = | 170 std::vector<SystemMonitor::MediaDeviceInfo> devices = |
160 system_monitor_->GetAttachedMediaDevices(); | 171 system_monitor_->GetAttachedMediaDevices(); |
161 ASSERT_EQ(1U, devices.size()); | 172 ASSERT_EQ(1U, devices.size()); |
162 EXPECT_EQ(kDeviceId1, devices[0].a); | 173 EXPECT_EQ(kDeviceId1, devices[0].unique_id); |
163 EXPECT_EQ(kDeviceName1, devices[0].b); | 174 EXPECT_EQ(kDeviceName1, devices[0].name); |
164 EXPECT_EQ(kDevicePath1, devices[0].c); | 175 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].type); |
| 176 EXPECT_EQ(kDevicePath1.value(), devices[0].location); |
165 | 177 |
166 const SystemMonitor::DeviceIdType kDeviceId2 = 44; | 178 const std::string kDeviceId2 = "44"; |
167 const char kDeviceName2[] = "test2"; | 179 const string16 kDeviceName2 = ASCIIToUTF16("test2"); |
168 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); | 180 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); |
169 system_monitor_->ProcessMediaDeviceAttached(kDeviceId2, | 181 system_monitor_->ProcessMediaDeviceAttached(kDeviceId2, |
170 kDeviceName2, | 182 kDeviceName2, |
171 kDevicePath2); | 183 base::SystemMonitor::TYPE_PATH, |
| 184 kDevicePath2.value()); |
172 message_loop_.RunAllPending(); | 185 message_loop_.RunAllPending(); |
173 devices = system_monitor_->GetAttachedMediaDevices(); | 186 devices = system_monitor_->GetAttachedMediaDevices(); |
174 ASSERT_EQ(2U, devices.size()); | 187 ASSERT_EQ(2U, devices.size()); |
175 EXPECT_EQ(kDeviceId1, devices[0].a); | 188 EXPECT_EQ(kDeviceId1, devices[0].unique_id); |
176 EXPECT_EQ(kDeviceName1, devices[0].b); | 189 EXPECT_EQ(kDeviceName1, devices[0].name); |
177 EXPECT_EQ(kDevicePath1, devices[0].c); | 190 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].type); |
178 EXPECT_EQ(kDeviceId2, devices[1].a); | 191 EXPECT_EQ(kDevicePath1.value(), devices[0].location); |
179 EXPECT_EQ(kDeviceName2, devices[1].b); | 192 EXPECT_EQ(kDeviceId2, devices[1].unique_id); |
180 EXPECT_EQ(kDevicePath2, devices[1].c); | 193 EXPECT_EQ(kDeviceName2, devices[1].name); |
| 194 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[1].type); |
| 195 EXPECT_EQ(kDevicePath2.value(), devices[1].location); |
181 | 196 |
182 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); | 197 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); |
183 message_loop_.RunAllPending(); | 198 message_loop_.RunAllPending(); |
184 devices = system_monitor_->GetAttachedMediaDevices(); | 199 devices = system_monitor_->GetAttachedMediaDevices(); |
185 ASSERT_EQ(1U, devices.size()); | 200 ASSERT_EQ(1U, devices.size()); |
186 EXPECT_EQ(kDeviceId2, devices[0].a); | 201 EXPECT_EQ(kDeviceId2, devices[0].unique_id); |
187 EXPECT_EQ(kDeviceName2, devices[0].b); | 202 EXPECT_EQ(kDeviceName2, devices[0].name); |
188 EXPECT_EQ(kDevicePath2, devices[0].c); | 203 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].type); |
| 204 EXPECT_EQ(kDevicePath2.value(), devices[0].location); |
189 | 205 |
190 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); | 206 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); |
191 message_loop_.RunAllPending(); | 207 message_loop_.RunAllPending(); |
192 devices = system_monitor_->GetAttachedMediaDevices(); | 208 devices = system_monitor_->GetAttachedMediaDevices(); |
193 EXPECT_EQ(0U, devices.size()); | 209 EXPECT_EQ(0U, devices.size()); |
194 } | 210 } |
195 | 211 |
196 } // namespace | 212 } // namespace |
197 | 213 |
198 } // namespace base | 214 } // namespace base |
OLD | NEW |