| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 ++state_changed_count_; | 51 ++state_changed_count_; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void BluetoothAudioSinkVolumeChanged(BluetoothAudioSink* audio_sink, | 54 void BluetoothAudioSinkVolumeChanged(BluetoothAudioSink* audio_sink, |
| 55 uint16_t volume) override { | 55 uint16_t volume) override { |
| 56 ++volume_changed_count_; | 56 ++volume_changed_count_; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void BluetoothAudioSinkDataAvailable(BluetoothAudioSink* audio_sink, | 59 void BluetoothAudioSinkDataAvailable(BluetoothAudioSink* audio_sink, |
| 60 char* data, | 60 char* data, |
| 61 size_t size) override { | 61 size_t size, |
| 62 uint16_t read_mtu) override { |
| 62 total_read_ += size; | 63 total_read_ += size; |
| 63 data_.clear(); | 64 data_.clear(); |
| 64 data_.insert(data_.begin(), data, data + size); | 65 data_.insert(data_.begin(), data, data + size); |
| 66 read_mtu_ = read_mtu; |
| 65 } | 67 } |
| 66 | 68 |
| 67 int state_changed_count_; | 69 int state_changed_count_; |
| 68 int volume_changed_count_; | 70 int volume_changed_count_; |
| 69 int data_available_count_; | 71 int data_available_count_; |
| 70 size_t total_read_; | 72 size_t total_read_; |
| 71 std::vector<char> data_; | 73 std::vector<char> data_; |
| 74 uint16_t read_mtu_; |
| 72 BluetoothAudioSink::State state_; | 75 BluetoothAudioSink::State state_; |
| 73 | 76 |
| 74 private: | 77 private: |
| 75 scoped_refptr<BluetoothAudioSink> audio_sink_; | 78 scoped_refptr<BluetoothAudioSink> audio_sink_; |
| 76 }; | 79 }; |
| 77 | 80 |
| 78 class BluetoothAudioSinkChromeOSTest : public testing::Test { | 81 class BluetoothAudioSinkChromeOSTest : public testing::Test { |
| 79 public: | 82 public: |
| 80 void SetUp() override { | 83 void SetUp() override { |
| 81 DBusThreadManager::Initialize(); | 84 DBusThreadManager::Initialize(); |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 834 |
| 832 message_loop_.RunUntilIdle(); | 835 message_loop_.RunUntilIdle(); |
| 833 | 836 |
| 834 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | 837 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
| 835 // and Acquire will trigger state change. Therefore, the state will be | 838 // and Acquire will trigger state change. Therefore, the state will be |
| 836 // STATE_ACTIVE right after STATE_PENDING. | 839 // STATE_ACTIVE right after STATE_PENDING. |
| 837 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | 840 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
| 838 EXPECT_EQ(observer_->state_changed_count_, 3); | 841 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 839 EXPECT_EQ(observer_->total_read_, data_one.size()); | 842 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 840 EXPECT_EQ(observer_->data_, data_one); | 843 EXPECT_EQ(observer_->data_, data_one); |
| 844 EXPECT_EQ(observer_->read_mtu_, FakeBluetoothMediaTransportClient::kReadMtu); |
| 841 } | 845 } |
| 842 | 846 |
| 843 // Tests the case where the remote device pauses and resume audio streaming. | 847 // Tests the case where the remote device pauses and resume audio streaming. |
| 844 TEST_F(BluetoothAudioSinkChromeOSTest, PauseAndResume) { | 848 TEST_F(BluetoothAudioSinkChromeOSTest, PauseAndResume) { |
| 845 GetAudioSink(); | 849 GetAudioSink(); |
| 846 | 850 |
| 847 media_endpoint_->SelectConfiguration( | 851 media_endpoint_->SelectConfiguration( |
| 848 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 852 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
| 849 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 853 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
| 850 base::Unretained(this))); | 854 base::Unretained(this))); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 866 EXPECT_EQ(observer_->volume_changed_count_, 1); | 870 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 867 | 871 |
| 868 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 872 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 869 | 873 |
| 870 std::vector<char> data_one(16, 0x12); | 874 std::vector<char> data_one(16, 0x12); |
| 871 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | 875 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
| 872 | 876 |
| 873 message_loop_.RunUntilIdle(); | 877 message_loop_.RunUntilIdle(); |
| 874 | 878 |
| 875 EXPECT_EQ(observer_->data_, data_one); | 879 EXPECT_EQ(observer_->data_, data_one); |
| 880 EXPECT_EQ(observer_->read_mtu_, FakeBluetoothMediaTransportClient::kReadMtu); |
| 876 EXPECT_EQ(observer_->state_changed_count_, 3); | 881 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 877 EXPECT_EQ(observer_->total_read_, data_one.size()); | 882 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 878 | 883 |
| 879 // Simulates the situation where the remote device pauses and resume audio | 884 // Simulates the situation where the remote device pauses and resume audio |
| 880 // streaming. | 885 // streaming. |
| 881 fake_transport_->SetState(media_endpoint_->object_path(), "idle"); | 886 fake_transport_->SetState(media_endpoint_->object_path(), "idle"); |
| 882 | 887 |
| 883 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 888 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 884 EXPECT_EQ(observer_->state_changed_count_, 4); | 889 EXPECT_EQ(observer_->state_changed_count_, 4); |
| 885 | 890 |
| 886 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 891 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 887 | 892 |
| 888 std::vector<char> data_two(8, 0x10); | 893 std::vector<char> data_two(8, 0x10); |
| 889 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); | 894 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); |
| 890 | 895 |
| 891 message_loop_.RunUntilIdle(); | 896 message_loop_.RunUntilIdle(); |
| 892 | 897 |
| 893 EXPECT_EQ(observer_->data_, data_two); | 898 EXPECT_EQ(observer_->data_, data_two); |
| 899 EXPECT_EQ(observer_->read_mtu_, FakeBluetoothMediaTransportClient::kReadMtu); |
| 894 EXPECT_EQ(observer_->state_changed_count_, 6); | 900 EXPECT_EQ(observer_->state_changed_count_, 6); |
| 895 EXPECT_EQ(observer_->total_read_, data_two.size()); | 901 EXPECT_EQ(observer_->total_read_, data_two.size()); |
| 896 } | 902 } |
| 897 | 903 |
| 898 TEST_F(BluetoothAudioSinkChromeOSTest, ContinuouslyStreaming) { | 904 TEST_F(BluetoothAudioSinkChromeOSTest, ContinuouslyStreaming) { |
| 899 GetAudioSink(); | 905 GetAudioSink(); |
| 900 | 906 |
| 901 media_endpoint_->SelectConfiguration( | 907 media_endpoint_->SelectConfiguration( |
| 902 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), | 908 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), |
| 903 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, | 909 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 920 EXPECT_EQ(observer_->volume_changed_count_, 1); | 926 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 921 | 927 |
| 922 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 928 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 923 | 929 |
| 924 std::vector<char> data_one(16, 0x12); | 930 std::vector<char> data_one(16, 0x12); |
| 925 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | 931 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
| 926 | 932 |
| 927 message_loop_.RunUntilIdle(); | 933 message_loop_.RunUntilIdle(); |
| 928 | 934 |
| 929 EXPECT_EQ(observer_->data_, data_one); | 935 EXPECT_EQ(observer_->data_, data_one); |
| 936 EXPECT_EQ(observer_->read_mtu_, FakeBluetoothMediaTransportClient::kReadMtu); |
| 930 EXPECT_EQ(observer_->state_changed_count_, 3); | 937 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 931 EXPECT_EQ(observer_->total_read_, data_one.size()); | 938 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 932 | 939 |
| 933 std::vector<char> data_two(8, 0x10); | 940 std::vector<char> data_two(8, 0x10); |
| 934 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); | 941 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); |
| 935 | 942 |
| 936 message_loop_.RunUntilIdle(); | 943 message_loop_.RunUntilIdle(); |
| 937 | 944 |
| 938 EXPECT_EQ(observer_->data_, data_two); | 945 EXPECT_EQ(observer_->data_, data_two); |
| 946 EXPECT_EQ(observer_->read_mtu_, FakeBluetoothMediaTransportClient::kReadMtu); |
| 939 EXPECT_EQ(observer_->state_changed_count_, 3); | 947 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 940 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); | 948 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); |
| 941 } | 949 } |
| 942 | 950 |
| 943 } // namespace chromeos | 951 } // namespace chromeos |
| OLD | NEW |