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 char kDeviceName[] = "media device"; |
111 | 113 |
112 testing::Sequence mock_sequencer[kObservers]; | 114 testing::Sequence mock_sequencer[kObservers]; |
113 MockDevicesChangedObserver observers[kObservers]; | 115 MockDevicesChangedObserver observers[kObservers]; |
114 for (int index = 0; index < kObservers; ++index) { | 116 for (int index = 0; index < kObservers; ++index) { |
115 system_monitor_->AddDevicesChangedObserver(&observers[index]); | 117 system_monitor_->AddDevicesChangedObserver(&observers[index]); |
116 | 118 |
117 EXPECT_CALL(observers[index], OnDevicesChanged()) | 119 EXPECT_CALL(observers[index], OnDevicesChanged()) |
118 .Times(3) | 120 .Times(3) |
119 .InSequence(mock_sequencer[index]); | 121 .InSequence(mock_sequencer[index]); |
120 EXPECT_CALL(observers[index], OnMediaDeviceAttached(1, "media device", | 122 EXPECT_CALL(observers[index], |
121 testing::_)) | 123 OnMediaDeviceAttached(1, |
| 124 kDeviceName, |
| 125 base::SystemMonitor::TYPE_PATH, |
| 126 testing::_)) |
122 .InSequence(mock_sequencer[index]); | 127 .InSequence(mock_sequencer[index]); |
123 EXPECT_CALL(observers[index], OnMediaDeviceDetached(1)) | 128 EXPECT_CALL(observers[index], OnMediaDeviceDetached(1)) |
124 .InSequence(mock_sequencer[index]); | 129 .InSequence(mock_sequencer[index]); |
125 EXPECT_CALL(observers[index], OnMediaDeviceDetached(2)) | 130 EXPECT_CALL(observers[index], OnMediaDeviceDetached(2)) |
126 .InSequence(mock_sequencer[index]); | 131 .InSequence(mock_sequencer[index]); |
127 } | 132 } |
128 | 133 |
129 system_monitor_->ProcessDevicesChanged(); | 134 system_monitor_->ProcessDevicesChanged(); |
130 message_loop_.RunAllPending(); | 135 message_loop_.RunAllPending(); |
131 | 136 |
132 system_monitor_->ProcessDevicesChanged(); | 137 system_monitor_->ProcessDevicesChanged(); |
133 system_monitor_->ProcessDevicesChanged(); | 138 system_monitor_->ProcessDevicesChanged(); |
134 message_loop_.RunAllPending(); | 139 message_loop_.RunAllPending(); |
135 | 140 |
136 system_monitor_->ProcessMediaDeviceAttached( | 141 system_monitor_->ProcessMediaDeviceAttached( |
137 1, "media device", FilePath(FILE_PATH_LITERAL("path"))); | 142 1, |
| 143 kDeviceName, |
| 144 base::SystemMonitor::TYPE_PATH, |
| 145 FILE_PATH_LITERAL("path")); |
138 message_loop_.RunAllPending(); | 146 message_loop_.RunAllPending(); |
139 | 147 |
140 system_monitor_->ProcessMediaDeviceDetached(1); | 148 system_monitor_->ProcessMediaDeviceDetached(1); |
141 system_monitor_->ProcessMediaDeviceDetached(2); | 149 system_monitor_->ProcessMediaDeviceDetached(2); |
142 message_loop_.RunAllPending(); | 150 message_loop_.RunAllPending(); |
143 } | 151 } |
144 | 152 |
145 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) { | 153 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesEmpty) { |
146 std::vector<SystemMonitor::MediaDeviceInfo> devices = | 154 std::vector<SystemMonitor::MediaDeviceInfo> devices = |
147 system_monitor_->GetAttachedMediaDevices(); | 155 system_monitor_->GetAttachedMediaDevices(); |
148 EXPECT_EQ(0U, devices.size()); | 156 EXPECT_EQ(0U, devices.size()); |
149 } | 157 } |
150 | 158 |
151 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesAttachDetach) { | 159 TEST_F(SystemMonitorTest, GetAttachedMediaDevicesAttachDetach) { |
152 const SystemMonitor::DeviceIdType kDeviceId1 = 42; | 160 const SystemMonitor::DeviceIdType kDeviceId1 = 42; |
153 const char kDeviceName1[] = "test"; | 161 const char kDeviceName1[] = "test"; |
154 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); | 162 const string16 kDevicePath1(ASCIIToUTF16("/testfoo")); |
155 system_monitor_->ProcessMediaDeviceAttached(kDeviceId1, | 163 system_monitor_->ProcessMediaDeviceAttached(kDeviceId1, |
156 kDeviceName1, | 164 kDeviceName1, |
157 kDevicePath1); | 165 base::SystemMonitor::TYPE_PATH, |
| 166 kDevicePath1); |
158 message_loop_.RunAllPending(); | 167 message_loop_.RunAllPending(); |
159 std::vector<SystemMonitor::MediaDeviceInfo> devices = | 168 std::vector<SystemMonitor::MediaDeviceInfo> devices = |
160 system_monitor_->GetAttachedMediaDevices(); | 169 system_monitor_->GetAttachedMediaDevices(); |
161 ASSERT_EQ(1U, devices.size()); | 170 ASSERT_EQ(1U, devices.size()); |
162 EXPECT_EQ(kDeviceId1, devices[0].a); | 171 EXPECT_EQ(kDeviceId1, devices[0].a); |
163 EXPECT_EQ(kDeviceName1, devices[0].b); | 172 EXPECT_EQ(kDeviceName1, devices[0].b); |
164 EXPECT_EQ(kDevicePath1, devices[0].c); | 173 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].c); |
| 174 EXPECT_EQ(kDevicePath1, devices[0].d); |
165 | 175 |
166 const SystemMonitor::DeviceIdType kDeviceId2 = 44; | 176 const SystemMonitor::DeviceIdType kDeviceId2 = 44; |
167 const char kDeviceName2[] = "test2"; | 177 const char kDeviceName2[] = "test2"; |
168 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); | 178 const string16 kDevicePath2(ASCIIToUTF16("/testbar")); |
169 system_monitor_->ProcessMediaDeviceAttached(kDeviceId2, | 179 system_monitor_->ProcessMediaDeviceAttached(kDeviceId2, |
170 kDeviceName2, | 180 kDeviceName2, |
171 kDevicePath2); | 181 base::SystemMonitor::TYPE_PATH, |
| 182 kDevicePath2); |
172 message_loop_.RunAllPending(); | 183 message_loop_.RunAllPending(); |
173 devices = system_monitor_->GetAttachedMediaDevices(); | 184 devices = system_monitor_->GetAttachedMediaDevices(); |
174 ASSERT_EQ(2U, devices.size()); | 185 ASSERT_EQ(2U, devices.size()); |
175 EXPECT_EQ(kDeviceId1, devices[0].a); | 186 EXPECT_EQ(kDeviceId1, devices[0].a); |
176 EXPECT_EQ(kDeviceName1, devices[0].b); | 187 EXPECT_EQ(kDeviceName1, devices[0].b); |
177 EXPECT_EQ(kDevicePath1, devices[0].c); | 188 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].c); |
| 189 EXPECT_EQ(kDevicePath1, devices[0].d); |
178 EXPECT_EQ(kDeviceId2, devices[1].a); | 190 EXPECT_EQ(kDeviceId2, devices[1].a); |
179 EXPECT_EQ(kDeviceName2, devices[1].b); | 191 EXPECT_EQ(kDeviceName2, devices[1].b); |
180 EXPECT_EQ(kDevicePath2, devices[1].c); | 192 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[1].c); |
| 193 EXPECT_EQ(kDevicePath2, devices[1].d); |
181 | 194 |
182 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); | 195 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); |
183 message_loop_.RunAllPending(); | 196 message_loop_.RunAllPending(); |
184 devices = system_monitor_->GetAttachedMediaDevices(); | 197 devices = system_monitor_->GetAttachedMediaDevices(); |
185 ASSERT_EQ(1U, devices.size()); | 198 ASSERT_EQ(1U, devices.size()); |
186 EXPECT_EQ(kDeviceId2, devices[0].a); | 199 EXPECT_EQ(kDeviceId2, devices[0].a); |
187 EXPECT_EQ(kDeviceName2, devices[0].b); | 200 EXPECT_EQ(kDeviceName2, devices[0].b); |
188 EXPECT_EQ(kDevicePath2, devices[0].c); | 201 EXPECT_EQ(base::SystemMonitor::TYPE_PATH, devices[0].c); |
| 202 EXPECT_EQ(kDevicePath2, devices[0].d); |
189 | 203 |
190 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); | 204 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); |
191 message_loop_.RunAllPending(); | 205 message_loop_.RunAllPending(); |
192 devices = system_monitor_->GetAttachedMediaDevices(); | 206 devices = system_monitor_->GetAttachedMediaDevices(); |
193 EXPECT_EQ(0U, devices.size()); | 207 EXPECT_EQ(0U, devices.size()); |
194 } | 208 } |
195 | 209 |
196 } // namespace | 210 } // namespace |
197 | 211 |
198 } // namespace base | 212 } // namespace base |
OLD | NEW |