Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: device/bluetooth/bluetooth_audio_sink_chromeos_unittest.cc

Issue 1034893002: device/bluetooth: Add read_mtu as an argument of BluetoothAudioSinkDataAvailable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename constants. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluetooth_audio_sink_chromeos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_,
845 FakeBluetoothMediaTransportClient::kDefaultReadMtu);
841 } 846 }
842 847
843 // Tests the case where the remote device pauses and resume audio streaming. 848 // Tests the case where the remote device pauses and resume audio streaming.
844 TEST_F(BluetoothAudioSinkChromeOSTest, PauseAndResume) { 849 TEST_F(BluetoothAudioSinkChromeOSTest, PauseAndResume) {
845 GetAudioSink(); 850 GetAudioSink();
846 851
847 media_endpoint_->SelectConfiguration( 852 media_endpoint_->SelectConfiguration(
848 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), 853 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}),
849 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, 854 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback,
850 base::Unretained(this))); 855 base::Unretained(this)));
(...skipping 15 matching lines...) Expand all
866 EXPECT_EQ(observer_->volume_changed_count_, 1); 871 EXPECT_EQ(observer_->volume_changed_count_, 1);
867 872
868 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); 873 fake_transport_->SetState(media_endpoint_->object_path(), "pending");
869 874
870 std::vector<char> data_one(16, 0x12); 875 std::vector<char> data_one(16, 0x12);
871 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); 876 fake_transport_->WriteData(media_endpoint_->object_path(), data_one);
872 877
873 message_loop_.RunUntilIdle(); 878 message_loop_.RunUntilIdle();
874 879
875 EXPECT_EQ(observer_->data_, data_one); 880 EXPECT_EQ(observer_->data_, data_one);
881 EXPECT_EQ(observer_->read_mtu_,
882 FakeBluetoothMediaTransportClient::kDefaultReadMtu);
876 EXPECT_EQ(observer_->state_changed_count_, 3); 883 EXPECT_EQ(observer_->state_changed_count_, 3);
877 EXPECT_EQ(observer_->total_read_, data_one.size()); 884 EXPECT_EQ(observer_->total_read_, data_one.size());
878 885
879 // Simulates the situation where the remote device pauses and resume audio 886 // Simulates the situation where the remote device pauses and resume audio
880 // streaming. 887 // streaming.
881 fake_transport_->SetState(media_endpoint_->object_path(), "idle"); 888 fake_transport_->SetState(media_endpoint_->object_path(), "idle");
882 889
883 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); 890 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
884 EXPECT_EQ(observer_->state_changed_count_, 4); 891 EXPECT_EQ(observer_->state_changed_count_, 4);
885 892
886 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); 893 fake_transport_->SetState(media_endpoint_->object_path(), "pending");
887 894
888 std::vector<char> data_two(8, 0x10); 895 std::vector<char> data_two(8, 0x10);
889 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); 896 fake_transport_->WriteData(media_endpoint_->object_path(), data_two);
890 897
891 message_loop_.RunUntilIdle(); 898 message_loop_.RunUntilIdle();
892 899
893 EXPECT_EQ(observer_->data_, data_two); 900 EXPECT_EQ(observer_->data_, data_two);
901 EXPECT_EQ(observer_->read_mtu_,
902 FakeBluetoothMediaTransportClient::kDefaultReadMtu);
894 EXPECT_EQ(observer_->state_changed_count_, 6); 903 EXPECT_EQ(observer_->state_changed_count_, 6);
895 EXPECT_EQ(observer_->total_read_, data_two.size()); 904 EXPECT_EQ(observer_->total_read_, data_two.size());
896 } 905 }
897 906
898 TEST_F(BluetoothAudioSinkChromeOSTest, ContinuouslyStreaming) { 907 TEST_F(BluetoothAudioSinkChromeOSTest, ContinuouslyStreaming) {
899 GetAudioSink(); 908 GetAudioSink();
900 909
901 media_endpoint_->SelectConfiguration( 910 media_endpoint_->SelectConfiguration(
902 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), 911 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}),
903 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, 912 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback,
(...skipping 16 matching lines...) Expand all
920 EXPECT_EQ(observer_->volume_changed_count_, 1); 929 EXPECT_EQ(observer_->volume_changed_count_, 1);
921 930
922 fake_transport_->SetState(media_endpoint_->object_path(), "pending"); 931 fake_transport_->SetState(media_endpoint_->object_path(), "pending");
923 932
924 std::vector<char> data_one(16, 0x12); 933 std::vector<char> data_one(16, 0x12);
925 fake_transport_->WriteData(media_endpoint_->object_path(), data_one); 934 fake_transport_->WriteData(media_endpoint_->object_path(), data_one);
926 935
927 message_loop_.RunUntilIdle(); 936 message_loop_.RunUntilIdle();
928 937
929 EXPECT_EQ(observer_->data_, data_one); 938 EXPECT_EQ(observer_->data_, data_one);
939 EXPECT_EQ(observer_->read_mtu_,
940 FakeBluetoothMediaTransportClient::kDefaultReadMtu);
930 EXPECT_EQ(observer_->state_changed_count_, 3); 941 EXPECT_EQ(observer_->state_changed_count_, 3);
931 EXPECT_EQ(observer_->total_read_, data_one.size()); 942 EXPECT_EQ(observer_->total_read_, data_one.size());
932 943
933 std::vector<char> data_two(8, 0x10); 944 std::vector<char> data_two(8, 0x10);
934 fake_transport_->WriteData(media_endpoint_->object_path(), data_two); 945 fake_transport_->WriteData(media_endpoint_->object_path(), data_two);
935 946
936 message_loop_.RunUntilIdle(); 947 message_loop_.RunUntilIdle();
937 948
938 EXPECT_EQ(observer_->data_, data_two); 949 EXPECT_EQ(observer_->data_, data_two);
950 EXPECT_EQ(observer_->read_mtu_,
951 FakeBluetoothMediaTransportClient::kDefaultReadMtu);
939 EXPECT_EQ(observer_->state_changed_count_, 3); 952 EXPECT_EQ(observer_->state_changed_count_, 3);
940 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size()); 953 EXPECT_EQ(observer_->total_read_, data_one.size() + data_two.size());
941 } 954 }
942 955
943 } // namespace chromeos 956 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_audio_sink_chromeos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698