OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 properties_.uuid = BluetoothMediaClient::kBluetoothAudioSinkUUID; | 74 properties_.uuid = BluetoothMediaClient::kBluetoothAudioSinkUUID; |
75 properties_.codec = FakeBluetoothMediaTransportClient::kTransportCodec; | 75 properties_.codec = FakeBluetoothMediaTransportClient::kTransportCodec; |
76 properties_.configuration = | 76 properties_.configuration = |
77 FakeBluetoothMediaTransportClient::kTransportConfiguration; | 77 FakeBluetoothMediaTransportClient::kTransportConfiguration; |
78 properties_.state = BluetoothMediaTransportClient::kStateIdle; | 78 properties_.state = BluetoothMediaTransportClient::kStateIdle; |
79 properties_.delay.reset( | 79 properties_.delay.reset( |
80 new uint16_t(FakeBluetoothMediaTransportClient::kTransportDelay)); | 80 new uint16_t(FakeBluetoothMediaTransportClient::kTransportDelay)); |
81 properties_.volume.reset( | 81 properties_.volume.reset( |
82 new uint16_t(FakeBluetoothMediaTransportClient::kTransportVolume)); | 82 new uint16_t(FakeBluetoothMediaTransportClient::kTransportVolume)); |
83 | 83 |
| 84 media_ = static_cast<FakeBluetoothMediaClient*>( |
| 85 DBusThreadManager::Get()->GetBluetoothMediaClient()); |
| 86 transport_ = static_cast<FakeBluetoothMediaTransportClient*>( |
| 87 DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); |
| 88 |
84 GetAdapter(); | 89 GetAdapter(); |
85 } | 90 } |
86 | 91 |
87 void TearDown() override { | 92 void TearDown() override { |
88 callback_count_ = 0; | 93 callback_count_ = 0; |
89 error_callback_count_ = 0; | 94 error_callback_count_ = 0; |
| 95 observer_.reset(); |
| 96 |
| 97 media_->SetVisible(true); |
90 | 98 |
91 // The adapter should outlive audio sink. | 99 // The adapter should outlive audio sink. |
92 audio_sink_ = nullptr; | 100 audio_sink_ = nullptr; |
93 adapter_ = nullptr; | 101 adapter_ = nullptr; |
94 DBusThreadManager::Shutdown(); | 102 DBusThreadManager::Shutdown(); |
95 } | 103 } |
96 | 104 |
97 // Gets the existing Bluetooth adapter. | 105 // Gets the existing Bluetooth adapter. |
98 void GetAdapter() { | 106 void GetAdapter() { |
99 BluetoothAdapterFactory::GetAdapter( | 107 BluetoothAdapterFactory::GetAdapter( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35})); | 139 std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35})); |
132 | 140 |
133 // Registers |audio_sink_| with valid codec and capabilities | 141 // Registers |audio_sink_| with valid codec and capabilities |
134 adapter_->RegisterAudioSink( | 142 adapter_->RegisterAudioSink( |
135 options, | 143 options, |
136 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterCallback, | 144 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterCallback, |
137 base::Unretained(this)), | 145 base::Unretained(this)), |
138 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterErrorCallback, | 146 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterErrorCallback, |
139 base::Unretained(this))); | 147 base::Unretained(this))); |
140 | 148 |
| 149 observer_.reset(new TestAudioSinkObserver(audio_sink_)); |
141 EXPECT_EQ(callback_count_, 1); | 150 EXPECT_EQ(callback_count_, 1); |
142 EXPECT_EQ(error_callback_count_, 0); | 151 EXPECT_EQ(error_callback_count_, 0); |
| 152 EXPECT_EQ(observer_->state_changed_count_, 0); |
| 153 EXPECT_EQ(observer_->volume_changed_count_, 0); |
| 154 } |
| 155 |
| 156 void GetFakeMediaEndpoint() { |
| 157 BluetoothAudioSinkChromeOS* audio_sink_chromeos = |
| 158 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get()); |
| 159 ASSERT_NE(audio_sink_chromeos, nullptr); |
| 160 |
| 161 media_endpoint_ = static_cast<FakeBluetoothMediaEndpointServiceProvider*>( |
| 162 audio_sink_chromeos->GetEndpointServiceProvider()); |
143 } | 163 } |
144 | 164 |
145 // Called whenever RegisterAudioSink is completed successfully. | 165 // Called whenever RegisterAudioSink is completed successfully. |
146 void RegisterCallback( | 166 void RegisterCallback( |
147 scoped_refptr<BluetoothAudioSink> audio_sink) { | 167 scoped_refptr<BluetoothAudioSink> audio_sink) { |
148 ++callback_count_; | 168 ++callback_count_; |
149 audio_sink_ = audio_sink; | 169 audio_sink_ = audio_sink; |
| 170 |
| 171 GetFakeMediaEndpoint(); |
| 172 ASSERT_NE(media_endpoint_, nullptr); |
| 173 media_->SetEndpointRegistered(media_endpoint_, true); |
| 174 |
150 ASSERT_NE(audio_sink_.get(), nullptr); | 175 ASSERT_NE(audio_sink_.get(), nullptr); |
151 ASSERT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 176 ASSERT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
152 } | 177 } |
153 | 178 |
154 // Called whenever RegisterAudioSink failed. | 179 // Called whenever RegisterAudioSink failed. |
155 void RegisterErrorCallback(BluetoothAudioSink::ErrorCode error_code) { | 180 void RegisterErrorCallback(BluetoothAudioSink::ErrorCode error_code) { |
156 ++error_callback_count_; | 181 ++error_callback_count_; |
157 EXPECT_EQ(error_code, BluetoothAudioSink::ERROR_NOT_REGISTERED); | 182 EXPECT_EQ(error_code, BluetoothAudioSink::ERROR_NOT_REGISTERED); |
158 } | 183 } |
159 | 184 |
160 // Called whenever there capabilities are returned from SelectConfiguration. | 185 // Called whenever there capabilities are returned from SelectConfiguration. |
161 void SelectConfigurationCallback(const std::vector<uint8_t>& capabilities) { | 186 void SelectConfigurationCallback(const std::vector<uint8_t>& capabilities) { |
162 ++callback_count_; | 187 ++callback_count_; |
163 | 188 |
164 // |capabilities| should be the same as the capabilities for registering an | 189 // |capabilities| should be the same as the capabilities for registering an |
165 // audio sink in GetAudioSink(). | 190 // audio sink in GetAudioSink(). |
166 EXPECT_EQ(capabilities, std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35})); | 191 EXPECT_EQ(capabilities, std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35})); |
167 } | 192 } |
168 | 193 |
| 194 void UnregisterErrorCallback(BluetoothAudioSink::ErrorCode error_code) { |
| 195 ++error_callback_count_; |
| 196 EXPECT_EQ(error_code, BluetoothAudioSink::ERROR_NOT_UNREGISTERED); |
| 197 } |
| 198 |
169 // Generic callbacks. | 199 // Generic callbacks. |
170 void Callback() { | 200 void Callback() { |
171 ++callback_count_; | 201 ++callback_count_; |
172 } | 202 } |
173 | 203 |
174 void ErrorCallback() { | 204 void ErrorCallback() { |
175 ++error_callback_count_; | 205 ++error_callback_count_; |
176 } | 206 } |
177 | 207 |
178 protected: | 208 protected: |
179 int callback_count_; | 209 int callback_count_; |
180 int error_callback_count_; | 210 int error_callback_count_; |
181 | 211 |
182 base::MessageLoop message_loop_; | 212 base::MessageLoop message_loop_; |
183 | 213 |
| 214 FakeBluetoothMediaClient* media_; |
| 215 FakeBluetoothMediaTransportClient* transport_; |
| 216 FakeBluetoothMediaEndpointServiceProvider* media_endpoint_; |
| 217 scoped_ptr<TestAudioSinkObserver> observer_; |
184 scoped_refptr<BluetoothAdapter> adapter_; | 218 scoped_refptr<BluetoothAdapter> adapter_; |
185 scoped_refptr<BluetoothAudioSink> audio_sink_; | 219 scoped_refptr<BluetoothAudioSink> audio_sink_; |
186 | 220 |
187 // The default property set used while calling SetConfiguration on a media | 221 // The default property set used while calling SetConfiguration on a media |
188 // endpoint object. | 222 // endpoint object. |
189 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties | 223 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties |
190 properties_; | 224 properties_; |
191 }; | 225 }; |
192 | 226 |
193 TEST_F(BluetoothAudioSinkChromeOSTest, RegisterSucceeded) { | 227 TEST_F(BluetoothAudioSinkChromeOSTest, RegisterSucceeded) { |
194 GetAudioSink(); | 228 GetAudioSink(); |
195 | |
196 // Adds an observer for |audio_sink_|. | |
197 TestAudioSinkObserver observer(audio_sink_); | |
198 EXPECT_EQ(observer.state_changed_count_, 0); | |
199 EXPECT_EQ(observer.volume_changed_count_, 0); | |
200 } | 229 } |
201 | 230 |
202 TEST_F(BluetoothAudioSinkChromeOSTest, RegisterFailedWithInvalidOptions) { | 231 TEST_F(BluetoothAudioSinkChromeOSTest, RegisterFailedWithInvalidOptions) { |
203 // Sets options with an invalid codec and valid capabilities. | 232 // Sets options with an invalid codec and valid capabilities. |
204 BluetoothAudioSink::Options options; | 233 BluetoothAudioSink::Options options; |
205 options.codec = 0xff; | 234 options.codec = 0xff; |
206 options.capabilities = std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35}); | 235 options.capabilities = std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35}); |
207 | 236 |
208 adapter_->RegisterAudioSink( | 237 adapter_->RegisterAudioSink( |
209 options, | 238 options, |
(...skipping 15 matching lines...) Expand all Loading... |
225 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterErrorCallback, | 254 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterErrorCallback, |
226 base::Unretained(this))); | 255 base::Unretained(this))); |
227 | 256 |
228 EXPECT_EQ(callback_count_, 0); | 257 EXPECT_EQ(callback_count_, 0); |
229 EXPECT_EQ(error_callback_count_, 2); | 258 EXPECT_EQ(error_callback_count_, 2); |
230 } | 259 } |
231 | 260 |
232 TEST_F(BluetoothAudioSinkChromeOSTest, SelectConfiguration) { | 261 TEST_F(BluetoothAudioSinkChromeOSTest, SelectConfiguration) { |
233 GetAudioSink(); | 262 GetAudioSink(); |
234 | 263 |
235 // Adds an observer for |audio_sink_|. | |
236 TestAudioSinkObserver observer(audio_sink_); | |
237 EXPECT_EQ(observer.state_changed_count_, 0); | |
238 EXPECT_EQ(observer.volume_changed_count_, 0); | |
239 | |
240 // Simulates calling SelectConfiguration on the media endpoint object owned by | 264 // Simulates calling SelectConfiguration on the media endpoint object owned by |
241 // |audio_sink_| with some fake capabilities. | 265 // |audio_sink_| with some fake capabilities. |
242 BluetoothAudioSinkChromeOS* audio_sink_chromeos = | 266 media_endpoint_->SelectConfiguration( |
243 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get()); | |
244 FakeBluetoothMediaEndpointServiceProvider* media_endpoint = | |
245 static_cast<FakeBluetoothMediaEndpointServiceProvider*>( | |
246 audio_sink_chromeos->GetEndpointServiceProvider()); | |
247 ASSERT_NE(media_endpoint, nullptr); | |
248 | |
249 media_endpoint->SelectConfiguration( | |
250 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 267 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
251 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 268 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
252 base::Unretained(this))); | 269 base::Unretained(this))); |
253 | 270 |
254 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 271 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
255 EXPECT_EQ(callback_count_, 2); | 272 EXPECT_EQ(callback_count_, 2); |
256 EXPECT_EQ(error_callback_count_, 0); | 273 EXPECT_EQ(error_callback_count_, 0); |
257 EXPECT_EQ(observer.state_changed_count_, 0); | 274 EXPECT_EQ(observer_->state_changed_count_, 0); |
258 EXPECT_EQ(observer.volume_changed_count_, 0); | 275 EXPECT_EQ(observer_->volume_changed_count_, 0); |
259 } | 276 } |
260 | 277 |
261 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfiguration) { | 278 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfiguration) { |
262 GetAudioSink(); | 279 GetAudioSink(); |
263 | 280 |
264 // Adds an observer for |audio_sink_|. | 281 media_endpoint_->SelectConfiguration( |
265 TestAudioSinkObserver observer(audio_sink_); | 282 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
266 EXPECT_EQ(observer.state_changed_count_, 0); | 283 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
267 EXPECT_EQ(observer.volume_changed_count_, 0); | 284 base::Unretained(this))); |
| 285 |
| 286 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
| 287 EXPECT_EQ(callback_count_, 2); |
| 288 EXPECT_EQ(error_callback_count_, 0); |
| 289 EXPECT_EQ(observer_->state_changed_count_, 0); |
| 290 EXPECT_EQ(observer_->volume_changed_count_, 0); |
268 | 291 |
269 // Simulates calling SetConfiguration on the media endpoint object owned by | 292 // Simulates calling SetConfiguration on the media endpoint object owned by |
270 // |audio_sink_| with a fake transport path and a | 293 // |audio_sink_| with a fake transport path and a |
271 // Delegate::TransportProperties structure. | 294 // Delegate::TransportProperties structure. |
272 BluetoothAudioSinkChromeOS* audio_sink_chromeos = | 295 media_endpoint_->SetConfiguration( |
273 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get()); | 296 transport_->GetTransportPath(media_endpoint_->object_path()), |
274 FakeBluetoothMediaEndpointServiceProvider* media_endpoint = | 297 properties_); |
275 static_cast<FakeBluetoothMediaEndpointServiceProvider*>( | 298 |
276 audio_sink_chromeos->GetEndpointServiceProvider()); | 299 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
277 ASSERT_NE(media_endpoint, nullptr); | 300 EXPECT_EQ(callback_count_, 2); |
278 | 301 EXPECT_EQ(error_callback_count_, 0); |
279 media_endpoint->SetConfiguration( | 302 EXPECT_EQ(observer_->state_changed_count_, 1); |
280 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath), | 303 EXPECT_EQ(observer_->volume_changed_count_, 1); |
281 properties_); | |
282 | |
283 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | |
284 EXPECT_EQ(callback_count_, 1); | |
285 EXPECT_EQ(error_callback_count_, 0); | |
286 EXPECT_EQ(observer.state_changed_count_, 1); | |
287 EXPECT_EQ(observer.volume_changed_count_, 1); | |
288 } | 304 } |
289 | 305 |
290 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfigurationWithUnexpectedState) { | 306 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfigurationWithUnexpectedState) { |
291 GetAudioSink(); | 307 GetAudioSink(); |
292 | 308 |
293 // Adds an observer for |audio_sink_|. | 309 media_endpoint_->SelectConfiguration( |
294 TestAudioSinkObserver observer(audio_sink_); | 310 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
295 EXPECT_EQ(observer.state_changed_count_, 0); | 311 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
296 EXPECT_EQ(observer.volume_changed_count_, 0); | 312 base::Unretained(this))); |
297 | 313 |
298 // Simulates calling SetConfiguration on the media endpoint object owned by | 314 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
299 // |audio_sink_| with a fake transport path and a | 315 EXPECT_EQ(callback_count_, 2); |
300 // Delegate::TransportProperties structure. | 316 EXPECT_EQ(error_callback_count_, 0); |
301 BluetoothAudioSinkChromeOS* audio_sink_chromeos = | 317 EXPECT_EQ(observer_->state_changed_count_, 0); |
302 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get()); | 318 EXPECT_EQ(observer_->volume_changed_count_, 0); |
303 FakeBluetoothMediaEndpointServiceProvider* media_endpoint = | |
304 static_cast<FakeBluetoothMediaEndpointServiceProvider*>( | |
305 audio_sink_chromeos->GetEndpointServiceProvider()); | |
306 ASSERT_NE(media_endpoint, nullptr); | |
307 | 319 |
308 // Set state of Delegate::TransportProperties with an unexpected value. | 320 // Set state of Delegate::TransportProperties with an unexpected value. |
309 properties_.state = "active"; | 321 properties_.state = "pending"; |
310 | 322 |
311 media_endpoint->SetConfiguration( | 323 media_endpoint_->SetConfiguration( |
312 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath), | 324 transport_->GetTransportPath(media_endpoint_->object_path()), |
313 properties_); | 325 properties_); |
314 | 326 |
315 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 327 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
316 EXPECT_EQ(callback_count_, 1); | 328 EXPECT_EQ(callback_count_, 2); |
317 EXPECT_EQ(error_callback_count_, 0); | 329 EXPECT_EQ(error_callback_count_, 0); |
318 EXPECT_EQ(observer.state_changed_count_, 0); | 330 EXPECT_EQ(observer_->state_changed_count_, 0); |
319 EXPECT_EQ(observer.volume_changed_count_, 0); | 331 EXPECT_EQ(observer_->volume_changed_count_, 0); |
320 } | 332 } |
321 | 333 |
322 // Checks if the observer is notified while the media object is | 334 // TODO(mcchou): Adds test on media-removed events for STATE_PENDING and |
323 // removed(invisible). Once the media object is removed, the audio sink is no | 335 // STATE_ACTIVE. |
324 // longer valid. | 336 // Checks if the observer is notified on media-removed event when the state of |
325 TEST_F(BluetoothAudioSinkChromeOSTest, ObserverNotifiedWhenMediaRemoved) { | 337 // |audio_sink_| is STATE_DISCONNECTED. Once the media object is removed, the |
326 GetAudioSink(); | 338 // audio sink is no longer valid. |
327 | 339 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringDisconnectedState) { |
328 // Adds an observer for |audio_sink_|. | 340 GetAudioSink(); |
329 TestAudioSinkObserver observer(audio_sink_); | |
330 EXPECT_EQ(observer.state_changed_count_, 0); | |
331 EXPECT_EQ(observer.volume_changed_count_, 0); | |
332 | 341 |
333 // Gets the media object and makes it invisible to see if the state of the | 342 // Gets the media object and makes it invisible to see if the state of the |
334 // audio sink changes accordingly. | 343 // audio sink changes accordingly. |
335 FakeBluetoothMediaClient* media = static_cast<FakeBluetoothMediaClient*>( | 344 media_->SetVisible(false); |
336 DBusThreadManager::Get()->GetBluetoothMediaClient()); | 345 |
337 media->SetVisible(false); | 346 GetFakeMediaEndpoint(); |
338 | |
339 BluetoothAudioSinkChromeOS* audio_sink_chromeos = | |
340 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get()); | |
341 FakeBluetoothMediaEndpointServiceProvider* media_endpoint = | |
342 static_cast<FakeBluetoothMediaEndpointServiceProvider*>( | |
343 audio_sink_chromeos->GetEndpointServiceProvider()); | |
344 | 347 |
345 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); | 348 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
346 EXPECT_EQ(media_endpoint, nullptr); | 349 EXPECT_EQ(media_endpoint_, nullptr); |
347 } | 350 EXPECT_EQ(observer_->state_changed_count_, 1); |
348 | 351 EXPECT_EQ(observer_->volume_changed_count_, 0); |
349 // Checks if the observer is notified while the media transport is | 352 } |
350 // removed(invisible). Once the media transport object is removed, the audio | 353 |
351 // sink is disconnected. | 354 // Checks if the observer is notified on media-removed event when the state of |
352 TEST_F(BluetoothAudioSinkChromeOSTest, ObserverNotifiedWhenTransportRemoved) { | 355 // |audio_sink_| is STATE_IDLE. Once the media object is removed, the audio sink |
353 GetAudioSink(); | 356 // is no longer valid. |
354 | 357 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringIdleState) { |
355 // Adds an observer for |audio_sink_|. | 358 GetAudioSink(); |
356 TestAudioSinkObserver observer(audio_sink_); | 359 |
357 EXPECT_EQ(observer.state_changed_count_, 0); | 360 media_endpoint_->SelectConfiguration( |
358 EXPECT_EQ(observer.volume_changed_count_, 0); | 361 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
359 | 362 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
360 // Simulates calling SetConfiguration on the media endpoint object owned by | 363 base::Unretained(this))); |
361 // |audio_sink_| with a fake transport path and a | 364 |
362 // Delegate::TransportProperties structure. | 365 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
363 BluetoothAudioSinkChromeOS* audio_sink_chromeos = | 366 EXPECT_EQ(callback_count_, 2); |
364 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get()); | 367 EXPECT_EQ(error_callback_count_, 0); |
365 FakeBluetoothMediaEndpointServiceProvider* media_endpoint = | 368 EXPECT_EQ(observer_->state_changed_count_, 0); |
366 static_cast<FakeBluetoothMediaEndpointServiceProvider*>( | 369 EXPECT_EQ(observer_->volume_changed_count_, 0); |
367 audio_sink_chromeos->GetEndpointServiceProvider()); | 370 |
368 ASSERT_NE(media_endpoint, nullptr); | 371 media_endpoint_->SetConfiguration( |
369 | 372 transport_->GetTransportPath(media_endpoint_->object_path()), |
370 media_endpoint->SetConfiguration( | 373 properties_); |
371 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath), | 374 |
372 properties_); | 375 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
373 | 376 EXPECT_EQ(callback_count_, 2); |
374 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 377 EXPECT_EQ(error_callback_count_, 0); |
375 EXPECT_EQ(callback_count_, 1); | 378 EXPECT_EQ(observer_->state_changed_count_, 1); |
376 EXPECT_EQ(error_callback_count_, 0); | 379 EXPECT_EQ(observer_->volume_changed_count_, 1); |
377 EXPECT_EQ(observer.state_changed_count_, 1); | 380 |
378 EXPECT_EQ(observer.volume_changed_count_, 1); | 381 // Gets the media object and makes it invisible to see if the state of the |
379 | 382 // audio sink changes accordingly. |
380 // Gets the media transport object and makes it invalid to see if the state | 383 media_->SetVisible(false); |
381 // of the audio sink changes accordingly. | 384 |
382 FakeBluetoothMediaTransportClient* transport = | 385 GetFakeMediaEndpoint(); |
383 static_cast<FakeBluetoothMediaTransportClient*>( | 386 |
384 DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); | 387 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
385 | 388 EXPECT_EQ(media_endpoint_, nullptr); |
386 transport->SetValid(media_endpoint->object_path(), false); | 389 |
387 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 390 // The state becomes disconnted and then invalid, since the removal of |
388 EXPECT_NE(media_endpoint, nullptr); | 391 // transport object should happend before media becomes invisible. |
| 392 // State: STATE_IDLE -> STATE_DISCONNECTED -> STATE_INVALID |
| 393 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 394 EXPECT_EQ(observer_->volume_changed_count_, 2); |
| 395 } |
| 396 |
| 397 // TODO(mcchou): Add tests on transport-removed event for STATE_PENDING and |
| 398 // STATE_ACTIVE. |
| 399 // Checks if the observer is notified on transport-removed event when the state |
| 400 // of |audio_sink_| is STATE_IDEL. Once the media transport object is removed, |
| 401 // the audio sink is disconnected. |
| 402 TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringIdleState) { |
| 403 GetAudioSink(); |
| 404 |
| 405 media_endpoint_->SelectConfiguration( |
| 406 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
| 407 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
| 408 base::Unretained(this))); |
| 409 |
| 410 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
| 411 EXPECT_EQ(callback_count_, 2); |
| 412 EXPECT_EQ(error_callback_count_, 0); |
| 413 EXPECT_EQ(observer_->state_changed_count_, 0); |
| 414 EXPECT_EQ(observer_->volume_changed_count_, 0); |
| 415 |
| 416 media_endpoint_->SetConfiguration( |
| 417 transport_->GetTransportPath(media_endpoint_->object_path()), |
| 418 properties_); |
| 419 |
| 420 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 421 EXPECT_EQ(callback_count_, 2); |
| 422 EXPECT_EQ(error_callback_count_, 0); |
| 423 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 424 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 425 |
| 426 // Makes the transport object invalid to see if the state of the audio sink |
| 427 // changes accordingly. |
| 428 transport_->SetValid(media_endpoint_, false); |
| 429 |
| 430 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
| 431 EXPECT_NE(media_endpoint_, nullptr); |
| 432 EXPECT_EQ(observer_->state_changed_count_, 2); |
| 433 EXPECT_EQ(observer_->volume_changed_count_, 2); |
| 434 } |
| 435 |
| 436 TEST_F(BluetoothAudioSinkChromeOSTest, |
| 437 AdapterPoweredChangedDuringDisconnectedState) { |
| 438 GetAudioSink(); |
| 439 |
| 440 adapter_->SetPowered( |
| 441 false, |
| 442 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
| 443 base::Unretained(this)), |
| 444 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback, |
| 445 base::Unretained(this))); |
| 446 |
| 447 EXPECT_TRUE(adapter_->IsPresent()); |
| 448 EXPECT_FALSE(adapter_->IsPowered()); |
| 449 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
| 450 EXPECT_EQ(callback_count_, 2); |
| 451 EXPECT_EQ(error_callback_count_, 0); |
| 452 EXPECT_EQ(observer_->state_changed_count_, 0); |
| 453 EXPECT_EQ(observer_->volume_changed_count_, 0); |
| 454 |
| 455 adapter_->SetPowered( |
| 456 true, |
| 457 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
| 458 base::Unretained(this)), |
| 459 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback, |
| 460 base::Unretained(this))); |
| 461 |
| 462 EXPECT_TRUE(adapter_->IsPresent()); |
| 463 EXPECT_TRUE(adapter_->IsPowered()); |
| 464 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
| 465 EXPECT_EQ(callback_count_, 3); |
| 466 EXPECT_EQ(error_callback_count_, 0); |
| 467 EXPECT_EQ(observer_->state_changed_count_, 0); |
| 468 EXPECT_EQ(observer_->volume_changed_count_, 0); |
| 469 } |
| 470 |
| 471 TEST_F(BluetoothAudioSinkChromeOSTest, AdapterPoweredChangedDuringIdleState) { |
| 472 GetAudioSink(); |
| 473 |
| 474 media_endpoint_->SelectConfiguration( |
| 475 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
| 476 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
| 477 base::Unretained(this))); |
| 478 |
| 479 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
| 480 EXPECT_EQ(callback_count_, 2); |
| 481 EXPECT_EQ(error_callback_count_, 0); |
| 482 EXPECT_EQ(observer_->state_changed_count_, 0); |
| 483 EXPECT_EQ(observer_->volume_changed_count_, 0); |
| 484 |
| 485 media_endpoint_->SetConfiguration( |
| 486 transport_->GetTransportPath(media_endpoint_->object_path()), |
| 487 properties_); |
| 488 |
| 489 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 490 EXPECT_EQ(callback_count_, 2); |
| 491 EXPECT_EQ(error_callback_count_, 0); |
| 492 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 493 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 494 |
| 495 adapter_->SetPowered( |
| 496 false, |
| 497 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
| 498 base::Unretained(this)), |
| 499 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback, |
| 500 base::Unretained(this))); |
| 501 GetFakeMediaEndpoint(); |
| 502 |
| 503 EXPECT_TRUE(adapter_->IsPresent()); |
| 504 EXPECT_FALSE(adapter_->IsPowered()); |
| 505 EXPECT_NE(media_endpoint_, nullptr); |
| 506 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
| 507 EXPECT_EQ(callback_count_, 3); |
| 508 EXPECT_EQ(error_callback_count_, 0); |
| 509 EXPECT_EQ(observer_->state_changed_count_, 2); |
| 510 EXPECT_EQ(observer_->volume_changed_count_, 2); |
| 511 } |
| 512 |
| 513 // TODO(mcchou): Add tests on UnregisterAudioSink for STATE_PENDING and |
| 514 // STATE_ACTIVE. |
| 515 |
| 516 TEST_F(BluetoothAudioSinkChromeOSTest, |
| 517 UnregisterAudioSinkDuringDisconnectedState) { |
| 518 GetAudioSink(); |
| 519 |
| 520 audio_sink_->Unregister( |
| 521 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
| 522 base::Unretained(this)), |
| 523 base::Bind(&BluetoothAudioSinkChromeOSTest::UnregisterErrorCallback, |
| 524 base::Unretained(this))); |
| 525 |
| 526 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
| 527 EXPECT_EQ(callback_count_, 2); |
| 528 EXPECT_EQ(error_callback_count_, 0); |
| 529 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 530 EXPECT_EQ(observer_->volume_changed_count_, 0); |
| 531 } |
| 532 |
| 533 TEST_F(BluetoothAudioSinkChromeOSTest, UnregisterAudioSinkDuringIdleState) { |
| 534 GetAudioSink(); |
| 535 |
| 536 media_endpoint_->SelectConfiguration( |
| 537 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
| 538 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
| 539 base::Unretained(this))); |
| 540 |
| 541 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
| 542 EXPECT_EQ(callback_count_, 2); |
| 543 EXPECT_EQ(error_callback_count_, 0); |
| 544 EXPECT_EQ(observer_->state_changed_count_, 0); |
| 545 EXPECT_EQ(observer_->volume_changed_count_, 0); |
| 546 |
| 547 media_endpoint_->SetConfiguration( |
| 548 transport_->GetTransportPath(media_endpoint_->object_path()), |
| 549 properties_); |
| 550 |
| 551 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 552 EXPECT_EQ(callback_count_, 2); |
| 553 EXPECT_EQ(error_callback_count_, 0); |
| 554 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 555 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 556 |
| 557 audio_sink_->Unregister( |
| 558 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
| 559 base::Unretained(this)), |
| 560 base::Bind(&BluetoothAudioSinkChromeOSTest::UnregisterErrorCallback, |
| 561 base::Unretained(this))); |
| 562 |
| 563 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
| 564 EXPECT_EQ(callback_count_, 3); |
| 565 EXPECT_EQ(error_callback_count_, 0); |
| 566 |
| 567 // The state becomes disconnted and then invalid, since the removal of |
| 568 // transport object should happend before the unregistration of endpoint. |
| 569 // State: STATE_IDLE -> STATE_DISCONNECTED -> STATE_INVALID |
| 570 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 571 EXPECT_EQ(observer_->volume_changed_count_, 2); |
389 } | 572 } |
390 | 573 |
391 } // namespace chromeos | 574 } // namespace chromeos |
OLD | NEW |