Replace FINAL and OVERRIDE with their C++11 counterparts in content/renderer
[chromium-blink-merge.git] / content / renderer / media / webrtc / webrtc_local_audio_track_adapter_unittest.cc
blobf4a037ca6e97e7c3f22117c24bc3e0b7a9c55ea1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "content/public/common/content_switches.h"
7 #include "content/renderer/media/mock_media_constraint_factory.h"
8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
9 #include "content/renderer/media/webrtc_local_audio_track.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
14 using ::testing::_;
15 using ::testing::AnyNumber;
17 namespace content {
19 namespace {
21 class MockWebRtcAudioSink : public webrtc::AudioTrackSinkInterface {
22 public:
23 MockWebRtcAudioSink() {}
24 ~MockWebRtcAudioSink() {}
25 MOCK_METHOD5(OnData, void(const void* audio_data,
26 int bits_per_sample,
27 int sample_rate,
28 int number_of_channels,
29 int number_of_frames));
32 } // namespace
34 class WebRtcLocalAudioTrackAdapterTest : public ::testing::Test {
35 public:
36 WebRtcLocalAudioTrackAdapterTest()
37 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
38 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480),
39 adapter_(WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)) {
40 MockMediaConstraintFactory constraint_factory;
41 capturer_ = WebRtcAudioCapturer::CreateCapturer(
42 -1, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", ""),
43 constraint_factory.CreateWebMediaConstraints(), NULL, NULL);
44 track_.reset(new WebRtcLocalAudioTrack(adapter_.get(), capturer_, NULL));
47 protected:
48 virtual void SetUp() override {
49 track_->OnSetFormat(params_);
50 EXPECT_TRUE(track_->GetAudioAdapter()->enabled());
53 media::AudioParameters params_;
54 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_;
55 scoped_refptr<WebRtcAudioCapturer> capturer_;
56 scoped_ptr<WebRtcLocalAudioTrack> track_;
59 // Adds and Removes a WebRtcAudioSink to a local audio track.
60 TEST_F(WebRtcLocalAudioTrackAdapterTest, AddAndRemoveSink) {
61 // Add a sink to the webrtc track.
62 scoped_ptr<MockWebRtcAudioSink> sink(new MockWebRtcAudioSink());
63 webrtc::AudioTrackInterface* webrtc_track =
64 static_cast<webrtc::AudioTrackInterface*>(adapter_.get());
65 webrtc_track->AddSink(sink.get());
67 // Send a packet via |track_| and it data should reach the sink of the
68 // |adapter_|.
69 const int length = params_.frames_per_buffer() * params_.channels();
70 scoped_ptr<int16[]> data(new int16[length]);
71 // Initialize the data to 0 to avoid Memcheck:Uninitialized warning.
72 memset(data.get(), 0, length * sizeof(data[0]));
74 EXPECT_CALL(*sink,
75 OnData(_, 16, params_.sample_rate(), params_.channels(),
76 params_.frames_per_buffer()));
77 track_->Capture(data.get(), base::TimeDelta(), 255, false, false);
79 // Remove the sink from the webrtc track.
80 webrtc_track->RemoveSink(sink.get());
81 sink.reset();
83 // Verify that no more callback gets into the sink.
84 track_->Capture(data.get(), base::TimeDelta(), 255, false, false);
87 TEST_F(WebRtcLocalAudioTrackAdapterTest, GetSignalLevel) {
88 webrtc::AudioTrackInterface* webrtc_track =
89 static_cast<webrtc::AudioTrackInterface*>(adapter_.get());
90 int signal_level = 0;
91 EXPECT_TRUE(webrtc_track->GetSignalLevel(&signal_level));
93 // Disable the audio processing in the audio track.
94 CommandLine::ForCurrentProcess()->AppendSwitch(
95 switches::kDisableAudioTrackProcessing);
96 EXPECT_FALSE(webrtc_track->GetSignalLevel(&signal_level));
99 } // namespace content