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

Side by Side Diff: remoting/protocol/audio_pump_unittest.cc

Issue 2254673002: Remove dependency on AudioStub in ConnectionToClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
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 "remoting/host/audio_pump.h" 5 #include "remoting/protocol/audio_pump.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "remoting/codec/audio_encoder.h" 16 #include "remoting/codec/audio_encoder.h"
17 #include "remoting/host/audio_capturer.h"
18 #include "remoting/proto/audio.pb.h" 17 #include "remoting/proto/audio.pb.h"
18 #include "remoting/protocol/audio_source.h"
19 #include "remoting/protocol/audio_stub.h" 19 #include "remoting/protocol/audio_stub.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace remoting { 22 namespace remoting {
23 namespace protocol {
23 24
24 namespace { 25 namespace {
25 26
26 // Creates a dummy packet with 1k data 27 // Creates a dummy packet with 1k data
27 std::unique_ptr<AudioPacket> MakeAudioPacket() { 28 std::unique_ptr<AudioPacket> MakeAudioPacket() {
28 std::unique_ptr<AudioPacket> packet(new AudioPacket); 29 std::unique_ptr<AudioPacket> packet(new AudioPacket);
29 packet->add_data()->resize(1000); 30 packet->add_data()->resize(1000);
30 return packet; 31 return packet;
31 } 32 }
32 33
33 } // namespace 34 } // namespace
34 35
35 class FakeAudioCapturer : public AudioCapturer { 36 class FakeAudioSource : public AudioSource {
36 public: 37 public:
37 FakeAudioCapturer() {} 38 FakeAudioSource() {}
38 ~FakeAudioCapturer() override {} 39 ~FakeAudioSource() override {}
39 40
40 bool Start(const PacketCapturedCallback& callback) override { 41 bool Start(const PacketCapturedCallback& callback) override {
41 callback_ = callback; 42 callback_ = callback;
42 return true; 43 return true;
43 } 44 }
44 45
45 const PacketCapturedCallback& callback() { return callback_; } 46 const PacketCapturedCallback& callback() { return callback_; }
46 47
47 private: 48 private:
48 PacketCapturedCallback callback_; 49 PacketCapturedCallback callback_;
49 50
50 DISALLOW_COPY_AND_ASSIGN(FakeAudioCapturer); 51 DISALLOW_COPY_AND_ASSIGN(FakeAudioSource);
51 }; 52 };
52 53
53 class FakeAudioEncoder : public AudioEncoder { 54 class FakeAudioEncoder : public AudioEncoder {
54 public: 55 public:
55 FakeAudioEncoder() {} 56 FakeAudioEncoder() {}
56 ~FakeAudioEncoder() override {} 57 ~FakeAudioEncoder() override {}
57 58
58 std::unique_ptr<AudioPacket> Encode( 59 std::unique_ptr<AudioPacket> Encode(
59 std::unique_ptr<AudioPacket> packet) override { 60 std::unique_ptr<AudioPacket> packet) override {
60 return packet; 61 return packet;
(...skipping 13 matching lines...) Expand all
74 void SetUp() override; 75 void SetUp() override;
75 void TearDown() override; 76 void TearDown() override;
76 77
77 // protocol::AudioStub interface. 78 // protocol::AudioStub interface.
78 void ProcessAudioPacket(std::unique_ptr<AudioPacket> audio_packet, 79 void ProcessAudioPacket(std::unique_ptr<AudioPacket> audio_packet,
79 const base::Closure& done) override; 80 const base::Closure& done) override;
80 81
81 protected: 82 protected:
82 base::MessageLoop message_loop_; 83 base::MessageLoop message_loop_;
83 84
84 // |capturer_| and |encoder_| are owned by the |pump_|. 85 // |source_| and |encoder_| are owned by the |pump_|.
85 FakeAudioCapturer* capturer_; 86 FakeAudioSource* source_;
86 FakeAudioEncoder* encoder_; 87 FakeAudioEncoder* encoder_;
87 88
88 std::unique_ptr<AudioPump> pump_; 89 std::unique_ptr<AudioPump> pump_;
89 90
90 ScopedVector<AudioPacket> sent_packets_; 91 ScopedVector<AudioPacket> sent_packets_;
91 std::vector<base::Closure> done_closures_; 92 std::vector<base::Closure> done_closures_;
92 93
93 private: 94 private:
94 DISALLOW_COPY_AND_ASSIGN(AudioPumpTest); 95 DISALLOW_COPY_AND_ASSIGN(AudioPumpTest);
95 }; 96 };
96 97
97 void AudioPumpTest::SetUp() { 98 void AudioPumpTest::SetUp() {
98 capturer_ = new FakeAudioCapturer(); 99 source_ = new FakeAudioSource();
99 encoder_ = new FakeAudioEncoder(); 100 encoder_ = new FakeAudioEncoder();
100 pump_.reset(new AudioPump(message_loop_.task_runner(), 101 pump_.reset(new AudioPump(message_loop_.task_runner(),
101 base::WrapUnique(capturer_), 102 base::WrapUnique(source_),
102 base::WrapUnique(encoder_), this)); 103 base::WrapUnique(encoder_), this));
103 } 104 }
104 105
105 void AudioPumpTest::TearDown() { 106 void AudioPumpTest::TearDown() {
106 pump_.reset(); 107 pump_.reset();
107 108
108 // Let the message loop run to finish destroying the capturer. 109 // Let the message loop run to finish destroying the capturer.
109 base::RunLoop().RunUntilIdle(); 110 base::RunLoop().RunUntilIdle();
110 } 111 }
111 112
112 void AudioPumpTest::ProcessAudioPacket( 113 void AudioPumpTest::ProcessAudioPacket(
113 std::unique_ptr<AudioPacket> audio_packet, 114 std::unique_ptr<AudioPacket> audio_packet,
114 const base::Closure& done) { 115 const base::Closure& done) {
115 sent_packets_.push_back(std::move(audio_packet)); 116 sent_packets_.push_back(std::move(audio_packet));
116 done_closures_.push_back(done); 117 done_closures_.push_back(done);
117 } 118 }
118 119
119 // Verify that the pump pauses pumping when the network is congested. 120 // Verify that the pump pauses pumping when the network is congested.
120 TEST_F(AudioPumpTest, BufferSizeLimit) { 121 TEST_F(AudioPumpTest, BufferSizeLimit) {
121 // Run message loop to let the pump start the capturer. 122 // Run message loop to let the pump start the capturer.
122 base::RunLoop().RunUntilIdle(); 123 base::RunLoop().RunUntilIdle();
123 ASSERT_FALSE(capturer_->callback().is_null()); 124 ASSERT_FALSE(source_->callback().is_null());
124 125
125 // Try sending 100 packets, 1k each. The pump should stop pumping and start 126 // Try sending 100 packets, 1k each. The pump should stop pumping and start
126 // dropping the data at some point. 127 // dropping the data at some point.
127 for (size_t i = 0; i < 100; ++i) { 128 for (size_t i = 0; i < 100; ++i) {
128 capturer_->callback().Run(MakeAudioPacket()); 129 source_->callback().Run(MakeAudioPacket());
129 base::RunLoop().RunUntilIdle(); 130 base::RunLoop().RunUntilIdle();
130 } 131 }
131 132
132 size_t num_sent_packets = sent_packets_.size(); 133 size_t num_sent_packets = sent_packets_.size();
133 EXPECT_LT(num_sent_packets, 100U); 134 EXPECT_LT(num_sent_packets, 100U);
134 EXPECT_GT(num_sent_packets, 0U); 135 EXPECT_GT(num_sent_packets, 0U);
135 136
136 // Call done closure for the first packet. This should allow one more packet 137 // Call done closure for the first packet. This should allow one more packet
137 // to be sent below. 138 // to be sent below.
138 done_closures_.front().Run(); 139 done_closures_.front().Run();
139 base::RunLoop().RunUntilIdle(); 140 base::RunLoop().RunUntilIdle();
140 141
141 // Verify that the pump continues to send captured audio. 142 // Verify that the pump continues to send captured audio.
142 capturer_->callback().Run(MakeAudioPacket()); 143 source_->callback().Run(MakeAudioPacket());
143 base::RunLoop().RunUntilIdle(); 144 base::RunLoop().RunUntilIdle();
144 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); 145 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size());
145 } 146 }
146 147
148 } // namespace protocol
147 } // namespace remoting 149 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698