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

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

Issue 2865113007: Remove ScopedVector from media/base/ (Closed)
Patch Set: Created 3 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/multi_channel_resampler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/base/text_renderer.h" 5 #include "media/base/text_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
xhwang 2017/05/10 17:24:48 #include "base/memory/ptr_util.h"
Chandan 2017/05/11 06:04:04 Done.
15 #include "base/memory/scoped_vector.h"
16 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 16 #include "base/run_loop.h"
18 #include "media/base/audio_decoder_config.h" 17 #include "media/base/audio_decoder_config.h"
19 #include "media/base/decoder_buffer.h" 18 #include "media/base/decoder_buffer.h"
20 #include "media/base/demuxer_stream.h" 19 #include "media/base/demuxer_stream.h"
21 #include "media/base/fake_text_track_stream.h" 20 #include "media/base/fake_text_track_stream.h"
22 #include "media/base/text_track_config.h" 21 #include "media/base/text_track_config.h"
23 #include "media/base/video_decoder_config.h" 22 #include "media/base/video_decoder_config.h"
24 #include "media/filters/webvtt_util.h" 23 #include "media/filters/webvtt_util.h"
25 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 void Destroy() { 69 void Destroy() {
71 text_renderer_.reset(); 70 text_renderer_.reset();
72 base::RunLoop().RunUntilIdle(); 71 base::RunLoop().RunUntilIdle();
73 } 72 }
74 73
75 void AddTextTrack(TextKind kind, 74 void AddTextTrack(TextKind kind,
76 const std::string& name, 75 const std::string& name,
77 const std::string& language, 76 const std::string& language,
78 bool expect_read) { 77 bool expect_read) {
79 const size_t idx = text_track_streams_.size(); 78 const size_t idx = text_track_streams_.size();
80 text_track_streams_.push_back(new FakeTextTrackStream); 79 text_track_streams_.push_back(base::MakeUnique<FakeTextTrackStream>());
81 80
82 if (expect_read) 81 if (expect_read)
83 ExpectRead(idx); 82 ExpectRead(idx);
84 83
85 const TextTrackConfig config(kind, name, language, std::string()); 84 const TextTrackConfig config(kind, name, language, std::string());
86 text_renderer_->AddTextStream(text_track_streams_.back(), config); 85 text_renderer_->AddTextStream(text_track_streams_.back().get(), config);
87 base::RunLoop().RunUntilIdle(); 86 base::RunLoop().RunUntilIdle();
88 87
89 EXPECT_EQ(text_tracks_.size(), text_track_streams_.size()); 88 EXPECT_EQ(text_tracks_.size(), text_track_streams_.size());
90 FakeTextTrack* const text_track = text_tracks_.back(); 89 FakeTextTrack* const text_track = text_tracks_.back();
91 EXPECT_TRUE(text_track); 90 EXPECT_TRUE(text_track);
92 EXPECT_TRUE(text_track->config_.Matches(config)); 91 EXPECT_TRUE(text_track->config_.Matches(config));
93 } 92 }
94 93
95 void OnAddTextTrack(const TextTrackConfig& config, 94 void OnAddTextTrack(const TextTrackConfig& config,
96 const AddTextTrackDoneCB& done_cb) { 95 const AddTextTrackDoneCB& done_cb) {
97 base::Closure destroy_cb = 96 base::Closure destroy_cb =
98 base::Bind(&TextRendererTest::OnDestroyTextTrack, 97 base::Bind(&TextRendererTest::OnDestroyTextTrack,
99 base::Unretained(this), 98 base::Unretained(this),
100 text_tracks_.size()); 99 text_tracks_.size());
101 // Text track objects are owned by the text renderer, but we cache them 100 // Text track objects are owned by the text renderer, but we cache them
102 // here so we can inspect them. They get removed from our cache when the 101 // here so we can inspect them. They get removed from our cache when the
103 // text renderer deallocates them. 102 // text renderer deallocates them.
104 text_tracks_.push_back(new FakeTextTrack(destroy_cb, config)); 103 text_tracks_.push_back(new FakeTextTrack(destroy_cb, config));
105 std::unique_ptr<TextTrack> text_track(text_tracks_.back()); 104 std::unique_ptr<TextTrack> text_track(text_tracks_.back());
106 done_cb.Run(std::move(text_track)); 105 done_cb.Run(std::move(text_track));
107 } 106 }
108 107
109 void RemoveTextTrack(unsigned idx) { 108 void RemoveTextTrack(unsigned idx) {
110 FakeTextTrackStream* const stream = text_track_streams_[idx]; 109 FakeTextTrackStream* const stream = text_track_streams_[idx].get();
111 text_renderer_->RemoveTextStream(stream); 110 text_renderer_->RemoveTextStream(stream);
112 EXPECT_FALSE(text_tracks_[idx]); 111 EXPECT_FALSE(text_tracks_[idx]);
113 } 112 }
114 113
115 void SatisfyPendingReads(const base::TimeDelta& start, 114 void SatisfyPendingReads(const base::TimeDelta& start,
116 const base::TimeDelta& duration, 115 const base::TimeDelta& duration,
117 const std::string& id, 116 const std::string& id,
118 const std::string& content, 117 const std::string& content,
119 const std::string& settings) { 118 const std::string& settings) {
120 for (TextTrackStreams::iterator itr = text_track_streams_.begin(); 119 for (TextTrackStreams::iterator itr = text_track_streams_.begin();
121 itr != text_track_streams_.end(); ++itr) { 120 itr != text_track_streams_.end(); ++itr) {
122 (*itr)->SatisfyPendingRead(start, duration, id, content, settings); 121 (*itr)->SatisfyPendingRead(start, duration, id, content, settings);
123 } 122 }
124 } 123 }
125 124
126 void AbortPendingRead(unsigned idx) { 125 void AbortPendingRead(unsigned idx) {
127 FakeTextTrackStream* const stream = text_track_streams_[idx]; 126 FakeTextTrackStream* const stream = text_track_streams_[idx].get();
128 stream->AbortPendingRead(); 127 stream->AbortPendingRead();
129 base::RunLoop().RunUntilIdle(); 128 base::RunLoop().RunUntilIdle();
130 } 129 }
131 130
132 void AbortPendingReads() { 131 void AbortPendingReads() {
133 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { 132 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) {
134 AbortPendingRead(idx); 133 AbortPendingRead(idx);
135 } 134 }
136 } 135 }
137 136
138 void SendEosNotification(unsigned idx) { 137 void SendEosNotification(unsigned idx) {
139 FakeTextTrackStream* const stream = text_track_streams_[idx]; 138 FakeTextTrackStream* const stream = text_track_streams_[idx].get();
140 stream->SendEosNotification(); 139 stream->SendEosNotification();
141 base::RunLoop().RunUntilIdle(); 140 base::RunLoop().RunUntilIdle();
142 } 141 }
143 142
144 void SendEosNotifications() { 143 void SendEosNotifications() {
145 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { 144 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) {
146 SendEosNotification(idx); 145 SendEosNotification(idx);
147 } 146 }
148 } 147 }
149 148
150 void SendCue(unsigned idx, bool expect_cue) { 149 void SendCue(unsigned idx, bool expect_cue) {
151 FakeTextTrackStream* const text_stream = text_track_streams_[idx]; 150 FakeTextTrackStream* const text_stream = text_track_streams_[idx].get();
152 151
153 const base::TimeDelta start; 152 const base::TimeDelta start;
154 const base::TimeDelta duration = base::TimeDelta::FromSeconds(42); 153 const base::TimeDelta duration = base::TimeDelta::FromSeconds(42);
155 const std::string id = "id"; 154 const std::string id = "id";
156 const std::string content = "subtitle"; 155 const std::string content = "subtitle";
157 const std::string settings; 156 const std::string settings;
158 157
159 if (expect_cue) { 158 if (expect_cue) {
160 FakeTextTrack* const text_track = text_tracks_[idx]; 159 FakeTextTrack* const text_track = text_tracks_[idx];
161 EXPECT_CALL(*text_track, addWebVTTCue(start, 160 EXPECT_CALL(*text_track, addWebVTTCue(start,
(...skipping 27 matching lines...) Expand all
189 base::RunLoop().RunUntilIdle(); 188 base::RunLoop().RunUntilIdle();
190 } 189 }
191 190
192 void Flush() { 191 void Flush() {
193 EXPECT_CALL(*this, OnFlush()); 192 EXPECT_CALL(*this, OnFlush());
194 text_renderer_->Flush(base::Bind(&TextRendererTest::OnFlush, 193 text_renderer_->Flush(base::Bind(&TextRendererTest::OnFlush,
195 base::Unretained(this))); 194 base::Unretained(this)));
196 } 195 }
197 196
198 void ExpectRead(size_t idx) { 197 void ExpectRead(size_t idx) {
199 FakeTextTrackStream* const stream = text_track_streams_[idx]; 198 FakeTextTrackStream* const stream = text_track_streams_[idx].get();
200 EXPECT_CALL(*stream, OnRead()); 199 EXPECT_CALL(*stream, OnRead());
201 } 200 }
202 201
203 MOCK_METHOD0(OnEnd, void()); 202 MOCK_METHOD0(OnEnd, void());
204 MOCK_METHOD0(OnPause, void()); 203 MOCK_METHOD0(OnPause, void());
205 MOCK_METHOD0(OnFlush, void()); 204 MOCK_METHOD0(OnFlush, void());
206 205
207 base::MessageLoop message_loop_; 206 base::MessageLoop message_loop_;
208 207
209 typedef ScopedVector<FakeTextTrackStream> TextTrackStreams; 208 typedef std::vector<std::unique_ptr<FakeTextTrackStream>> TextTrackStreams;
210 TextTrackStreams text_track_streams_; 209 TextTrackStreams text_track_streams_;
211 210
212 typedef std::vector<FakeTextTrack*> TextTracks; 211 typedef std::vector<FakeTextTrack*> TextTracks;
213 TextTracks text_tracks_; 212 TextTracks text_tracks_;
214 213
215 std::unique_ptr<TextRenderer> text_renderer_; 214 std::unique_ptr<TextRenderer> text_renderer_;
216 215
217 private: 216 private:
218 DISALLOW_COPY_AND_ASSIGN(TextRendererTest); 217 DISALLOW_COPY_AND_ASSIGN(TextRendererTest);
219 }; 218 };
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 Play(); 1205 Play();
1207 AbortPendingRead(0); 1206 AbortPendingRead(0);
1208 RemoveTextTrack(0); 1207 RemoveTextTrack(0);
1209 EXPECT_TRUE(text_renderer_->HasTracks()); 1208 EXPECT_TRUE(text_renderer_->HasTracks());
1210 Pause(); 1209 Pause();
1211 EXPECT_CALL(*this, OnPause()); 1210 EXPECT_CALL(*this, OnPause());
1212 SendEosNotification(1); 1211 SendEosNotification(1);
1213 } 1212 }
1214 1213
1215 } // namespace media 1214 } // namespace media
OLDNEW
« no previous file with comments | « media/base/multi_channel_resampler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698