| 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 "device/bluetooth/bluez/bluetooth_audio_sink_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_audio_sink_bluez.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 properties_); | 439 properties_); |
| 440 | 440 |
| 441 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 441 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 442 EXPECT_EQ(callback_count_, 2); | 442 EXPECT_EQ(callback_count_, 2); |
| 443 EXPECT_EQ(error_callback_count_, 0); | 443 EXPECT_EQ(error_callback_count_, 0); |
| 444 EXPECT_EQ(observer_->state_changed_count_, 1); | 444 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 445 EXPECT_EQ(observer_->volume_changed_count_, 1); | 445 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 446 | 446 |
| 447 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 447 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 448 | 448 |
| 449 message_loop_.RunUntilIdle(); | 449 base::RunLoop().RunUntilIdle(); |
| 450 | 450 |
| 451 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | 451 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
| 452 // and Acquire will trigger state change. Therefore, the state will be | 452 // and Acquire will trigger state change. Therefore, the state will be |
| 453 // STATE_ACTIVE right after STATE_PENDING. | 453 // STATE_ACTIVE right after STATE_PENDING. |
| 454 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | 454 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
| 455 EXPECT_EQ(observer_->state_changed_count_, 3); | 455 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 456 | 456 |
| 457 // Gets the media object and makes it invisible to see if the state of the | 457 // Gets the media object and makes it invisible to see if the state of the |
| 458 // audio sink changes accordingly. | 458 // audio sink changes accordingly. |
| 459 fake_media_->SetVisible(false); | 459 fake_media_->SetVisible(false); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 properties_); | 526 properties_); |
| 527 | 527 |
| 528 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 528 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 529 EXPECT_EQ(callback_count_, 2); | 529 EXPECT_EQ(callback_count_, 2); |
| 530 EXPECT_EQ(error_callback_count_, 0); | 530 EXPECT_EQ(error_callback_count_, 0); |
| 531 EXPECT_EQ(observer_->state_changed_count_, 1); | 531 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 532 EXPECT_EQ(observer_->volume_changed_count_, 1); | 532 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 533 | 533 |
| 534 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 534 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 535 | 535 |
| 536 message_loop_.RunUntilIdle(); | 536 base::RunLoop().RunUntilIdle(); |
| 537 | 537 |
| 538 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | 538 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
| 539 // and Acquire will trigger state change. Therefore, the state will be | 539 // and Acquire will trigger state change. Therefore, the state will be |
| 540 // STATE_ACTIVE right after STATE_PENDING. | 540 // STATE_ACTIVE right after STATE_PENDING. |
| 541 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | 541 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
| 542 EXPECT_EQ(observer_->state_changed_count_, 3); | 542 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 543 | 543 |
| 544 // Makes the transport object invalid to see if the state of the audio sink | 544 // Makes the transport object invalid to see if the state of the audio sink |
| 545 // changes accordingly. | 545 // changes accordingly. |
| 546 fake_transport_->SetValid(media_endpoint_, false); | 546 fake_transport_->SetValid(media_endpoint_, false); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 properties_); | 699 properties_); |
| 700 | 700 |
| 701 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 701 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 702 EXPECT_EQ(callback_count_, 2); | 702 EXPECT_EQ(callback_count_, 2); |
| 703 EXPECT_EQ(error_callback_count_, 0); | 703 EXPECT_EQ(error_callback_count_, 0); |
| 704 EXPECT_EQ(observer_->state_changed_count_, 1); | 704 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 705 EXPECT_EQ(observer_->volume_changed_count_, 1); | 705 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 706 | 706 |
| 707 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 707 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 708 | 708 |
| 709 message_loop_.RunUntilIdle(); | 709 base::RunLoop().RunUntilIdle(); |
| 710 | 710 |
| 711 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | 711 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
| 712 // and Acquire will trigger state change. Therefore, the state will be | 712 // and Acquire will trigger state change. Therefore, the state will be |
| 713 // STATE_ACTIVE right after STATE_PENDING. | 713 // STATE_ACTIVE right after STATE_PENDING. |
| 714 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | 714 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
| 715 EXPECT_EQ(observer_->state_changed_count_, 3); | 715 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 716 | 716 |
| 717 audio_sink_->Unregister( | 717 audio_sink_->Unregister( |
| 718 base::Bind(&BluetoothAudioSinkBlueZTest::Callback, | 718 base::Bind(&BluetoothAudioSinkBlueZTest::Callback, |
| 719 base::Unretained(this)), | 719 base::Unretained(this)), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 EXPECT_EQ(callback_count_, 2); | 827 EXPECT_EQ(callback_count_, 2); |
| 828 EXPECT_EQ(error_callback_count_, 0); | 828 EXPECT_EQ(error_callback_count_, 0); |
| 829 EXPECT_EQ(observer_->state_changed_count_, 1); | 829 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 830 EXPECT_EQ(observer_->volume_changed_count_, 1); | 830 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 831 | 831 |
| 832 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 832 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 833 | 833 |
| 834 std::vector<char> data_one(16, 0x12); | 834 std::vector<char> data_one(16, 0x12); |
| 835 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | 835 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
| 836 | 836 |
| 837 message_loop_.RunUntilIdle(); | 837 base::RunLoop().RunUntilIdle(); |
| 838 | 838 |
| 839 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, | 839 // Acquire is called when the state of |audio_sink_| becomes STATE_PENDING, |
| 840 // and Acquire will trigger state change. Therefore, the state will be | 840 // and Acquire will trigger state change. Therefore, the state will be |
| 841 // STATE_ACTIVE right after STATE_PENDING. | 841 // STATE_ACTIVE right after STATE_PENDING. |
| 842 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE | 842 // State: STATE_IDLE -> STATE_PENDING -> STATE_ACTIVE |
| 843 EXPECT_EQ(observer_->state_changed_count_, 3); | 843 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 844 EXPECT_EQ(observer_->total_read_, data_one.size()); | 844 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 845 EXPECT_EQ(observer_->data_, data_one); | 845 EXPECT_EQ(observer_->data_, data_one); |
| 846 EXPECT_EQ(observer_->read_mtu_, | 846 EXPECT_EQ(observer_->read_mtu_, |
| 847 FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 847 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 870 EXPECT_EQ(callback_count_, 2); | 870 EXPECT_EQ(callback_count_, 2); |
| 871 EXPECT_EQ(error_callback_count_, 0); | 871 EXPECT_EQ(error_callback_count_, 0); |
| 872 EXPECT_EQ(observer_->state_changed_count_, 1); | 872 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 873 EXPECT_EQ(observer_->volume_changed_count_, 1); | 873 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 874 | 874 |
| 875 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 875 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 876 | 876 |
| 877 std::vector<char> data_one(16, 0x12); | 877 std::vector<char> data_one(16, 0x12); |
| 878 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | 878 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
| 879 | 879 |
| 880 message_loop_.RunUntilIdle(); | 880 base::RunLoop().RunUntilIdle(); |
| 881 | 881 |
| 882 EXPECT_EQ(observer_->data_, data_one); | 882 EXPECT_EQ(observer_->data_, data_one); |
| 883 EXPECT_EQ(observer_->read_mtu_, | 883 EXPECT_EQ(observer_->read_mtu_, |
| 884 FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 884 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 885 EXPECT_EQ(observer_->state_changed_count_, 3); | 885 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 886 EXPECT_EQ(observer_->total_read_, data_one.size()); | 886 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 887 | 887 |
| 888 // Simulates the situation where the remote device pauses and resume audio | 888 // Simulates the situation where the remote device pauses and resume audio |
| 889 // streaming. | 889 // streaming. |
| 890 fake_transport_->SetState(media_endpoint_->object_path(), "idle"); | 890 fake_transport_->SetState(media_endpoint_->object_path(), "idle"); |
| 891 | 891 |
| 892 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); | 892 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); |
| 893 EXPECT_EQ(observer_->state_changed_count_, 4); | 893 EXPECT_EQ(observer_->state_changed_count_, 4); |
| 894 | 894 |
| 895 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 895 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 896 | 896 |
| 897 std::vector<char> data_two(8, 0x10); | 897 std::vector<char> data_two(8, 0x10); |
| 898 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); | 898 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); |
| 899 | 899 |
| 900 message_loop_.RunUntilIdle(); | 900 base::RunLoop().RunUntilIdle(); |
| 901 | 901 |
| 902 EXPECT_EQ(observer_->data_, data_two); | 902 EXPECT_EQ(observer_->data_, data_two); |
| 903 EXPECT_EQ(observer_->read_mtu_, | 903 EXPECT_EQ(observer_->read_mtu_, |
| 904 FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 904 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 905 EXPECT_EQ(observer_->state_changed_count_, 6); | 905 EXPECT_EQ(observer_->state_changed_count_, 6); |
| 906 EXPECT_EQ(observer_->total_read_, data_two.size()); | 906 EXPECT_EQ(observer_->total_read_, data_two.size()); |
| 907 } | 907 } |
| 908 | 908 |
| 909 TEST_F(BluetoothAudioSinkBlueZTest, ContinuouslyStreaming) { | 909 TEST_F(BluetoothAudioSinkBlueZTest, ContinuouslyStreaming) { |
| 910 GetAudioSink(); | 910 GetAudioSink(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 928 EXPECT_EQ(callback_count_, 2); | 928 EXPECT_EQ(callback_count_, 2); |
| 929 EXPECT_EQ(error_callback_count_, 0); | 929 EXPECT_EQ(error_callback_count_, 0); |
| 930 EXPECT_EQ(observer_->state_changed_count_, 1); | 930 EXPECT_EQ(observer_->state_changed_count_, 1); |
| 931 EXPECT_EQ(observer_->volume_changed_count_, 1); | 931 EXPECT_EQ(observer_->volume_changed_count_, 1); |
| 932 | 932 |
| 933 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); | 933 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); |
| 934 | 934 |
| 935 std::vector<char> data_one(16, 0x12); | 935 std::vector<char> data_one(16, 0x12); |
| 936 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); | 936 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); |
| 937 | 937 |
| 938 message_loop_.RunUntilIdle(); | 938 base::RunLoop().RunUntilIdle(); |
| 939 | 939 |
| 940 EXPECT_EQ(observer_->data_, data_one); | 940 EXPECT_EQ(observer_->data_, data_one); |
| 941 EXPECT_EQ(observer_->read_mtu_, | 941 EXPECT_EQ(observer_->read_mtu_, |
| 942 FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 942 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 943 EXPECT_EQ(observer_->state_changed_count_, 3); | 943 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 944 EXPECT_EQ(observer_->total_read_, data_one.size()); | 944 EXPECT_EQ(observer_->total_read_, data_one.size()); |
| 945 | 945 |
| 946 std::vector<char> data_two(8, 0x10); | 946 std::vector<char> data_two(8, 0x10); |
| 947 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); | 947 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); |
| 948 | 948 |
| 949 message_loop_.RunUntilIdle(); | 949 base::RunLoop().RunUntilIdle(); |
| 950 | 950 |
| 951 EXPECT_EQ(observer_->data_, data_two); | 951 EXPECT_EQ(observer_->data_, data_two); |
| 952 EXPECT_EQ(observer_->read_mtu_, | 952 EXPECT_EQ(observer_->read_mtu_, |
| 953 FakeBluetoothMediaTransportClient::kDefaultReadMtu); | 953 FakeBluetoothMediaTransportClient::kDefaultReadMtu); |
| 954 EXPECT_EQ(observer_->state_changed_count_, 3); | 954 EXPECT_EQ(observer_->state_changed_count_, 3); |
| 955 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); | 955 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); |
| 956 } | 956 } |
| 957 | 957 |
| 958 } // namespace bluez | 958 } // namespace bluez |
| OLD | NEW |