| 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..b415e73d1b6707c2a9de47b183716f43af5e957e 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,19 @@ class TestAudioSinkObserver : public BluetoothAudioSink::Observer {
|
| ++volume_changed_count_;
|
| }
|
|
|
| + void BluetoothAudioSinkDataAvailable(BluetoothAudioSink* audio_sink,
|
| + char* data,
|
| + size_t size) override {
|
| + total_read_ += size;
|
| + data_.clear();
|
| + data_.insert(data_.begin(), data, data + size);
|
| + }
|
| +
|
| int state_changed_count_;
|
| int volume_changed_count_;
|
| + int data_available_count_;
|
| + size_t total_read_;
|
| + std::vector<char> data_;
|
| BluetoothAudioSink::State state_;
|
|
|
| private:
|
| @@ -68,6 +83,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 +101,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 +109,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 +187,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 +226,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 +310,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 +338,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 +348,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 +356,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 +384,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 +395,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 +409,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 +477,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 +488,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 +496,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 +590,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 +617,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 +649,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 +675,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 +737,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 +747,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 +769,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 +784,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 +792,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 +800,144 @@ 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(16, 0x12);
|
| + 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());
|
| + EXPECT_EQ(observer_->data_, data_one);
|
| +}
|
| +
|
| +// 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_->data_, data_one);
|
| + 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_->data_, data_two);
|
| + 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_->data_, data_one);
|
| + 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_->data_, data_two);
|
| + EXPECT_EQ(observer_->state_changed_count_, 3);
|
| + EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size());
|
| +}
|
| +
|
| } // namespace chromeos
|
|
|