| 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" |
| 11 #include "dbus/object_path.h" | 11 #include "dbus/object_path.h" |
| 12 #include "device/bluetooth/bluetooth_adapter.h" | 12 #include "device/bluetooth/bluetooth_adapter.h" |
| 13 #include "device/bluetooth/bluetooth_adapter_factory.h" | 13 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 14 #include "device/bluetooth/bluetooth_audio_sink.h" | 14 #include "device/bluetooth/bluetooth_audio_sink.h" |
| 15 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h" | 15 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h" |
| 16 #include "device/bluetooth/dbus/bluetooth_media_client.h" | 16 #include "device/bluetooth/dbus/bluetooth_media_client.h" |
| 17 #include "device/bluetooth/dbus/bluetooth_media_endpoint_service_provider.h" | 17 #include "device/bluetooth/dbus/bluetooth_media_endpoint_service_provider.h" |
| 18 #include "device/bluetooth/dbus/bluetooth_media_transport_client.h" | 18 #include "device/bluetooth/dbus/bluetooth_media_transport_client.h" |
| 19 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 19 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 20 #include "device/bluetooth/dbus/fake_bluetooth_media_client.h" | 20 #include "device/bluetooth/dbus/fake_bluetooth_media_client.h" |
| 21 #include "device/bluetooth/dbus/fake_bluetooth_media_endpoint_service_provider.h
" | 21 #include "device/bluetooth/dbus/fake_bluetooth_media_endpoint_service_provider.h
" |
| 22 #include "device/bluetooth/dbus/fake_bluetooth_media_transport_client.h" | 22 #include "device/bluetooth/dbus/fake_bluetooth_media_transport_client.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 using bluez::FakeBluetoothMediaTransportClient; |
| 25 using dbus::ObjectPath; | 26 using dbus::ObjectPath; |
| 26 using device::BluetoothAdapter; | 27 using device::BluetoothAdapter; |
| 27 using device::BluetoothAdapterFactory; | 28 using device::BluetoothAdapterFactory; |
| 28 using device::BluetoothAudioSink; | 29 using device::BluetoothAudioSink; |
| 29 | 30 |
| 30 namespace chromeos { | 31 namespace chromeos { |
| 31 | 32 |
| 32 class TestAudioSinkObserver : public BluetoothAudioSink::Observer { | 33 class TestAudioSinkObserver : public BluetoothAudioSink::Observer { |
| 33 public: | 34 public: |
| 34 explicit TestAudioSinkObserver(scoped_refptr<BluetoothAudioSink> audio_sink) | 35 explicit TestAudioSinkObserver(scoped_refptr<BluetoothAudioSink> audio_sink) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 class BluetoothAudioSinkChromeOSTest : public testing::Test { | 82 class BluetoothAudioSinkChromeOSTest : public testing::Test { |
| 82 public: | 83 public: |
| 83 void SetUp() override { | 84 void SetUp() override { |
| 84 bluez::BluezDBusManager::Initialize(NULL, true); | 85 bluez::BluezDBusManager::Initialize(NULL, true); |
| 85 | 86 |
| 86 callback_count_ = 0; | 87 callback_count_ = 0; |
| 87 error_callback_count_ = 0; | 88 error_callback_count_ = 0; |
| 88 | 89 |
| 89 fake_media_ = static_cast<bluez::FakeBluetoothMediaClient*>( | 90 fake_media_ = static_cast<bluez::FakeBluetoothMediaClient*>( |
| 90 bluez::BluezDBusManager::Get()->GetBluetoothMediaClient()); | 91 bluez::BluezDBusManager::Get()->GetBluetoothMediaClient()); |
| 91 fake_transport_ = static_cast<bluez::FakeBluetoothMediaTransportClient*>( | 92 fake_transport_ = static_cast<FakeBluetoothMediaTransportClient*>( |
| 92 bluez::BluezDBusManager::Get()->GetBluetoothMediaTransportClient()); | 93 bluez::BluezDBusManager::Get()->GetBluetoothMediaTransportClient()); |
| 93 | 94 |
| 94 // Initiates Delegate::TransportProperties with default values. | 95 // Initiates Delegate::TransportProperties with default values. |
| 95 properties_.device = ObjectPath( | 96 properties_.device = |
| 96 bluez::FakeBluetoothMediaTransportClient::kTransportDevicePath); | 97 ObjectPath(FakeBluetoothMediaTransportClient::kTransportDevicePath); |
| 97 properties_.uuid = bluez::BluetoothMediaClient::kBluetoothAudioSinkUUID; | 98 properties_.uuid = bluez::BluetoothMediaClient::kBluetoothAudioSinkUUID; |
| 98 properties_.codec = | 99 properties_.codec = FakeBluetoothMediaTransportClient::kTransportCodec; |
| 99 bluez::FakeBluetoothMediaTransportClient::kTransportCodec; | 100 properties_.configuration = std::vector<uint8_t>( |
| 100 properties_.configuration = | 101 FakeBluetoothMediaTransportClient::kTransportConfiguration, |
| 101 bluez::FakeBluetoothMediaTransportClient::kTransportConfiguration; | 102 FakeBluetoothMediaTransportClient::kTransportConfiguration + |
| 103 FakeBluetoothMediaTransportClient::kTransportConfigurationLength); |
| 102 properties_.state = bluez::BluetoothMediaTransportClient::kStateIdle; | 104 properties_.state = bluez::BluetoothMediaTransportClient::kStateIdle; |
| 103 properties_.delay.reset(new uint16_t( | 105 properties_.delay.reset( |
| 104 bluez::FakeBluetoothMediaTransportClient::kTransportDelay)); | 106 new uint16_t(FakeBluetoothMediaTransportClient::kTransportDelay)); |
| 105 properties_.volume.reset(new uint16_t( | 107 properties_.volume.reset( |
| 106 bluez::FakeBluetoothMediaTransportClient::kTransportVolume)); | 108 new uint16_t(FakeBluetoothMediaTransportClient::kTransportVolume)); |
| 107 | 109 |
| 108 GetAdapter(); | 110 GetAdapter(); |
| 109 } | 111 } |
| 110 | 112 |
| 111 void TearDown() override { | 113 void TearDown() override { |
| 112 callback_count_ = 0; | 114 callback_count_ = 0; |
| 113 error_callback_count_ = 0; | 115 error_callback_count_ = 0; |
| 114 observer_.reset(); | 116 observer_.reset(); |
| 115 | 117 |
| 116 fake_media_->SetVisible(true); | 118 fake_media_->SetVisible(true); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 ++error_callback_count_; | 229 ++error_callback_count_; |
| 228 } | 230 } |
| 229 | 231 |
| 230 protected: | 232 protected: |
| 231 int callback_count_; | 233 int callback_count_; |
| 232 int error_callback_count_; | 234 int error_callback_count_; |
| 233 | 235 |
| 234 base::MessageLoopForIO message_loop_; | 236 base::MessageLoopForIO message_loop_; |
| 235 | 237 |
| 236 bluez::FakeBluetoothMediaClient* fake_media_; | 238 bluez::FakeBluetoothMediaClient* fake_media_; |
| 237 bluez::FakeBluetoothMediaTransportClient* fake_transport_; | 239 FakeBluetoothMediaTransportClient* fake_transport_; |
| 238 bluez::FakeBluetoothMediaEndpointServiceProvider* media_endpoint_; | 240 bluez::FakeBluetoothMediaEndpointServiceProvider* media_endpoint_; |
| 239 scoped_ptr<TestAudioSinkObserver> observer_; | 241 scoped_ptr<TestAudioSinkObserver> observer_; |
| 240 scoped_refptr<BluetoothAdapter> adapter_; | 242 scoped_refptr<BluetoothAdapter> adapter_; |
| 241 scoped_refptr<BluetoothAudioSink> audio_sink_; | 243 scoped_refptr<BluetoothAudioSink> audio_sink_; |
| 242 | 244 |
| 243 // The default property set used while calling SetConfiguration on a media | 245 // The default property set used while calling SetConfiguration on a media |
| 244 // endpoint object. | 246 // endpoint object. |
| 245 bluez::BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties | 247 bluez::BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties |
| 246 properties_; | 248 properties_; |
| 247 }; | 249 }; |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 781 |
| 780 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 782 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 781 EXPECT_EQ(callback_count_, 2); | 783 EXPECT_EQ(callback_count_, 2); |
| 782 EXPECT_EQ(error_callback_count_, 0); | 784 EXPECT_EQ(error_callback_count_, 0); |
| 783 EXPECT_EQ(observer_->state_changed_count_, 1); | 785 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 784 EXPECT_EQ(observer_->volume_changed_count_, 1); | 786 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 785 | 787 |
| 786 // |kTransportVolume| is the initial volume of the transport, and this | 788 // |kTransportVolume| is the initial volume of the transport, and this |
| 787 // value is propagated to the audio sink via SetConfiguration. | 789 // value is propagated to the audio sink via SetConfiguration. |
| 788 EXPECT_EQ(audio_sink_->GetVolume(), | 790 EXPECT_EQ(audio_sink_->GetVolume(), |
| 789 bluez::FakeBluetoothMediaTransportClient::kTransportVolume); | 791 FakeBluetoothMediaTransportClient::kTransportVolume); |
| 790 | 792 |
| 791 // Changes volume to a valid level. | 793 // Changes volume to a valid level. |
| 792 fake_transport_->SetVolume(media_endpoint_->object_path(), 100); | 794 fake_transport_->SetVolume(media_endpoint_->object_path(), 100); |
| 793 | 795 |
| 794 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 796 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 795 EXPECT_EQ(observer_->state_changed_count_, 1); | 797 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 796 EXPECT_EQ(observer_->volume_changed_count_, 2); | 798 EXPECT_EQ(observer_->volume_changed_count_, 2); |
| 797 EXPECT_EQ(audio_sink_->GetVolume(), 100); | 799 EXPECT_EQ(audio_sink_->GetVolume(), 100); |
| 798 | 800 |
| 799 // Changes volume to an invalid level. | 801 // Changes volume to an invalid level. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 message_loop_.RunUntilIdle(); | 839 message_loop_.RunUntilIdle(); |
| 838 | 840 |
| 839 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | 841 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
| 840 // and Acquire will trigger state change. Therefore, the state will be | 842 // and Acquire will trigger state change. Therefore, the state will be |
| 841 // STATE_ACTIVE right after STATE_PENDING. | 843 // STATE_ACTIVE right after STATE_PENDING. |
| 842 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | 844 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
| 843 EXPECT_EQ(observer_->state_changed_count_, 3); | 845 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 844 EXPECT_EQ(observer_->total_read_, data_one.size()); | 846 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 845 EXPECT_EQ(observer_->data_, data_one); | 847 EXPECT_EQ(observer_->data_, data_one); |
| 846 EXPECT_EQ(observer_->read_mtu_, | 848 EXPECT_EQ(observer_->read_mtu_, |
| 847 bluez::FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 849 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 848 } | 850 } |
| 849 | 851 |
| 850 // Tests the case where the remote device pauses and resume audio streaming. | 852 // Tests the case where the remote device pauses and resume audio streaming. |
| 851 TEST_F(BluetoothAudioSinkChromeOSTest, PauseAndResume) { | 853 TEST_F(BluetoothAudioSinkChromeOSTest, PauseAndResume) { |
| 852 GetAudioSink(); | 854 GetAudioSink(); |
| 853 | 855 |
| 854 media_endpoint_->SelectConfiguration( | 856 media_endpoint_->SelectConfiguration( |
| 855 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 857 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
| 856 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 858 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
| 857 base::Unretained(this))); | 859 base::Unretained(this))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 874 | 876 |
| 875 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 877 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 876 | 878 |
| 877 std::vector<char> data_one(16, 0x12); | 879 std::vector<char> data_one(16, 0x12); |
| 878 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | 880 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
| 879 | 881 |
| 880 message_loop_.RunUntilIdle(); | 882 message_loop_.RunUntilIdle(); |
| 881 | 883 |
| 882 EXPECT_EQ(observer_->data_, data_one); | 884 EXPECT_EQ(observer_->data_, data_one); |
| 883 EXPECT_EQ(observer_->read_mtu_, | 885 EXPECT_EQ(observer_->read_mtu_, |
| 884 bluez::FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 886 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 885 EXPECT_EQ(observer_->state_changed_count_, 3); | 887 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 886 EXPECT_EQ(observer_->total_read_, data_one.size()); | 888 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 887 | 889 |
| 888 // Simulates the situation where the remote device pauses and resume audio | 890 // Simulates the situation where the remote device pauses and resume audio |
| 889 // streaming. | 891 // streaming. |
| 890 fake_transport_->SetState(media_endpoint_->object_path(), "idle"); | 892 fake_transport_->SetState(media_endpoint_->object_path(), "idle"); |
| 891 | 893 |
| 892 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 894 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 893 EXPECT_EQ(observer_->state_changed_count_, 4); | 895 EXPECT_EQ(observer_->state_changed_count_, 4); |
| 894 | 896 |
| 895 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 897 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 896 | 898 |
| 897 std::vector<char> data_two(8, 0x10); | 899 std::vector<char> data_two(8, 0x10); |
| 898 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); | 900 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); |
| 899 | 901 |
| 900 message_loop_.RunUntilIdle(); | 902 message_loop_.RunUntilIdle(); |
| 901 | 903 |
| 902 EXPECT_EQ(observer_->data_, data_two); | 904 EXPECT_EQ(observer_->data_, data_two); |
| 903 EXPECT_EQ(observer_->read_mtu_, | 905 EXPECT_EQ(observer_->read_mtu_, |
| 904 bluez::FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 906 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 905 EXPECT_EQ(observer_->state_changed_count_, 6); | 907 EXPECT_EQ(observer_->state_changed_count_, 6); |
| 906 EXPECT_EQ(observer_->total_read_, data_two.size()); | 908 EXPECT_EQ(observer_->total_read_, data_two.size()); |
| 907 } | 909 } |
| 908 | 910 |
| 909 TEST_F(BluetoothAudioSinkChromeOSTest, ContinuouslyStreaming) { | 911 TEST_F(BluetoothAudioSinkChromeOSTest, ContinuouslyStreaming) { |
| 910 GetAudioSink(); | 912 GetAudioSink(); |
| 911 | 913 |
| 912 media_endpoint_->SelectConfiguration( | 914 media_endpoint_->SelectConfiguration( |
| 913 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 915 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
| 914 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 916 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 932 | 934 |
| 933 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 935 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 934 | 936 |
| 935 std::vector<char> data_one(16, 0x12); | 937 std::vector<char> data_one(16, 0x12); |
| 936 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | 938 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
| 937 | 939 |
| 938 message_loop_.RunUntilIdle(); | 940 message_loop_.RunUntilIdle(); |
| 939 | 941 |
| 940 EXPECT_EQ(observer_->data_, data_one); | 942 EXPECT_EQ(observer_->data_, data_one); |
| 941 EXPECT_EQ(observer_->read_mtu_, | 943 EXPECT_EQ(observer_->read_mtu_, |
| 942 bluez::FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 944 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 943 EXPECT_EQ(observer_->state_changed_count_, 3); | 945 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 944 EXPECT_EQ(observer_->total_read_, data_one.size()); | 946 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 945 | 947 |
| 946 std::vector<char> data_two(8, 0x10); | 948 std::vector<char> data_two(8, 0x10); |
| 947 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); | 949 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); |
| 948 | 950 |
| 949 message_loop_.RunUntilIdle(); | 951 message_loop_.RunUntilIdle(); |
| 950 | 952 |
| 951 EXPECT_EQ(observer_->data_, data_two); | 953 EXPECT_EQ(observer_->data_, data_two); |
| 952 EXPECT_EQ(observer_->read_mtu_, | 954 EXPECT_EQ(observer_->read_mtu_, |
| 953 bluez::FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 955 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 954 EXPECT_EQ(observer_->state_changed_count_, 3); | 956 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 955 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); | 957 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); |
| 956 } | 958 } |
| 957 | 959 |
| 958 } // namespace chromeos | 960 } // namespace chromeos |
| OLD | NEW |