Index: device/bluetooth/bluetooth_audio_sink_chromeos_unittest.cc |
diff --git a/device/bluetooth/bluetooth_audio_sink_chromeos_unittest.cc b/device/bluetooth/bluetooth_audio_sink_chromeos_unittest.cc |
index ee6cf2ab8c1197b95468cec0fad9d883a36c7e41..1f0424a24eba9c8b9ee880fa9175409a30ffe806 100644 |
--- a/device/bluetooth/bluetooth_audio_sink_chromeos_unittest.cc |
+++ b/device/bluetooth/bluetooth_audio_sink_chromeos_unittest.cc |
@@ -34,6 +34,7 @@ class TestAudioSinkObserver : public BluetoothAudioSink::Observer { |
explicit TestAudioSinkObserver(scoped_refptr<BluetoothAudioSink> audio_sink) |
: state_changed_count_(0), |
volume_changed_count_(0), |
+ total_read_(0), |
state_(audio_sink->GetState()), |
audio_sink_(audio_sink) { |
audio_sink_->AddObserver(this); |
@@ -44,6 +45,9 @@ class TestAudioSinkObserver : public BluetoothAudioSink::Observer { |
void BluetoothAudioSinkStateChanged( |
BluetoothAudioSink* audio_sink, |
BluetoothAudioSink::State state) override { |
+ if (state == BluetoothAudioSink::STATE_IDLE) |
+ total_read_ = 0; |
+ |
++state_changed_count_; |
} |
@@ -52,8 +56,16 @@ class TestAudioSinkObserver : public BluetoothAudioSink::Observer { |
++volume_changed_count_; |
} |
+ void BluetoothAudioSinkDataAvailable(BluetoothAudioSink* audio_sink, |
+ char* data, |
+ size_t size) override { |
+ total_read_ += size; |
+ } |
+ |
int state_changed_count_; |
int volume_changed_count_; |
+ int data_available_count_; |
+ size_t total_read_; |
BluetoothAudioSink::State state_; |
private: |
@@ -68,6 +80,11 @@ class BluetoothAudioSinkChromeOSTest : public testing::Test { |
callback_count_ = 0; |
error_callback_count_ = 0; |
+ fake_media_ = static_cast<FakeBluetoothMediaClient*>( |
+ DBusThreadManager::Get()->GetBluetoothMediaClient()); |
+ fake_transport_ = static_cast<FakeBluetoothMediaTransportClient*>( |
+ DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); |
+ |
// Initiates Delegate::TransportProperties with default values. |
properties_.device = |
ObjectPath(FakeBluetoothMediaTransportClient::kTransportDevicePath); |
@@ -81,11 +98,6 @@ class BluetoothAudioSinkChromeOSTest : public testing::Test { |
properties_.volume.reset( |
new uint16_t(FakeBluetoothMediaTransportClient::kTransportVolume)); |
- media_ = static_cast<FakeBluetoothMediaClient*>( |
- DBusThreadManager::Get()->GetBluetoothMediaClient()); |
- transport_ = static_cast<FakeBluetoothMediaTransportClient*>( |
- DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); |
- |
GetAdapter(); |
} |
@@ -94,7 +106,7 @@ class BluetoothAudioSinkChromeOSTest : public testing::Test { |
error_callback_count_ = 0; |
observer_.reset(); |
- media_->SetVisible(true); |
+ fake_media_->SetVisible(true); |
// The adapter should outlive audio sink. |
audio_sink_ = nullptr; |
@@ -172,7 +184,7 @@ class BluetoothAudioSinkChromeOSTest : public testing::Test { |
GetFakeMediaEndpoint(); |
ASSERT_NE(media_endpoint_, nullptr); |
- media_->SetEndpointRegistered(media_endpoint_, true); |
+ fake_media_->SetEndpointRegistered(media_endpoint_, true); |
ASSERT_NE(audio_sink_.get(), nullptr); |
ASSERT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
@@ -211,10 +223,10 @@ class BluetoothAudioSinkChromeOSTest : public testing::Test { |
int callback_count_; |
int error_callback_count_; |
- base::MessageLoop message_loop_; |
+ base::MessageLoopForIO message_loop_; |
- FakeBluetoothMediaClient* media_; |
- FakeBluetoothMediaTransportClient* transport_; |
+ FakeBluetoothMediaClient* fake_media_; |
+ FakeBluetoothMediaTransportClient* fake_transport_; |
FakeBluetoothMediaEndpointServiceProvider* media_endpoint_; |
scoped_ptr<TestAudioSinkObserver> observer_; |
scoped_refptr<BluetoothAdapter> adapter_; |
@@ -295,7 +307,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, SetConfiguration) { |
// |audio_sink_| with a fake transport path and a |
// Delegate::TransportProperties structure. |
media_endpoint_->SetConfiguration( |
- transport_->GetTransportPath(media_endpoint_->object_path()), |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
properties_); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
@@ -323,7 +335,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, SetConfigurationWithUnexpectedState) { |
properties_.state = "pending"; |
media_endpoint_->SetConfiguration( |
- transport_->GetTransportPath(media_endpoint_->object_path()), |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
properties_); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
@@ -333,8 +345,6 @@ TEST_F(BluetoothAudioSinkChromeOSTest, SetConfigurationWithUnexpectedState) { |
EXPECT_EQ(observer_->volume_changed_count_, 0); |
} |
-// TODO(mcchou): Adds test on media-removed events for STATE_PENDING and |
-// STATE_ACTIVE. |
// Checks if the observer is notified on media-removed event when the state of |
// |audio_sink_| is STATE_DISCONNECTED. Once the media object is removed, the |
// audio sink is no longer valid. |
@@ -343,7 +353,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringDisconnectedState) { |
// Gets the media object and makes it invisible to see if the state of the |
// audio sink changes accordingly. |
- media_->SetVisible(false); |
+ fake_media_->SetVisible(false); |
GetFakeMediaEndpoint(); |
@@ -371,7 +381,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringIdleState) { |
EXPECT_EQ(observer_->volume_changed_count_, 0); |
media_endpoint_->SetConfiguration( |
- transport_->GetTransportPath(media_endpoint_->object_path()), |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
properties_); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
@@ -382,7 +392,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringIdleState) { |
// Gets the media object and makes it invisible to see if the state of the |
// audio sink changes accordingly. |
- media_->SetVisible(false); |
+ fake_media_->SetVisible(false); |
GetFakeMediaEndpoint(); |
@@ -396,8 +406,56 @@ TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringIdleState) { |
EXPECT_EQ(observer_->volume_changed_count_, 2); |
} |
-// TODO(mcchou): Add tests on transport-removed event for STATE_PENDING and |
-// STATE_ACTIVE. |
+TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringActiveState) { |
+ GetAudioSink(); |
+ |
+ media_endpoint_->SelectConfiguration( |
+ std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
+ base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 0); |
+ EXPECT_EQ(observer_->volume_changed_count_, 0); |
+ |
+ media_endpoint_->SetConfiguration( |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
+ properties_); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 1); |
+ EXPECT_EQ(observer_->volume_changed_count_, 1); |
+ |
+ fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
+ // and Acquire will trigger state change. Therefore, the state will be |
+ // STATE_ACTIVE right after STATE_PENDING. |
+ // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
+ EXPECT_EQ(observer_->state_changed_count_, 3); |
+ |
+ // Gets the media object and makes it invisible to see if the state of the |
+ // audio sink changes accordingly. |
+ fake_media_->SetVisible(false); |
+ |
+ GetFakeMediaEndpoint(); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
+ EXPECT_EQ(media_endpoint_, nullptr); |
+ |
+ // The state becomes disconnted and then invalid, since the removal of |
+ // transport object should happend before media becomes invisible. |
+ // State: STATE_ACTIVE -> STATE_DISCONNECTED -> STATE_INVALID |
+ EXPECT_EQ(observer_->state_changed_count_, 5); |
+ EXPECT_EQ(observer_->volume_changed_count_, 2); |
+} |
+ |
// Checks if the observer is notified on transport-removed event when the state |
// of |audio_sink_| is STATE_IDEL. Once the media transport object is removed, |
// the audio sink is disconnected. |
@@ -416,7 +474,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringIdleState) { |
EXPECT_EQ(observer_->volume_changed_count_, 0); |
media_endpoint_->SetConfiguration( |
- transport_->GetTransportPath(media_endpoint_->object_path()), |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
properties_); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
@@ -427,7 +485,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringIdleState) { |
// Makes the transport object invalid to see if the state of the audio sink |
// changes accordingly. |
- transport_->SetValid(media_endpoint_, false); |
+ fake_transport_->SetValid(media_endpoint_, false); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
EXPECT_NE(media_endpoint_, nullptr); |
@@ -435,6 +493,50 @@ TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringIdleState) { |
EXPECT_EQ(observer_->volume_changed_count_, 2); |
} |
+TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringActiveState) { |
+ GetAudioSink(); |
+ |
+ media_endpoint_->SelectConfiguration( |
+ std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
+ base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 0); |
+ EXPECT_EQ(observer_->volume_changed_count_, 0); |
+ |
+ media_endpoint_->SetConfiguration( |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
+ properties_); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 1); |
+ EXPECT_EQ(observer_->volume_changed_count_, 1); |
+ |
+ fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
+ // and Acquire will trigger state change. Therefore, the state will be |
+ // STATE_ACTIVE right after STATE_PENDING. |
+ // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
+ EXPECT_EQ(observer_->state_changed_count_, 3); |
+ |
+ // Makes the transport object invalid to see if the state of the audio sink |
+ // changes accordingly. |
+ fake_transport_->SetValid(media_endpoint_, false); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
+ EXPECT_NE(media_endpoint_, nullptr); |
+ EXPECT_EQ(observer_->state_changed_count_, 4); |
+ EXPECT_EQ(observer_->volume_changed_count_, 2); |
+} |
+ |
TEST_F(BluetoothAudioSinkChromeOSTest, |
AdapterPoweredChangedDuringDisconnectedState) { |
GetAudioSink(); |
@@ -485,7 +587,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, AdapterPoweredChangedDuringIdleState) { |
EXPECT_EQ(observer_->volume_changed_count_, 0); |
media_endpoint_->SetConfiguration( |
- transport_->GetTransportPath(media_endpoint_->object_path()), |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
properties_); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
@@ -512,9 +614,6 @@ TEST_F(BluetoothAudioSinkChromeOSTest, AdapterPoweredChangedDuringIdleState) { |
EXPECT_EQ(observer_->volume_changed_count_, 2); |
} |
-// TODO(mcchou): Add tests on UnregisterAudioSink for STATE_PENDING and |
-// STATE_ACTIVE. |
- |
TEST_F(BluetoothAudioSinkChromeOSTest, |
UnregisterAudioSinkDuringDisconnectedState) { |
GetAudioSink(); |
@@ -547,7 +646,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, UnregisterAudioSinkDuringIdleState) { |
EXPECT_EQ(observer_->volume_changed_count_, 0); |
media_endpoint_->SetConfiguration( |
- transport_->GetTransportPath(media_endpoint_->object_path()), |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
properties_); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
@@ -573,6 +672,53 @@ TEST_F(BluetoothAudioSinkChromeOSTest, UnregisterAudioSinkDuringIdleState) { |
EXPECT_EQ(observer_->volume_changed_count_, 2); |
} |
+TEST_F(BluetoothAudioSinkChromeOSTest, UnregisterAudioSinkDuringActiveState) { |
+ GetAudioSink(); |
+ |
+ media_endpoint_->SelectConfiguration( |
+ std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
+ base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 0); |
+ EXPECT_EQ(observer_->volume_changed_count_, 0); |
+ |
+ media_endpoint_->SetConfiguration( |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
+ properties_); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 1); |
+ EXPECT_EQ(observer_->volume_changed_count_, 1); |
+ |
+ fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
+ // and Acquire will trigger state change. Therefore, the state will be |
+ // STATE_ACTIVE right after STATE_PENDING. |
+ // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
+ EXPECT_EQ(observer_->state_changed_count_, 3); |
+ |
+ audio_sink_->Unregister( |
+ base::Bind(&BluetoothAudioSinkChromeOSTest::Callback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothAudioSinkChromeOSTest::UnregisterErrorCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); |
+ EXPECT_EQ(callback_count_, 3); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 5); |
+ EXPECT_EQ(observer_->volume_changed_count_, 2); |
+} |
+ |
TEST_F(BluetoothAudioSinkChromeOSTest, StateChanged) { |
GetAudioSink(); |
@@ -588,7 +734,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, StateChanged) { |
EXPECT_EQ(observer_->volume_changed_count_, 0); |
media_endpoint_->SetConfiguration( |
- transport_->GetTransportPath(media_endpoint_->object_path()), |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
properties_); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
@@ -598,10 +744,10 @@ TEST_F(BluetoothAudioSinkChromeOSTest, StateChanged) { |
EXPECT_EQ(observer_->volume_changed_count_, 1); |
// Changes the current state of transport to pending. |
- transport_->SetState(media_endpoint_->object_path(), "pending"); |
+ fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_PENDING); |
- EXPECT_EQ(observer_->state_changed_count_, 2); |
+ EXPECT_EQ(observer_->state_changed_count_, 3); |
EXPECT_EQ(observer_->volume_changed_count_, 1); |
} |
@@ -620,7 +766,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, VolumeChanged) { |
EXPECT_EQ(observer_->volume_changed_count_, 0); |
media_endpoint_->SetConfiguration( |
- transport_->GetTransportPath(media_endpoint_->object_path()), |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
properties_); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
@@ -635,7 +781,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, VolumeChanged) { |
FakeBluetoothMediaTransportClient::kTransportVolume); |
// Changes volume to a valid level. |
- transport_->SetVolume(media_endpoint_->object_path(), 100); |
+ fake_transport_->SetVolume(media_endpoint_->object_path(), 100); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
EXPECT_EQ(observer_->state_changed_count_, 1); |
@@ -643,7 +789,7 @@ TEST_F(BluetoothAudioSinkChromeOSTest, VolumeChanged) { |
EXPECT_EQ(audio_sink_->GetVolume(), 100); |
// Changes volume to an invalid level. |
- transport_->SetVolume(media_endpoint_->object_path(), 200); |
+ fake_transport_->SetVolume(media_endpoint_->object_path(), 200); |
EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
EXPECT_EQ(observer_->state_changed_count_, 1); |
@@ -651,4 +797,140 @@ TEST_F(BluetoothAudioSinkChromeOSTest, VolumeChanged) { |
EXPECT_EQ(audio_sink_->GetVolume(), BluetoothAudioSink::kInvalidVolume); |
} |
+TEST_F(BluetoothAudioSinkChromeOSTest, AcquireFD) { |
+ GetAudioSink(); |
+ |
+ media_endpoint_->SelectConfiguration( |
+ std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
+ base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 0); |
+ EXPECT_EQ(observer_->volume_changed_count_, 0); |
+ |
+ media_endpoint_->SetConfiguration( |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
+ properties_); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 1); |
+ EXPECT_EQ(observer_->volume_changed_count_, 1); |
+ |
+ fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
+ |
+ std::vector<char> data_one({0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}); |
+ fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
+ // and Acquire will trigger state change. Therefore, the state will be |
+ // STATE_ACTIVE right after STATE_PENDING. |
+ // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
+ EXPECT_EQ(observer_->state_changed_count_, 3); |
+ 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!
|
+} |
+ |
+// Tests the case where the remote device pauses and resume audio streaming. |
+TEST_F(BluetoothAudioSinkChromeOSTest, PauseAndResume) { |
+ GetAudioSink(); |
+ |
+ media_endpoint_->SelectConfiguration( |
+ std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
+ base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 0); |
+ EXPECT_EQ(observer_->volume_changed_count_, 0); |
+ |
+ media_endpoint_->SetConfiguration( |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
+ properties_); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 1); |
+ EXPECT_EQ(observer_->volume_changed_count_, 1); |
+ |
+ fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
+ |
+ std::vector<char> data_one(16, 0x12); |
+ fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ EXPECT_EQ(observer_->state_changed_count_, 3); |
+ EXPECT_EQ(observer_->total_read_, data_one.size()); |
+ |
+ // Simulates the situation where the remote device pauses and resume audio |
+ // streaming. |
+ fake_transport_->SetState(media_endpoint_->object_path(), "idle"); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
+ EXPECT_EQ(observer_->state_changed_count_, 4); |
+ |
+ fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
+ |
+ std::vector<char> data_two(8, 0x10); |
+ fake_transport_->WriteData(media_endpoint_->object_path(), data_two); |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ EXPECT_EQ(observer_->state_changed_count_, 6); |
+ EXPECT_EQ(observer_->total_read_, data_two.size()); |
+} |
+ |
+TEST_F(BluetoothAudioSinkChromeOSTest, ContinuouslyStreaming) { |
+ GetAudioSink(); |
+ |
+ media_endpoint_->SelectConfiguration( |
+ std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
+ base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 0); |
+ EXPECT_EQ(observer_->volume_changed_count_, 0); |
+ |
+ media_endpoint_->SetConfiguration( |
+ fake_transport_->GetTransportPath(media_endpoint_->object_path()), |
+ properties_); |
+ |
+ EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
+ EXPECT_EQ(callback_count_, 2); |
+ EXPECT_EQ(error_callback_count_, 0); |
+ EXPECT_EQ(observer_->state_changed_count_, 1); |
+ EXPECT_EQ(observer_->volume_changed_count_, 1); |
+ |
+ fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
+ |
+ std::vector<char> data_one(16, 0x12); |
+ fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ EXPECT_EQ(observer_->state_changed_count_, 3); |
+ EXPECT_EQ(observer_->total_read_, data_one.size()); |
+ |
+ std::vector<char> data_two(8, 0x10); |
+ fake_transport_->WriteData(media_endpoint_->object_path(), data_two); |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ EXPECT_EQ(observer_->state_changed_count_, 3); |
+ EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); |
+} |
+ |
} // namespace chromeos |