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

Side by Side Diff: media/base/silent_sink_suspender_unittest.cc

Issue 2567143002: media::SilentSinkSuspender should simulate |delay| and |delay_timestamp| (Closed)
Patch Set: build fix content_unittets & media_blink_unittsests Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 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 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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 #include "base/test/test_message_loop.h" 6 #include "base/test/test_message_loop.h"
7 #include "media/base/fake_audio_render_callback.h" 7 #include "media/base/fake_audio_render_callback.h"
8 #include "media/base/mock_audio_renderer_sink.h" 8 #include "media/base/mock_audio_renderer_sink.h"
9 #include "media/base/silent_sink_suspender.h" 9 #include "media/base/silent_sink_suspender.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 ACTION_P(RunClosure, closure) { 15 ACTION_P(RunClosure, closure) {
16 closure.Run(); 16 closure.Run();
17 } 17 }
18 18
19 class SilentSinkSuspenderTest : public testing::Test { 19 class SilentSinkSuspenderTest : public testing::Test {
20 public: 20 public:
21 SilentSinkSuspenderTest() 21 SilentSinkSuspenderTest()
22 : params_(AudioParameters::AUDIO_FAKE, 22 : params_(AudioParameters::AUDIO_FAKE,
23 CHANNEL_LAYOUT_MONO, 23 CHANNEL_LAYOUT_MONO,
24 44100, 24 44100,
25 8, 25 8,
26 128), 26 128),
27 mock_sink_(new testing::StrictMock<MockAudioRendererSink>()), 27 mock_sink_(new testing::StrictMock<MockAudioRendererSink>()),
28 fake_callback_(0.1), 28 fake_callback_(0.1, params_.sample_rate()),
29 temp_bus_(AudioBus::Create(params_)), 29 temp_bus_(AudioBus::Create(params_)),
30 // Set a negative timeout so any silence will suspend immediately. 30 // Set a negative timeout so any silence will suspend immediately.
31 suspender_(&fake_callback_, 31 suspender_(&fake_callback_,
32 base::TimeDelta::FromSeconds(-1), 32 base::TimeDelta::FromSeconds(-1),
33 params_, 33 params_,
34 mock_sink_, 34 mock_sink_,
35 test_loop_.task_runner()) {} 35 test_loop_.task_runner()) {}
36 ~SilentSinkSuspenderTest() override {} 36 ~SilentSinkSuspenderTest() override {}
37 37
38 protected: 38 protected:
39 base::TestMessageLoop test_loop_; 39 base::TestMessageLoop test_loop_;
40 const AudioParameters params_; 40 const AudioParameters params_;
41 scoped_refptr<testing::StrictMock<MockAudioRendererSink>> mock_sink_; 41 scoped_refptr<testing::StrictMock<MockAudioRendererSink>> mock_sink_;
42 FakeAudioRenderCallback fake_callback_; 42 FakeAudioRenderCallback fake_callback_;
43 std::unique_ptr<AudioBus> temp_bus_; 43 std::unique_ptr<AudioBus> temp_bus_;
44 SilentSinkSuspender suspender_; 44 SilentSinkSuspender suspender_;
45 45
46 private: 46 private:
47 DISALLOW_COPY_AND_ASSIGN(SilentSinkSuspenderTest); 47 DISALLOW_COPY_AND_ASSIGN(SilentSinkSuspenderTest);
48 }; 48 };
49 49
50 TEST_F(SilentSinkSuspenderTest, BasicPassthough) { 50 TEST_F(SilentSinkSuspenderTest, BasicPassthough) {
51 temp_bus_->Zero(); 51 temp_bus_->Zero();
52 auto delay = base::TimeDelta::FromMilliseconds(20);
52 EXPECT_EQ(temp_bus_->frames(), 53 EXPECT_EQ(temp_bus_->frames(),
53 suspender_.Render(base::TimeDelta(), base::TimeTicks(), 0, 54 suspender_.Render(delay, base::TimeTicks(), 0, temp_bus_.get()));
54 temp_bus_.get())); 55
56 // Delay should remain.
57 EXPECT_EQ(delay, fake_callback_.last_delay());
55 EXPECT_FALSE(temp_bus_->AreFramesZero()); 58 EXPECT_FALSE(temp_bus_->AreFramesZero());
56 } 59 }
57 60
58 TEST_F(SilentSinkSuspenderTest, SuspendResumeTriggered) { 61 TEST_F(SilentSinkSuspenderTest, SuspendResumeTriggered) {
59 // Verify a normal Render() doesn't invoke suspend. 62 // Verify a normal Render() doesn't invoke suspend.
60 EXPECT_FALSE(suspender_.is_using_fake_sink_for_testing()); 63 EXPECT_FALSE(suspender_.is_using_fake_sink_for_testing());
61 temp_bus_->Zero(); 64 temp_bus_->Zero();
62 EXPECT_EQ(temp_bus_->frames(), 65 EXPECT_EQ(temp_bus_->frames(),
63 suspender_.Render(base::TimeDelta(), base::TimeTicks(), 0, 66 suspender_.Render(base::TimeDelta(), base::TimeTicks(), 0,
64 temp_bus_.get())); 67 temp_bus_.get()));
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 0); 179 0);
177 EXPECT_EQ(temp_bus_->frames(), 180 EXPECT_EQ(temp_bus_->frames(),
178 suspender_.Render(base::TimeDelta(), base::TimeTicks(), 0, 181 suspender_.Render(base::TimeDelta(), base::TimeTicks(), 0,
179 temp_bus_.get())); 182 temp_bus_.get()));
180 EXPECT_EQ(memcmp(temp_bus_->channel(0), true_bus2->channel(0), 183 EXPECT_EQ(memcmp(temp_bus_->channel(0), true_bus2->channel(0),
181 temp_bus_->frames() * sizeof(float)), 184 temp_bus_->frames() * sizeof(float)),
182 0); 185 0);
183 } 186 }
184 187
185 } // namespace content 188 } // namespace content
OLDNEW
« no previous file with comments | « media/base/silent_sink_suspender.cc ('k') | media/blink/webaudiosourceprovider_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698