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

Side by Side Diff: content/renderer/media/renderer_webaudiodevice_impl_unittest.cc

Issue 2501863003: Support for AudioContextOptions latencyHint. (Closed)
Patch Set: Adding additional tests. Created 4 years 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
(Empty)
1 // Copyright 2016 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.
4
5 #include "content/renderer/media/renderer_webaudiodevice_impl.h"
6
7 #include "base/bind.h"
8 #include "content/renderer/media/audio_device_factory.h"
9 #include "media/base/audio_capturer_source.h"
10 #include "media/base/mock_audio_renderer_sink.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using testing::_;
15
16 namespace content {
17
18 namespace {
19
20 const int kHardwareSampleRate = 44100;
21 const int kHardwareBufferSize = 128;
22 const int kRenderFrameId = 100;
23
24 int MockFrameIdFromCurrentContext() {
25 return kRenderFrameId;
26 }
27
28 media::AudioParameters MockGetOutputDeviceParameters(
29 int frame_id,
30 int session_id,
31 const std::string& device_id,
32 const url::Origin& security_origin) {
33 return media::AudioParameters(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
34 media::CHANNEL_LAYOUT_STEREO,
35 kHardwareSampleRate, 16, kHardwareBufferSize);
36 }
37
38 class MockRendererWebAudioDeviceImpl : public RendererWebAudioDeviceImpl {
o1ka 2016/12/07 20:56:01 Nit: such class is usually called FooUnderTest. (
Andrew MacPherson 2016/12/08 10:06:12 Done, fixed the class name. Re: virtual methods I
o1ka 2016/12/08 10:57:19 Sounds good.
39 public:
40 MockRendererWebAudioDeviceImpl(
41 media::ChannelLayout layout,
42 const blink::WebAudioLatencyHint& latency_hint,
43 blink::WebAudioDevice::RenderCallback* callback,
44 int session_id,
45 const url::Origin& security_origin)
46 : RendererWebAudioDeviceImpl(layout,
47 latency_hint,
48 callback,
49 session_id,
50 security_origin,
51 base::Bind(&MockGetOutputDeviceParameters),
52 base::Bind(&MockFrameIdFromCurrentContext)) {
53 }
54 };
55
56 } // namespace
57
58 class RendererWebAudioDeviceImplTest
59 : public blink::WebAudioDevice::RenderCallback,
60 public AudioDeviceFactory,
61 public testing::Test {
62 public:
63 MOCK_METHOD3(render,
64 void(const blink::WebVector<float*>& sourceData,
65 const blink::WebVector<float*>& destinationData,
66 size_t numberOfFrames));
67
68 protected:
69 RendererWebAudioDeviceImplTest() {}
70
71 void SetupDevice(blink::WebAudioLatencyHint latencyHint) {
72 webaudio_device_.reset(new MockRendererWebAudioDeviceImpl(
73 media::CHANNEL_LAYOUT_MONO, latencyHint, this, 0, url::Origin()));
74 }
75
76 MOCK_METHOD1(CreateAudioCapturerSource,
77 scoped_refptr<media::AudioCapturerSource>(int));
78 MOCK_METHOD4(CreateFinalAudioRendererSink,
79 scoped_refptr<media::AudioRendererSink>(int,
80 int,
81 const std::string&,
82 const url::Origin&));
83 MOCK_METHOD5(
84 CreateSwitchableAudioRendererSink,
85 scoped_refptr<media::SwitchableAudioRendererSink>(SourceType,
86 int,
87 int,
88 const std::string&,
89 const url::Origin&));
90
91 scoped_refptr<media::AudioRendererSink> CreateAudioRendererSink(
92 SourceType source_type,
93 int render_frame_id,
94 int session_id,
95 const std::string& device_id,
96 const url::Origin& security_origin) {
97 scoped_refptr<media::MockAudioRendererSink> fake_sink(
o1ka 2016/12/07 20:56:01 Is this local needed?
Andrew MacPherson 2016/12/08 10:06:12 Done.
98 new media::MockAudioRendererSink(
99 device_id, media::OUTPUT_DEVICE_STATUS_OK,
100 MockGetOutputDeviceParameters(render_frame_id, session_id,
101 device_id, security_origin)));
102 mock_sink_ = fake_sink;
103
104 EXPECT_CALL(*mock_sink_.get(), Start());
o1ka 2016/12/07 20:56:01 Do you start WebAudioDeviceImpl in each test? Will
Andrew MacPherson 2016/12/08 10:06:12 The CreateAudioRendererSink method is only invoked
o1ka 2016/12/08 10:57:19 Acknowledged.
105 EXPECT_CALL(*mock_sink_.get(), Play());
106
o1ka 2016/12/07 20:56:01 We should ensure the sink gets stopped - this is a
Andrew MacPherson 2016/12/08 10:06:12 Done, I've moved the EXPECT_CALL for Stop up to wh
107 return fake_sink;
108 }
109
110 void TearDown() override {
111 webaudio_device_.reset();
112 mock_sink_ = nullptr;
113 }
114
115 std::unique_ptr<RendererWebAudioDeviceImpl> webaudio_device_;
116 scoped_refptr<media::MockAudioRendererSink> mock_sink_;
117 };
118
119 TEST_F(RendererWebAudioDeviceImplTest, TestLatencyHint) {
120 SetupDevice(blink::WebAudioLatencyHint(
121 blink::WebAudioLatencyHint::CategoryInteractive));
122 int interactive_frames = webaudio_device_->framesPerBuffer();
123
124 SetupDevice(
125 blink::WebAudioLatencyHint(blink::WebAudioLatencyHint::CategoryBalanced));
126 int balanced_frames = webaudio_device_->framesPerBuffer();
127
128 SetupDevice(
129 blink::WebAudioLatencyHint(blink::WebAudioLatencyHint::CategoryPlayback));
130 int playback_frames = webaudio_device_->framesPerBuffer();
131
132 EXPECT_GT(playback_frames, balanced_frames);
133 EXPECT_GT(balanced_frames, interactive_frames);
o1ka 2016/12/07 20:56:01 Have you considered comparing with media::AudioLat
Andrew MacPherson 2016/12/08 10:06:12 I've added a latencyType() method to the WebAudioD
o1ka 2016/12/08 10:57:19 Sorry, I was unclear. latencyType() method is not
Andrew MacPherson 2016/12/08 12:22:54 Ah, sorry, I think I read too quickly and misunder
o1ka 2016/12/08 13:10:15 Great, thanks!
134 }
135
136 TEST_F(RendererWebAudioDeviceImplTest, TestStartStop) {
137 SetupDevice(blink::WebAudioLatencyHint(
138 blink::WebAudioLatencyHint::CategoryInteractive));
139 webaudio_device_->start();
140 EXPECT_CALL(*mock_sink_.get(), Stop());
141 webaudio_device_->stop();
142 }
143
o1ka 2016/12/07 20:56:01 Could you add testing that sampleRate() and frames
Andrew MacPherson 2016/12/08 10:06:12 Done, I just modified the very simple StartStop te
144 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698