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 16 matching lines...) Expand all Loading... | |
27 using device::BluetoothAdapterFactory; | 27 using device::BluetoothAdapterFactory; |
28 using device::BluetoothAudioSink; | 28 using device::BluetoothAudioSink; |
29 | 29 |
30 namespace chromeos { | 30 namespace chromeos { |
31 | 31 |
32 class TestAudioSinkObserver : public BluetoothAudioSink::Observer { | 32 class TestAudioSinkObserver : public BluetoothAudioSink::Observer { |
33 public: | 33 public: |
34 explicit TestAudioSinkObserver(scoped_refptr<BluetoothAudioSink> audio_sink) | 34 explicit TestAudioSinkObserver(scoped_refptr<BluetoothAudioSink> audio_sink) |
35 : state_changed_count_(0), | 35 : state_changed_count_(0), |
36 volume_changed_count_(0), | 36 volume_changed_count_(0), |
37 total_read_(0), | |
37 state_(audio_sink->GetState()), | 38 state_(audio_sink->GetState()), |
38 audio_sink_(audio_sink) { | 39 audio_sink_(audio_sink) { |
39 audio_sink_->AddObserver(this); | 40 audio_sink_->AddObserver(this); |
40 } | 41 } |
41 | 42 |
42 ~TestAudioSinkObserver() override { audio_sink_->RemoveObserver(this); } | 43 ~TestAudioSinkObserver() override { audio_sink_->RemoveObserver(this); } |
43 | 44 |
44 void BluetoothAudioSinkStateChanged( | 45 void BluetoothAudioSinkStateChanged( |
45 BluetoothAudioSink* audio_sink, | 46 BluetoothAudioSink* audio_sink, |
46 BluetoothAudioSink::State state) override { | 47 BluetoothAudioSink::State state) override { |
48 if (state == BluetoothAudioSink::STATE_IDLE) | |
49 total_read_ = 0; | |
50 | |
47 ++state_changed_count_; | 51 ++state_changed_count_; |
48 } | 52 } |
49 | 53 |
50 void BluetoothAudioSinkVolumeChanged(BluetoothAudioSink* audio_sink, | 54 void BluetoothAudioSinkVolumeChanged(BluetoothAudioSink* audio_sink, |
51 uint16_t volume) override { | 55 uint16_t volume) override { |
52 ++volume_changed_count_; | 56 ++volume_changed_count_; |
53 } | 57 } |
54 | 58 |
59 void BluetoothAudioSinkDataAvailable(BluetoothAudioSink* audio_sink, | |
60 char* data, | |
61 size_t size) override { | |
62 total_read_ += size; | |
63 } | |
64 | |
55 int state_changed_count_; | 65 int state_changed_count_; |
56 int volume_changed_count_; | 66 int volume_changed_count_; |
67 int data_available_count_; | |
68 size_t total_read_; | |
57 BluetoothAudioSink::State state_; | 69 BluetoothAudioSink::State state_; |
58 | 70 |
59 private: | 71 private: |
60 scoped_refptr<BluetoothAudioSink> audio_sink_; | 72 scoped_refptr<BluetoothAudioSink> audio_sink_; |
61 }; | 73 }; |
62 | 74 |
63 class BluetoothAudioSinkChromeOSTest : public testing::Test { | 75 class BluetoothAudioSinkChromeOSTest : public testing::Test { |
64 public: | 76 public: |
65 void SetUp() override { | 77 void SetUp() override { |
66 DBusThreadManager::Initialize(); | 78 DBusThreadManager::Initialize(); |
67 | 79 |
68 callback_count_ = 0; | 80 callback_count_ = 0; |
69 error_callback_count_ = 0; | 81 error_callback_count_ = 0; |
70 | 82 |
83 fake_media_ = static_cast<FakeBluetoothMediaClient*>( | |
84 DBusThreadManager::Get()->GetBluetoothMediaClient()); | |
85 fake_transport_ = static_cast<FakeBluetoothMediaTransportClient*>( | |
86 DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); | |
87 | |
71 // Initiates Delegate::TransportProperties with default values. | 88 // Initiates Delegate::TransportProperties with default values. |
72 properties_.device = | 89 properties_.device = |
73 ObjectPath(FakeBluetoothMediaTransportClient::kTransportDevicePath); | 90 ObjectPath(FakeBluetoothMediaTransportClient::kTransportDevicePath); |
74 properties_.uuid = BluetoothMediaClient::kBluetoothAudioSinkUUID; | 91 properties_.uuid = BluetoothMediaClient::kBluetoothAudioSinkUUID; |
75 properties_.codec = FakeBluetoothMediaTransportClient::kTransportCodec; | 92 properties_.codec = FakeBluetoothMediaTransportClient::kTransportCodec; |
76 properties_.configuration = | 93 properties_.configuration = |
77 FakeBluetoothMediaTransportClient::kTransportConfiguration; | 94 FakeBluetoothMediaTransportClient::kTransportConfiguration; |
78 properties_.state = BluetoothMediaTransportClient::kStateIdle; | 95 properties_.state = BluetoothMediaTransportClient::kStateIdle; |
79 properties_.delay.reset( | 96 properties_.delay.reset( |
80 new uint16_t(FakeBluetoothMediaTransportClient::kTransportDelay)); | 97 new uint16_t(FakeBluetoothMediaTransportClient::kTransportDelay)); |
81 properties_.volume.reset( | 98 properties_.volume.reset( |
82 new uint16_t(FakeBluetoothMediaTransportClient::kTransportVolume)); | 99 new uint16_t(FakeBluetoothMediaTransportClient::kTransportVolume)); |
83 | 100 |
84 media_ = static_cast<FakeBluetoothMediaClient*>( | |
85 DBusThreadManager::Get()->GetBluetoothMediaClient()); | |
86 transport_ = static_cast<FakeBluetoothMediaTransportClient*>( | |
87 DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); | |
88 | |
89 GetAdapter(); | 101 GetAdapter(); |
90 } | 102 } |
91 | 103 |
92 void TearDown() override { | 104 void TearDown() override { |
93 callback_count_ = 0; | 105 callback_count_ = 0; |
94 error_callback_count_ = 0; | 106 error_callback_count_ = 0; |
95 observer_.reset(); | 107 observer_.reset(); |
96 | 108 |
97 media_->SetVisible(true); | 109 fake_media_->SetVisible(true); |
98 | 110 |
99 // The adapter should outlive audio sink. | 111 // The adapter should outlive audio sink. |
100 audio_sink_ = nullptr; | 112 audio_sink_ = nullptr; |
101 adapter_ = nullptr; | 113 adapter_ = nullptr; |
102 DBusThreadManager::Shutdown(); | 114 DBusThreadManager::Shutdown(); |
103 } | 115 } |
104 | 116 |
105 // Gets the existing Bluetooth adapter. | 117 // Gets the existing Bluetooth adapter. |
106 void GetAdapter() { | 118 void GetAdapter() { |
107 BluetoothAdapterFactory::GetAdapter( | 119 BluetoothAdapterFactory::GetAdapter( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 } | 177 } |
166 | 178 |
167 // Called whenever RegisterAudioSink is completed successfully. | 179 // Called whenever RegisterAudioSink is completed successfully. |
168 void RegisterCallback( | 180 void RegisterCallback( |
169 scoped_refptr<BluetoothAudioSink> audio_sink) { | 181 scoped_refptr<BluetoothAudioSink> audio_sink) { |
170 ++callback_count_; | 182 ++callback_count_; |
171 audio_sink_ = audio_sink; | 183 audio_sink_ = audio_sink; |
172 | 184 |
173 GetFakeMediaEndpoint(); | 185 GetFakeMediaEndpoint(); |
174 ASSERT_NE(media_endpoint_, nullptr); | 186 ASSERT_NE(media_endpoint_, nullptr); |
175 media_->SetEndpointRegistered(media_endpoint_, true); | 187 fake_media_->SetEndpointRegistered(media_endpoint_, true); |
176 | 188 |
177 ASSERT_NE(audio_sink_.get(), nullptr); | 189 ASSERT_NE(audio_sink_.get(), nullptr); |
178 ASSERT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 190 ASSERT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
179 } | 191 } |
180 | 192 |
181 // Called whenever RegisterAudioSink failed. | 193 // Called whenever RegisterAudioSink failed. |
182 void RegisterErrorCallback(BluetoothAudioSink::ErrorCode error_code) { | 194 void RegisterErrorCallback(BluetoothAudioSink::ErrorCode error_code) { |
183 ++error_callback_count_; | 195 ++error_callback_count_; |
184 EXPECT_EQ(error_code, BluetoothAudioSink::ERROR_NOT_REGISTERED); | 196 EXPECT_EQ(error_code, BluetoothAudioSink::ERROR_NOT_REGISTERED); |
185 } | 197 } |
(...skipping 18 matching lines...) Expand all Loading... | |
204 } | 216 } |
205 | 217 |
206 void ErrorCallback() { | 218 void ErrorCallback() { |
207 ++error_callback_count_; | 219 ++error_callback_count_; |
208 } | 220 } |
209 | 221 |
210 protected: | 222 protected: |
211 int callback_count_; | 223 int callback_count_; |
212 int error_callback_count_; | 224 int error_callback_count_; |
213 | 225 |
214 base::MessageLoop message_loop_; | 226 base::MessageLoopForIO message_loop_; |
215 | 227 |
216 FakeBluetoothMediaClient* media_; | 228 FakeBluetoothMediaClient* fake_media_; |
217 FakeBluetoothMediaTransportClient* transport_; | 229 FakeBluetoothMediaTransportClient* fake_transport_; |
218 FakeBluetoothMediaEndpointServiceProvider* media_endpoint_; | 230 FakeBluetoothMediaEndpointServiceProvider* media_endpoint_; |
219 scoped_ptr<TestAudioSinkObserver> observer_; | 231 scoped_ptr<TestAudioSinkObserver> observer_; |
220 scoped_refptr<BluetoothAdapter> adapter_; | 232 scoped_refptr<BluetoothAdapter> adapter_; |
221 scoped_refptr<BluetoothAudioSink> audio_sink_; | 233 scoped_refptr<BluetoothAudioSink> audio_sink_; |
222 | 234 |
223 // The default property set used while calling SetConfiguration on a media | 235 // The default property set used while calling SetConfiguration on a media |
224 // endpoint object. | 236 // endpoint object. |
225 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties | 237 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties |
226 properties_; | 238 properties_; |
227 }; | 239 }; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 300 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
289 EXPECT_EQ(callback_count_, 2); | 301 EXPECT_EQ(callback_count_, 2); |
290 EXPECT_EQ(error_callback_count_, 0); | 302 EXPECT_EQ(error_callback_count_, 0); |
291 EXPECT_EQ(observer_->state_changed_count_, 0); | 303 EXPECT_EQ(observer_->state_changed_count_, 0); |
292 EXPECT_EQ(observer_->volume_changed_count_, 0); | 304 EXPECT_EQ(observer_->volume_changed_count_, 0); |
293 | 305 |
294 // Simulates calling SetConfiguration on the media endpoint object owned by | 306 // Simulates calling SetConfiguration on the media endpoint object owned by |
295 // |audio_sink_| with a fake transport path and a | 307 // |audio_sink_| with a fake transport path and a |
296 // Delegate::TransportProperties structure. | 308 // Delegate::TransportProperties structure. |
297 media_endpoint_->SetConfiguration( | 309 media_endpoint_->SetConfiguration( |
298 transport_->GetTransportPath(media_endpoint_->object_path()), | 310 fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
299 properties_); | 311 properties_); |
300 | 312 |
301 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 313 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
302 EXPECT_EQ(callback_count_, 2); | 314 EXPECT_EQ(callback_count_, 2); |
303 EXPECT_EQ(error_callback_count_, 0); | 315 EXPECT_EQ(error_callback_count_, 0); |
304 EXPECT_EQ(observer_->state_changed_count_, 1); | 316 EXPECT_EQ(observer_->state_changed_count_, 1); |
305 EXPECT_EQ(observer_->volume_changed_count_, 1); | 317 EXPECT_EQ(observer_->volume_changed_count_, 1); |
306 } | 318 } |
307 | 319 |
308 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfigurationWithUnexpectedState) { | 320 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfigurationWithUnexpectedState) { |
309 GetAudioSink(); | 321 GetAudioSink(); |
310 | 322 |
311 media_endpoint_->SelectConfiguration( | 323 media_endpoint_->SelectConfiguration( |
312 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 324 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
313 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 325 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
314 base::Unretained(this))); | 326 base::Unretained(this))); |
315 | 327 |
316 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 328 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
317 EXPECT_EQ(callback_count_, 2); | 329 EXPECT_EQ(callback_count_, 2); |
318 EXPECT_EQ(error_callback_count_, 0); | 330 EXPECT_EQ(error_callback_count_, 0); |
319 EXPECT_EQ(observer_->state_changed_count_, 0); | 331 EXPECT_EQ(observer_->state_changed_count_, 0); |
320 EXPECT_EQ(observer_->volume_changed_count_, 0); | 332 EXPECT_EQ(observer_->volume_changed_count_, 0); |
321 | 333 |
322 // Set state of Delegate::TransportProperties with an unexpected value. | 334 // Set state of Delegate::TransportProperties with an unexpected value. |
323 properties_.state = "pending"; | 335 properties_.state = "pending"; |
324 | 336 |
325 media_endpoint_->SetConfiguration( | 337 media_endpoint_->SetConfiguration( |
326 transport_->GetTransportPath(media_endpoint_->object_path()), | 338 fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
327 properties_); | 339 properties_); |
328 | 340 |
329 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 341 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
330 EXPECT_EQ(callback_count_, 2); | 342 EXPECT_EQ(callback_count_, 2); |
331 EXPECT_EQ(error_callback_count_, 0); | 343 EXPECT_EQ(error_callback_count_, 0); |
332 EXPECT_EQ(observer_->state_changed_count_, 0); | 344 EXPECT_EQ(observer_->state_changed_count_, 0); |
333 EXPECT_EQ(observer_->volume_changed_count_, 0); | 345 EXPECT_EQ(observer_->volume_changed_count_, 0); |
334 } | 346 } |
335 | 347 |
336 // TODO(mcchou): Adds test on media-removed events for STATE_PENDING and | |
337 // STATE_ACTIVE. | |
338 // Checks if the observer is notified on media-removed event when the state of | 348 // Checks if the observer is notified on media-removed event when the state of |
339 // |audio_sink_| is STATE_DISCONNECTED. Once the media object is removed, the | 349 // |audio_sink_| is STATE_DISCONNECTED. Once the media object is removed, the |
340 // audio sink is no longer valid. | 350 // audio sink is no longer valid. |
341 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringDisconnectedState) { | 351 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringDisconnectedState) { |
342 GetAudioSink(); | 352 GetAudioSink(); |
343 | 353 |
344 // Gets the media object and makes it invisible to see if the state of the | 354 // Gets the media object and makes it invisible to see if the state of the |
345 // audio sink changes accordingly. | 355 // audio sink changes accordingly. |
346 media_->SetVisible(false); | 356 fake_media_->SetVisible(false); |
347 | 357 |
348 GetFakeMediaEndpoint(); | 358 GetFakeMediaEndpoint(); |
349 | 359 |
350 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); | 360 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
351 EXPECT_EQ(media_endpoint_, nullptr); | 361 EXPECT_EQ(media_endpoint_, nullptr); |
352 EXPECT_EQ(observer_->state_changed_count_, 1); | 362 EXPECT_EQ(observer_->state_changed_count_, 1); |
353 EXPECT_EQ(observer_->volume_changed_count_, 0); | 363 EXPECT_EQ(observer_->volume_changed_count_, 0); |
354 } | 364 } |
355 | 365 |
356 // Checks if the observer is notified on media-removed event when the state of | 366 // Checks if the observer is notified on media-removed event when the state of |
357 // |audio_sink_| is STATE_IDLE. Once the media object is removed, the audio sink | 367 // |audio_sink_| is STATE_IDLE. Once the media object is removed, the audio sink |
358 // is no longer valid. | 368 // is no longer valid. |
359 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringIdleState) { | 369 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringIdleState) { |
360 GetAudioSink(); | 370 GetAudioSink(); |
361 | 371 |
362 media_endpoint_->SelectConfiguration( | 372 media_endpoint_->SelectConfiguration( |
363 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 373 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
364 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 374 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
365 base::Unretained(this))); | 375 base::Unretained(this))); |
366 | 376 |
367 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 377 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
368 EXPECT_EQ(callback_count_, 2); | 378 EXPECT_EQ(callback_count_, 2); |
369 EXPECT_EQ(error_callback_count_, 0); | 379 EXPECT_EQ(error_callback_count_, 0); |
370 EXPECT_EQ(observer_->state_changed_count_, 0); | 380 EXPECT_EQ(observer_->state_changed_count_, 0); |
371 EXPECT_EQ(observer_->volume_changed_count_, 0); | 381 EXPECT_EQ(observer_->volume_changed_count_, 0); |
372 | 382 |
373 media_endpoint_->SetConfiguration( | 383 media_endpoint_->SetConfiguration( |
374 transport_->GetTransportPath(media_endpoint_->object_path()), | 384 fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
375 properties_); | 385 properties_); |
376 | 386 |
377 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 387 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
378 EXPECT_EQ(callback_count_, 2); | 388 EXPECT_EQ(callback_count_, 2); |
379 EXPECT_EQ(error_callback_count_, 0); | 389 EXPECT_EQ(error_callback_count_, 0); |
380 EXPECT_EQ(observer_->state_changed_count_, 1); | 390 EXPECT_EQ(observer_->state_changed_count_, 1); |
381 EXPECT_EQ(observer_->volume_changed_count_, 1); | 391 EXPECT_EQ(observer_->volume_changed_count_, 1); |
382 | 392 |
383 // Gets the media object and makes it invisible to see if the state of the | 393 // Gets the media object and makes it invisible to see if the state of the |
384 // audio sink changes accordingly. | 394 // audio sink changes accordingly. |
385 media_->SetVisible(false); | 395 fake_media_->SetVisible(false); |
386 | 396 |
387 GetFakeMediaEndpoint(); | 397 GetFakeMediaEndpoint(); |
388 | 398 |
389 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); | 399 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
390 EXPECT_EQ(media_endpoint_, nullptr); | 400 EXPECT_EQ(media_endpoint_, nullptr); |
391 | 401 |
392 // The state becomes disconnted and then invalid, since the removal of | 402 // The state becomes disconnted and then invalid, since the removal of |
393 // transport object should happend before media becomes invisible. | 403 // transport object should happend before media becomes invisible. |
394 // State: STATE_IDLE -> STATE_DISCONNECTED -> STATE_INVALID | 404 // State: STATE_IDLE -> STATE_DISCONNECTED -> STATE_INVALID |
395 EXPECT_EQ(observer_->state_changed_count_, 3); | 405 EXPECT_EQ(observer_->state_changed_count_, 3); |
396 EXPECT_EQ(observer_->volume_changed_count_, 2); | 406 EXPECT_EQ(observer_->volume_changed_count_, 2); |
397 } | 407 } |
398 | 408 |
399 // TODO(mcchou): Add tests on transport-removed event for STATE_PENDING and | 409 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringActiveState) { |
400 // STATE_ACTIVE. | 410 GetAudioSink(); |
411 | |
412 media_endpoint_->SelectConfiguration( | |
413 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | |
414 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | |
415 base::Unretained(this))); | |
416 | |
417 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | |
418 EXPECT_EQ(callback_count_, 2); | |
419 EXPECT_EQ(error_callback_count_, 0); | |
420 EXPECT_EQ(observer_->state_changed_count_, 0); | |
421 EXPECT_EQ(observer_->volume_changed_count_, 0); | |
422 | |
423 media_endpoint_->SetConfiguration( | |
424 fake_transport_->GetTransportPath(media_endpoint_->object_path()), | |
425 properties_); | |
426 | |
427 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | |
428 EXPECT_EQ(callback_count_, 2); | |
429 EXPECT_EQ(error_callback_count_, 0); | |
430 EXPECT_EQ(observer_->state_changed_count_, 1); | |
431 EXPECT_EQ(observer_->volume_changed_count_, 1); | |
432 | |
433 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | |
434 | |
435 message_loop_.RunUntilIdle(); | |
436 | |
437 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | |
438 // and Acquire will trigger state change. Therefore, the state will be | |
439 // STATE_ACTIVE right after STATE_PENDING. | |
440 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | |
441 EXPECT_EQ(observer_->state_changed_count_, 3); | |
442 | |
443 // Gets the media object and makes it invisible to see if the state of the | |
444 // audio sink changes accordingly. | |
445 fake_media_->SetVisible(false); | |
446 | |
447 GetFakeMediaEndpoint(); | |
448 | |
449 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); | |
450 EXPECT_EQ(media_endpoint_, nullptr); | |
451 | |
452 // The state becomes disconnted and then invalid, since the removal of | |
453 // transport object should happend before media becomes invisible. | |
454 // State: STATE_ACTIVE -> STATE_DISCONNECTED -> STATE_INVALID | |
455 EXPECT_EQ(observer_->state_changed_count_, 5); | |
456 EXPECT_EQ(observer_->volume_changed_count_, 2); | |
457 } | |
458 | |
401 // Checks if the observer is notified on transport-removed event when the state | 459 // Checks if the observer is notified on transport-removed event when the state |
402 // of |audio_sink_| is STATE_IDEL. Once the media transport object is removed, | 460 // of |audio_sink_| is STATE_IDEL. Once the media transport object is removed, |
403 // the audio sink is disconnected. | 461 // the audio sink is disconnected. |
404 TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringIdleState) { | 462 TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringIdleState) { |
405 GetAudioSink(); | 463 GetAudioSink(); |
406 | 464 |
407 media_endpoint_->SelectConfiguration( | 465 media_endpoint_->SelectConfiguration( |
408 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 466 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
409 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 467 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
410 base::Unretained(this))); | 468 base::Unretained(this))); |
411 | 469 |
412 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 470 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
413 EXPECT_EQ(callback_count_, 2); | 471 EXPECT_EQ(callback_count_, 2); |
414 EXPECT_EQ(error_callback_count_, 0); | 472 EXPECT_EQ(error_callback_count_, 0); |
415 EXPECT_EQ(observer_->state_changed_count_, 0); | 473 EXPECT_EQ(observer_->state_changed_count_, 0); |
416 EXPECT_EQ(observer_->volume_changed_count_, 0); | 474 EXPECT_EQ(observer_->volume_changed_count_, 0); |
417 | 475 |
418 media_endpoint_->SetConfiguration( | 476 media_endpoint_->SetConfiguration( |
419 transport_->GetTransportPath(media_endpoint_->object_path()), | 477 fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
420 properties_); | 478 properties_); |
421 | 479 |
422 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 480 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
423 EXPECT_EQ(callback_count_, 2); | 481 EXPECT_EQ(callback_count_, 2); |
424 EXPECT_EQ(error_callback_count_, 0); | 482 EXPECT_EQ(error_callback_count_, 0); |
425 EXPECT_EQ(observer_->state_changed_count_, 1); | 483 EXPECT_EQ(observer_->state_changed_count_, 1); |
426 EXPECT_EQ(observer_->volume_changed_count_, 1); | 484 EXPECT_EQ(observer_->volume_changed_count_, 1); |
427 | 485 |
428 // Makes the transport object invalid to see if the state of the audio sink | 486 // Makes the transport object invalid to see if the state of the audio sink |
429 // changes accordingly. | 487 // changes accordingly. |
430 transport_->SetValid(media_endpoint_, false); | 488 fake_transport_->SetValid(media_endpoint_, false); |
431 | 489 |
432 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 490 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
433 EXPECT_NE(media_endpoint_, nullptr); | 491 EXPECT_NE(media_endpoint_, nullptr); |
434 EXPECT_EQ(observer_->state_changed_count_, 2); | 492 EXPECT_EQ(observer_->state_changed_count_, 2); |
435 EXPECT_EQ(observer_->volume_changed_count_, 2); | 493 EXPECT_EQ(observer_->volume_changed_count_, 2); |
436 } | 494 } |
437 | 495 |
496 TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringActiveState) { | |
497 GetAudioSink(); | |
498 | |
499 media_endpoint_->SelectConfiguration( | |
500 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | |
501 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | |
502 base::Unretained(this))); | |
503 | |
504 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | |
505 EXPECT_EQ(callback_count_, 2); | |
506 EXPECT_EQ(error_callback_count_, 0); | |
507 EXPECT_EQ(observer_->state_changed_count_, 0); | |
508 EXPECT_EQ(observer_->volume_changed_count_, 0); | |
509 | |
510 media_endpoint_->SetConfiguration( | |
511 fake_transport_->GetTransportPath(media_endpoint_->object_path()), | |
512 properties_); | |
513 | |
514 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | |
515 EXPECT_EQ(callback_count_, 2); | |
516 EXPECT_EQ(error_callback_count_, 0); | |
517 EXPECT_EQ(observer_->state_changed_count_, 1); | |
518 EXPECT_EQ(observer_->volume_changed_count_, 1); | |
519 | |
520 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | |
521 | |
522 message_loop_.RunUntilIdle(); | |
523 | |
524 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | |
525 // and Acquire will trigger state change. Therefore, the state will be | |
526 // STATE_ACTIVE right after STATE_PENDING. | |
527 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | |
528 EXPECT_EQ(observer_->state_changed_count_, 3); | |
529 | |
530 // Makes the transport object invalid to see if the state of the audio sink | |
531 // changes accordingly. | |
532 fake_transport_->SetValid(media_endpoint_, false); | |
533 | |
534 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | |
535 EXPECT_NE(media_endpoint_, nullptr); | |
536 EXPECT_EQ(observer_->state_changed_count_, 4); | |
537 EXPECT_EQ(observer_->volume_changed_count_, 2); | |
538 } | |
539 | |
438 TEST_F(BluetoothAudioSinkChromeOSTest, | 540 TEST_F(BluetoothAudioSinkChromeOSTest, |
439 AdapterPoweredChangedDuringDisconnectedState) { | 541 AdapterPoweredChangedDuringDisconnectedState) { |
440 GetAudioSink(); | 542 GetAudioSink(); |
441 | 543 |
442 adapter_->SetPowered( | 544 adapter_->SetPowered( |
443 false, | 545 false, |
444 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, | 546 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
445 base::Unretained(this)), | 547 base::Unretained(this)), |
446 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback, | 548 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback, |
447 base::Unretained(this))); | 549 base::Unretained(this))); |
(...skipping 30 matching lines...) Expand all Loading... | |
478 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 580 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
479 base::Unretained(this))); | 581 base::Unretained(this))); |
480 | 582 |
481 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 583 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
482 EXPECT_EQ(callback_count_, 2); | 584 EXPECT_EQ(callback_count_, 2); |
483 EXPECT_EQ(error_callback_count_, 0); | 585 EXPECT_EQ(error_callback_count_, 0); |
484 EXPECT_EQ(observer_->state_changed_count_, 0); | 586 EXPECT_EQ(observer_->state_changed_count_, 0); |
485 EXPECT_EQ(observer_->volume_changed_count_, 0); | 587 EXPECT_EQ(observer_->volume_changed_count_, 0); |
486 | 588 |
487 media_endpoint_->SetConfiguration( | 589 media_endpoint_->SetConfiguration( |
488 transport_->GetTransportPath(media_endpoint_->object_path()), | 590 fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
489 properties_); | 591 properties_); |
490 | 592 |
491 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 593 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
492 EXPECT_EQ(callback_count_, 2); | 594 EXPECT_EQ(callback_count_, 2); |
493 EXPECT_EQ(error_callback_count_, 0); | 595 EXPECT_EQ(error_callback_count_, 0); |
494 EXPECT_EQ(observer_->state_changed_count_, 1); | 596 EXPECT_EQ(observer_->state_changed_count_, 1); |
495 EXPECT_EQ(observer_->volume_changed_count_, 1); | 597 EXPECT_EQ(observer_->volume_changed_count_, 1); |
496 | 598 |
497 adapter_->SetPowered( | 599 adapter_->SetPowered( |
498 false, | 600 false, |
499 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, | 601 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
500 base::Unretained(this)), | 602 base::Unretained(this)), |
501 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback, | 603 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback, |
502 base::Unretained(this))); | 604 base::Unretained(this))); |
503 GetFakeMediaEndpoint(); | 605 GetFakeMediaEndpoint(); |
504 | 606 |
505 EXPECT_TRUE(adapter_->IsPresent()); | 607 EXPECT_TRUE(adapter_->IsPresent()); |
506 EXPECT_FALSE(adapter_->IsPowered()); | 608 EXPECT_FALSE(adapter_->IsPowered()); |
507 EXPECT_NE(media_endpoint_, nullptr); | 609 EXPECT_NE(media_endpoint_, nullptr); |
508 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 610 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
509 EXPECT_EQ(callback_count_, 3); | 611 EXPECT_EQ(callback_count_, 3); |
510 EXPECT_EQ(error_callback_count_, 0); | 612 EXPECT_EQ(error_callback_count_, 0); |
511 EXPECT_EQ(observer_->state_changed_count_, 2); | 613 EXPECT_EQ(observer_->state_changed_count_, 2); |
512 EXPECT_EQ(observer_->volume_changed_count_, 2); | 614 EXPECT_EQ(observer_->volume_changed_count_, 2); |
513 } | 615 } |
514 | 616 |
515 // TODO(mcchou): Add tests on UnregisterAudioSink for STATE_PENDING and | |
516 // STATE_ACTIVE. | |
517 | |
518 TEST_F(BluetoothAudioSinkChromeOSTest, | 617 TEST_F(BluetoothAudioSinkChromeOSTest, |
519 UnregisterAudioSinkDuringDisconnectedState) { | 618 UnregisterAudioSinkDuringDisconnectedState) { |
520 GetAudioSink(); | 619 GetAudioSink(); |
521 | 620 |
522 audio_sink_->Unregister( | 621 audio_sink_->Unregister( |
523 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, | 622 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
524 base::Unretained(this)), | 623 base::Unretained(this)), |
525 base::Bind(&BluetoothAudioSinkChromeOSTest::UnregisterErrorCallback, | 624 base::Bind(&BluetoothAudioSinkChromeOSTest::UnregisterErrorCallback, |
526 base::Unretained(this))); | 625 base::Unretained(this))); |
527 | 626 |
(...skipping 12 matching lines...) Expand all Loading... | |
540 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 639 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
541 base::Unretained(this))); | 640 base::Unretained(this))); |
542 | 641 |
543 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 642 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
544 EXPECT_EQ(callback_count_, 2); | 643 EXPECT_EQ(callback_count_, 2); |
545 EXPECT_EQ(error_callback_count_, 0); | 644 EXPECT_EQ(error_callback_count_, 0); |
546 EXPECT_EQ(observer_->state_changed_count_, 0); | 645 EXPECT_EQ(observer_->state_changed_count_, 0); |
547 EXPECT_EQ(observer_->volume_changed_count_, 0); | 646 EXPECT_EQ(observer_->volume_changed_count_, 0); |
548 | 647 |
549 media_endpoint_->SetConfiguration( | 648 media_endpoint_->SetConfiguration( |
550 transport_->GetTransportPath(media_endpoint_->object_path()), | 649 fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
551 properties_); | 650 properties_); |
552 | 651 |
553 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 652 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
554 EXPECT_EQ(callback_count_, 2); | 653 EXPECT_EQ(callback_count_, 2); |
555 EXPECT_EQ(error_callback_count_, 0); | 654 EXPECT_EQ(error_callback_count_, 0); |
556 EXPECT_EQ(observer_->state_changed_count_, 1); | 655 EXPECT_EQ(observer_->state_changed_count_, 1); |
557 EXPECT_EQ(observer_->volume_changed_count_, 1); | 656 EXPECT_EQ(observer_->volume_changed_count_, 1); |
558 | 657 |
559 audio_sink_->Unregister( | 658 audio_sink_->Unregister( |
560 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, | 659 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
561 base::Unretained(this)), | 660 base::Unretained(this)), |
562 base::Bind(&BluetoothAudioSinkChromeOSTest::UnregisterErrorCallback, | 661 base::Bind(&BluetoothAudioSinkChromeOSTest::UnregisterErrorCallback, |
563 base::Unretained(this))); | 662 base::Unretained(this))); |
564 | 663 |
565 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); | 664 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
566 EXPECT_EQ(callback_count_, 3); | 665 EXPECT_EQ(callback_count_, 3); |
567 EXPECT_EQ(error_callback_count_, 0); | 666 EXPECT_EQ(error_callback_count_, 0); |
568 | 667 |
569 // The state becomes disconnted and then invalid, since the removal of | 668 // The state becomes disconnted and then invalid, since the removal of |
570 // transport object should happend before the unregistration of endpoint. | 669 // transport object should happend before the unregistration of endpoint. |
571 // State: STATE_IDLE -> STATE_DISCONNECTED -> STATE_INVALID | 670 // State: STATE_IDLE -> STATE_DISCONNECTED -> STATE_INVALID |
572 EXPECT_EQ(observer_->state_changed_count_, 3); | 671 EXPECT_EQ(observer_->state_changed_count_, 3); |
573 EXPECT_EQ(observer_->volume_changed_count_, 2); | 672 EXPECT_EQ(observer_->volume_changed_count_, 2); |
574 } | 673 } |
575 | 674 |
675 TEST_F(BluetoothAudioSinkChromeOSTest, UnregisterAudioSinkDuringActiveState) { | |
676 GetAudioSink(); | |
677 | |
678 media_endpoint_->SelectConfiguration( | |
679 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | |
680 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | |
681 base::Unretained(this))); | |
682 | |
683 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | |
684 EXPECT_EQ(callback_count_, 2); | |
685 EXPECT_EQ(error_callback_count_, 0); | |
686 EXPECT_EQ(observer_->state_changed_count_, 0); | |
687 EXPECT_EQ(observer_->volume_changed_count_, 0); | |
688 | |
689 media_endpoint_->SetConfiguration( | |
690 fake_transport_->GetTransportPath(media_endpoint_->object_path()), | |
691 properties_); | |
692 | |
693 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | |
694 EXPECT_EQ(callback_count_, 2); | |
695 EXPECT_EQ(error_callback_count_, 0); | |
696 EXPECT_EQ(observer_->state_changed_count_, 1); | |
697 EXPECT_EQ(observer_->volume_changed_count_, 1); | |
698 | |
699 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | |
700 | |
701 message_loop_.RunUntilIdle(); | |
702 | |
703 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | |
704 // and Acquire will trigger state change. Therefore, the state will be | |
705 // STATE_ACTIVE right after STATE_PENDING. | |
706 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | |
707 EXPECT_EQ(observer_->state_changed_count_, 3); | |
708 | |
709 audio_sink_->Unregister( | |
710 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, | |
711 base::Unretained(this)), | |
712 base::Bind(&BluetoothAudioSinkChromeOSTest::UnregisterErrorCallback, | |
713 base::Unretained(this))); | |
714 | |
715 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); | |
716 EXPECT_EQ(callback_count_, 3); | |
717 EXPECT_EQ(error_callback_count_, 0); | |
718 EXPECT_EQ(observer_->state_changed_count_, 5); | |
719 EXPECT_EQ(observer_->volume_changed_count_, 2); | |
720 } | |
721 | |
576 TEST_F(BluetoothAudioSinkChromeOSTest, StateChanged) { | 722 TEST_F(BluetoothAudioSinkChromeOSTest, StateChanged) { |
577 GetAudioSink(); | 723 GetAudioSink(); |
578 | 724 |
579 media_endpoint_->SelectConfiguration( | 725 media_endpoint_->SelectConfiguration( |
580 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 726 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
581 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 727 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
582 base::Unretained(this))); | 728 base::Unretained(this))); |
583 | 729 |
584 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 730 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
585 EXPECT_EQ(callback_count_, 2); | 731 EXPECT_EQ(callback_count_, 2); |
586 EXPECT_EQ(error_callback_count_, 0); | 732 EXPECT_EQ(error_callback_count_, 0); |
587 EXPECT_EQ(observer_->state_changed_count_, 0); | 733 EXPECT_EQ(observer_->state_changed_count_, 0); |
588 EXPECT_EQ(observer_->volume_changed_count_, 0); | 734 EXPECT_EQ(observer_->volume_changed_count_, 0); |
589 | 735 |
590 media_endpoint_->SetConfiguration( | 736 media_endpoint_->SetConfiguration( |
591 transport_->GetTransportPath(media_endpoint_->object_path()), | 737 fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
592 properties_); | 738 properties_); |
593 | 739 |
594 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 740 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
595 EXPECT_EQ(callback_count_, 2); | 741 EXPECT_EQ(callback_count_, 2); |
596 EXPECT_EQ(error_callback_count_, 0); | 742 EXPECT_EQ(error_callback_count_, 0); |
597 EXPECT_EQ(observer_->state_changed_count_, 1); | 743 EXPECT_EQ(observer_->state_changed_count_, 1); |
598 EXPECT_EQ(observer_->volume_changed_count_, 1); | 744 EXPECT_EQ(observer_->volume_changed_count_, 1); |
599 | 745 |
600 // Changes the current state of transport to pending. | 746 // Changes the current state of transport to pending. |
601 transport_->SetState(media_endpoint_->object_path(), "pending"); | 747 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
602 | 748 |
603 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_PENDING); | 749 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_PENDING); |
604 EXPECT_EQ(observer_->state_changed_count_, 2); | 750 EXPECT_EQ(observer_->state_changed_count_, 3); |
605 EXPECT_EQ(observer_->volume_changed_count_, 1); | 751 EXPECT_EQ(observer_->volume_changed_count_, 1); |
606 } | 752 } |
607 | 753 |
608 TEST_F(BluetoothAudioSinkChromeOSTest, VolumeChanged) { | 754 TEST_F(BluetoothAudioSinkChromeOSTest, VolumeChanged) { |
609 GetAudioSink(); | 755 GetAudioSink(); |
610 | 756 |
611 media_endpoint_->SelectConfiguration( | 757 media_endpoint_->SelectConfiguration( |
612 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 758 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
613 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 759 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
614 base::Unretained(this))); | 760 base::Unretained(this))); |
615 | 761 |
616 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | 762 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
617 EXPECT_EQ(callback_count_, 2); | 763 EXPECT_EQ(callback_count_, 2); |
618 EXPECT_EQ(error_callback_count_, 0); | 764 EXPECT_EQ(error_callback_count_, 0); |
619 EXPECT_EQ(observer_->state_changed_count_, 0); | 765 EXPECT_EQ(observer_->state_changed_count_, 0); |
620 EXPECT_EQ(observer_->volume_changed_count_, 0); | 766 EXPECT_EQ(observer_->volume_changed_count_, 0); |
621 | 767 |
622 media_endpoint_->SetConfiguration( | 768 media_endpoint_->SetConfiguration( |
623 transport_->GetTransportPath(media_endpoint_->object_path()), | 769 fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
624 properties_); | 770 properties_); |
625 | 771 |
626 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 772 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
627 EXPECT_EQ(callback_count_, 2); | 773 EXPECT_EQ(callback_count_, 2); |
628 EXPECT_EQ(error_callback_count_, 0); | 774 EXPECT_EQ(error_callback_count_, 0); |
629 EXPECT_EQ(observer_->state_changed_count_, 1); | 775 EXPECT_EQ(observer_->state_changed_count_, 1); |
630 EXPECT_EQ(observer_->volume_changed_count_, 1); | 776 EXPECT_EQ(observer_->volume_changed_count_, 1); |
631 | 777 |
632 // |kTransportVolume| is the initial volume of the transport, and this | 778 // |kTransportVolume| is the initial volume of the transport, and this |
633 // value is propagated to the audio sink via SetConfiguration. | 779 // value is propagated to the audio sink via SetConfiguration. |
634 EXPECT_EQ(audio_sink_->GetVolume(), | 780 EXPECT_EQ(audio_sink_->GetVolume(), |
635 FakeBluetoothMediaTransportClient::kTransportVolume); | 781 FakeBluetoothMediaTransportClient::kTransportVolume); |
636 | 782 |
637 // Changes volume to a valid level. | 783 // Changes volume to a valid level. |
638 transport_->SetVolume(media_endpoint_->object_path(), 100); | 784 fake_transport_->SetVolume(media_endpoint_->object_path(), 100); |
639 | 785 |
640 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 786 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
641 EXPECT_EQ(observer_->state_changed_count_, 1); | 787 EXPECT_EQ(observer_->state_changed_count_, 1); |
642 EXPECT_EQ(observer_->volume_changed_count_, 2); | 788 EXPECT_EQ(observer_->volume_changed_count_, 2); |
643 EXPECT_EQ(audio_sink_->GetVolume(), 100); | 789 EXPECT_EQ(audio_sink_->GetVolume(), 100); |
644 | 790 |
645 // Changes volume to an invalid level. | 791 // Changes volume to an invalid level. |
646 transport_->SetVolume(media_endpoint_->object_path(), 200); | 792 fake_transport_->SetVolume(media_endpoint_->object_path(), 200); |
647 | 793 |
648 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 794 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
649 EXPECT_EQ(observer_->state_changed_count_, 1); | 795 EXPECT_EQ(observer_->state_changed_count_, 1); |
650 EXPECT_EQ(observer_->volume_changed_count_, 3); | 796 EXPECT_EQ(observer_->volume_changed_count_, 3); |
651 EXPECT_EQ(audio_sink_->GetVolume(), BluetoothAudioSink::kInvalidVolume); | 797 EXPECT_EQ(audio_sink_->GetVolume(), BluetoothAudioSink::kInvalidVolume); |
652 } | 798 } |
653 | 799 |
800 TEST_F(BluetoothAudioSinkChromeOSTest, AcquireFD) { | |
801 GetAudioSink(); | |
802 | |
803 media_endpoint_->SelectConfiguration( | |
804 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | |
805 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | |
806 base::Unretained(this))); | |
807 | |
808 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | |
809 EXPECT_EQ(callback_count_, 2); | |
810 EXPECT_EQ(error_callback_count_, 0); | |
811 EXPECT_EQ(observer_->state_changed_count_, 0); | |
812 EXPECT_EQ(observer_->volume_changed_count_, 0); | |
813 | |
814 media_endpoint_->SetConfiguration( | |
815 fake_transport_->GetTransportPath(media_endpoint_->object_path()), | |
816 properties_); | |
817 | |
818 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | |
819 EXPECT_EQ(callback_count_, 2); | |
820 EXPECT_EQ(error_callback_count_, 0); | |
821 EXPECT_EQ(observer_->state_changed_count_, 1); | |
822 EXPECT_EQ(observer_->volume_changed_count_, 1); | |
823 | |
824 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | |
825 | |
826 std::vector<char> data_one({0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
827 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}); | |
828 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | |
829 | |
830 message_loop_.RunUntilIdle(); | |
831 | |
832 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | |
833 // and Acquire will trigger state change. Therefore, the state will be | |
834 // STATE_ACTIVE right after STATE_PENDING. | |
835 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | |
836 EXPECT_EQ(observer_->state_changed_count_, 3); | |
837 EXPECT_EQ(observer_->total_read_, data_one.size()); | |
armansito
2015/03/12 03:42:55
It would be cool if you could also check that the
Miao
2015/03/12 22:33:32
Added!
| |
838 } | |
839 | |
840 // Tests the case where the remote device pauses and resume audio streaming. | |
841 TEST_F(BluetoothAudioSinkChromeOSTest, PauseAndResume) { | |
842 GetAudioSink(); | |
843 | |
844 media_endpoint_->SelectConfiguration( | |
845 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | |
846 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | |
847 base::Unretained(this))); | |
848 | |
849 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | |
850 EXPECT_EQ(callback_count_, 2); | |
851 EXPECT_EQ(error_callback_count_, 0); | |
852 EXPECT_EQ(observer_->state_changed_count_, 0); | |
853 EXPECT_EQ(observer_->volume_changed_count_, 0); | |
854 | |
855 media_endpoint_->SetConfiguration( | |
856 fake_transport_->GetTransportPath(media_endpoint_->object_path()), | |
857 properties_); | |
858 | |
859 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | |
860 EXPECT_EQ(callback_count_, 2); | |
861 EXPECT_EQ(error_callback_count_, 0); | |
862 EXPECT_EQ(observer_->state_changed_count_, 1); | |
863 EXPECT_EQ(observer_->volume_changed_count_, 1); | |
864 | |
865 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | |
866 | |
867 std::vector<char> data_one(16, 0x12); | |
868 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | |
869 | |
870 message_loop_.RunUntilIdle(); | |
871 | |
872 EXPECT_EQ(observer_->state_changed_count_, 3); | |
873 EXPECT_EQ(observer_->total_read_, data_one.size()); | |
874 | |
875 // Simulates the situation where the remote device pauses and resume audio | |
876 // streaming. | |
877 fake_transport_->SetState(media_endpoint_->object_path(), "idle"); | |
878 | |
879 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | |
880 EXPECT_EQ(observer_->state_changed_count_, 4); | |
881 | |
882 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | |
883 | |
884 std::vector<char> data_two(8, 0x10); | |
885 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); | |
886 | |
887 message_loop_.RunUntilIdle(); | |
888 | |
889 EXPECT_EQ(observer_->state_changed_count_, 6); | |
890 EXPECT_EQ(observer_->total_read_, data_two.size()); | |
891 } | |
892 | |
893 TEST_F(BluetoothAudioSinkChromeOSTest, ContinuouslyStreaming) { | |
894 GetAudioSink(); | |
895 | |
896 media_endpoint_->SelectConfiguration( | |
897 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | |
898 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | |
899 base::Unretained(this))); | |
900 | |
901 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); | |
902 EXPECT_EQ(callback_count_, 2); | |
903 EXPECT_EQ(error_callback_count_, 0); | |
904 EXPECT_EQ(observer_->state_changed_count_, 0); | |
905 EXPECT_EQ(observer_->volume_changed_count_, 0); | |
906 | |
907 media_endpoint_->SetConfiguration( | |
908 fake_transport_->GetTransportPath(media_endpoint_->object_path()), | |
909 properties_); | |
910 | |
911 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | |
912 EXPECT_EQ(callback_count_, 2); | |
913 EXPECT_EQ(error_callback_count_, 0); | |
914 EXPECT_EQ(observer_->state_changed_count_, 1); | |
915 EXPECT_EQ(observer_->volume_changed_count_, 1); | |
916 | |
917 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | |
918 | |
919 std::vector<char> data_one(16, 0x12); | |
920 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | |
921 | |
922 message_loop_.RunUntilIdle(); | |
923 | |
924 EXPECT_EQ(observer_->state_changed_count_, 3); | |
925 EXPECT_EQ(observer_->total_read_, data_one.size()); | |
926 | |
927 std::vector<char> data_two(8, 0x10); | |
928 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); | |
929 | |
930 message_loop_.RunUntilIdle(); | |
931 | |
932 EXPECT_EQ(observer_->state_changed_count_, 3); | |
933 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); | |
934 } | |
935 | |
654 } // namespace chromeos | 936 } // namespace chromeos |
OLD | NEW |