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

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

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: android Created 4 years, 7 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 | « media/base/null_video_sink.h ('k') | media/base/pipeline.h » ('j') | 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 <memory>
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
7 #include "base/macros.h" 9 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/test/simple_test_tick_clock.h" 11 #include "base/test/simple_test_tick_clock.h"
10 #include "media/base/null_video_sink.h" 12 #include "media/base/null_video_sink.h"
11 #include "media/base/test_helpers.h" 13 #include "media/base/test_helpers.h"
12 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 using testing::_; 17 using testing::_;
16 using testing::DoAll; 18 using testing::DoAll;
17 using testing::Return; 19 using testing::Return;
18 20
19 namespace media { 21 namespace media {
20 22
21 ACTION_P(RunClosure, closure) { 23 ACTION_P(RunClosure, closure) {
22 closure.Run(); 24 closure.Run();
23 } 25 }
24 26
25 class NullVideoSinkTest : public testing::Test, 27 class NullVideoSinkTest : public testing::Test,
26 public VideoRendererSink::RenderCallback { 28 public VideoRendererSink::RenderCallback {
27 public: 29 public:
28 NullVideoSinkTest() { 30 NullVideoSinkTest() {
29 // Never use null TimeTicks since they have special connotations. 31 // Never use null TimeTicks since they have special connotations.
30 tick_clock_.Advance(base::TimeDelta::FromMicroseconds(12345)); 32 tick_clock_.Advance(base::TimeDelta::FromMicroseconds(12345));
31 } 33 }
32 ~NullVideoSinkTest() override {} 34 ~NullVideoSinkTest() override {}
33 35
34 scoped_ptr<NullVideoSink> ConstructSink(bool clockless, 36 std::unique_ptr<NullVideoSink> ConstructSink(bool clockless,
35 base::TimeDelta interval) { 37 base::TimeDelta interval) {
36 scoped_ptr<NullVideoSink> new_sink(new NullVideoSink( 38 std::unique_ptr<NullVideoSink> new_sink(new NullVideoSink(
37 clockless, interval, 39 clockless, interval,
38 base::Bind(&NullVideoSinkTest::FrameReceived, base::Unretained(this)), 40 base::Bind(&NullVideoSinkTest::FrameReceived, base::Unretained(this)),
39 message_loop_.task_runner())); 41 message_loop_.task_runner()));
40 new_sink->set_tick_clock_for_testing(&tick_clock_); 42 new_sink->set_tick_clock_for_testing(&tick_clock_);
41 return new_sink; 43 return new_sink;
42 } 44 }
43 45
44 scoped_refptr<VideoFrame> CreateFrame(base::TimeDelta timestamp) { 46 scoped_refptr<VideoFrame> CreateFrame(base::TimeDelta timestamp) {
45 const gfx::Size natural_size(8, 8); 47 const gfx::Size natural_size(8, 8);
46 return VideoFrame::CreateFrame(PIXEL_FORMAT_YV12, natural_size, 48 return VideoFrame::CreateFrame(PIXEL_FORMAT_YV12, natural_size,
(...skipping 13 matching lines...) Expand all
60 protected: 62 protected:
61 base::MessageLoop message_loop_; 63 base::MessageLoop message_loop_;
62 base::SimpleTestTickClock tick_clock_; 64 base::SimpleTestTickClock tick_clock_;
63 65
64 DISALLOW_COPY_AND_ASSIGN(NullVideoSinkTest); 66 DISALLOW_COPY_AND_ASSIGN(NullVideoSinkTest);
65 }; 67 };
66 68
67 TEST_F(NullVideoSinkTest, BasicFunctionality) { 69 TEST_F(NullVideoSinkTest, BasicFunctionality) {
68 const base::TimeDelta kInterval = base::TimeDelta::FromMilliseconds(25); 70 const base::TimeDelta kInterval = base::TimeDelta::FromMilliseconds(25);
69 71
70 scoped_ptr<NullVideoSink> sink = ConstructSink(false, kInterval); 72 std::unique_ptr<NullVideoSink> sink = ConstructSink(false, kInterval);
71 scoped_refptr<VideoFrame> test_frame = CreateFrame(base::TimeDelta()); 73 scoped_refptr<VideoFrame> test_frame = CreateFrame(base::TimeDelta());
72 74
73 // The sink shouldn't have to be started to use the paint method. 75 // The sink shouldn't have to be started to use the paint method.
74 EXPECT_CALL(*this, FrameReceived(test_frame)); 76 EXPECT_CALL(*this, FrameReceived(test_frame));
75 sink->PaintFrameUsingOldRenderingPath(test_frame); 77 sink->PaintFrameUsingOldRenderingPath(test_frame);
76 78
77 { 79 {
78 SCOPED_TRACE("Waiting for sink startup."); 80 SCOPED_TRACE("Waiting for sink startup.");
79 sink->Start(this); 81 sink->Start(this);
80 const base::TimeTicks current_time = tick_clock_.NowTicks(); 82 const base::TimeTicks current_time = tick_clock_.NowTicks();
(...skipping 29 matching lines...) Expand all
110 WaitableMessageLoopEvent event; 112 WaitableMessageLoopEvent event;
111 sink->set_stop_cb(event.GetClosure()); 113 sink->set_stop_cb(event.GetClosure());
112 sink->Stop(); 114 sink->Stop();
113 event.RunAndWait(); 115 event.RunAndWait();
114 } 116 }
115 } 117 }
116 118
117 TEST_F(NullVideoSinkTest, ClocklessFunctionality) { 119 TEST_F(NullVideoSinkTest, ClocklessFunctionality) {
118 // Construct the sink with a huge interval, it should still complete quickly. 120 // Construct the sink with a huge interval, it should still complete quickly.
119 const base::TimeDelta interval = base::TimeDelta::FromSeconds(10); 121 const base::TimeDelta interval = base::TimeDelta::FromSeconds(10);
120 scoped_ptr<NullVideoSink> sink = ConstructSink(true, interval); 122 std::unique_ptr<NullVideoSink> sink = ConstructSink(true, interval);
121 123
122 scoped_refptr<VideoFrame> test_frame = CreateFrame(base::TimeDelta()); 124 scoped_refptr<VideoFrame> test_frame = CreateFrame(base::TimeDelta());
123 sink->Start(this); 125 sink->Start(this);
124 126
125 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(1); 127 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(1);
126 EXPECT_CALL(*this, FrameReceived(scoped_refptr<VideoFrame>())).Times(1); 128 EXPECT_CALL(*this, FrameReceived(scoped_refptr<VideoFrame>())).Times(1);
127 129
128 const int kTestRuns = 6; 130 const int kTestRuns = 6;
129 const base::TimeTicks now = base::TimeTicks::Now(); 131 const base::TimeTicks now = base::TimeTicks::Now();
130 const base::TimeTicks current_time = tick_clock_.NowTicks(); 132 const base::TimeTicks current_time = tick_clock_.NowTicks();
(...skipping 10 matching lines...) Expand all
141 current_time + (i + 1) * interval, false)) 143 current_time + (i + 1) * interval, false))
142 .WillOnce(DoAll(RunClosure(event.GetClosure()), Return(nullptr))); 144 .WillOnce(DoAll(RunClosure(event.GetClosure()), Return(nullptr)));
143 } 145 }
144 } 146 }
145 event.RunAndWait(); 147 event.RunAndWait();
146 ASSERT_LT(base::TimeTicks::Now() - now, kTestRuns * interval); 148 ASSERT_LT(base::TimeTicks::Now() - now, kTestRuns * interval);
147 sink->Stop(); 149 sink->Stop();
148 } 150 }
149 151
150 } // namespace media 152 } // namespace media
OLDNEW
« no previous file with comments | « media/base/null_video_sink.h ('k') | media/base/pipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698