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

Side by Side Diff: webkit/media/buffered_data_source_unittest.cc

Issue 10451049: Track buffered byte ranges correctly in media::Pipeline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « webkit/media/buffered_data_source.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "media/base/media_log.h" 7 #include "media/base/media_log.h"
8 #include "media/base/mock_callback.h" 8 #include "media/base/mock_callback.h"
9 #include "media/base/mock_data_source_host.h" 9 #include "media/base/mock_data_source_host.h"
10 #include "media/base/mock_filters.h" 10 #include "media/base/mock_filters.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 data_source_->Initialize(response_generator_.gurl(), 99 data_source_->Initialize(response_generator_.gurl(),
100 media::NewExpectedStatusCB(expected)); 100 media::NewExpectedStatusCB(expected));
101 message_loop_.RunAllPending(); 101 message_loop_.RunAllPending();
102 } 102 }
103 103
104 // Helper to initialize tests with a valid 206 response. 104 // Helper to initialize tests with a valid 206 response.
105 void InitializeWith206Response() { 105 void InitializeWith206Response() {
106 Initialize(media::PIPELINE_OK); 106 Initialize(media::PIPELINE_OK);
107 107
108 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 108 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()));
109 EXPECT_CALL(host_, SetBufferedBytes(0));
110 Respond(response_generator_.Generate206(0)); 109 Respond(response_generator_.Generate206(0));
111 } 110 }
112 111
113 // Stops any active loaders and shuts down the data source. 112 // Stops any active loaders and shuts down the data source.
114 // 113 //
115 // This typically happens when the page is closed and for our purposes is 114 // This typically happens when the page is closed and for our purposes is
116 // appropriate to do when tearing down a test. 115 // appropriate to do when tearing down a test.
117 void Stop() { 116 void Stop() {
118 if (data_source_->loading()) { 117 if (data_source_->loading()) {
119 loader()->didFail(url_loader(), response_generator_.GenerateError()); 118 loader()->didFail(url_loader(), response_generator_.GenerateError());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // Used for calling BufferedResourceLoader::didReceiveData(). 189 // Used for calling BufferedResourceLoader::didReceiveData().
191 char data_[kDataSize]; 190 char data_[kDataSize];
192 191
193 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); 192 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest);
194 }; 193 };
195 194
196 TEST_F(BufferedDataSourceTest, Range_Supported) { 195 TEST_F(BufferedDataSourceTest, Range_Supported) {
197 Initialize(media::PIPELINE_OK); 196 Initialize(media::PIPELINE_OK);
198 197
199 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 198 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()));
200 EXPECT_CALL(host_, SetBufferedBytes(0));
201 Respond(response_generator_.Generate206(0)); 199 Respond(response_generator_.Generate206(0));
202 200
203 EXPECT_TRUE(data_source_->loading()); 201 EXPECT_TRUE(data_source_->loading());
204 EXPECT_FALSE(data_source_->IsStreaming()); 202 EXPECT_FALSE(data_source_->IsStreaming());
205 Stop(); 203 Stop();
206 } 204 }
207 205
208 TEST_F(BufferedDataSourceTest, Range_InstanceSizeUnknown) { 206 TEST_F(BufferedDataSourceTest, Range_InstanceSizeUnknown) {
209 Initialize(media::PIPELINE_OK); 207 Initialize(media::PIPELINE_OK);
210 208
211 EXPECT_CALL(host_, SetBufferedBytes(0));
212 Respond(response_generator_.Generate206( 209 Respond(response_generator_.Generate206(
213 0, TestResponseGenerator::kNoContentRangeInstanceSize)); 210 0, TestResponseGenerator::kNoContentRangeInstanceSize));
214 211
215 EXPECT_TRUE(data_source_->loading()); 212 EXPECT_TRUE(data_source_->loading());
216 EXPECT_TRUE(data_source_->IsStreaming()); 213 EXPECT_TRUE(data_source_->IsStreaming());
217 Stop(); 214 Stop();
218 } 215 }
219 216
220 TEST_F(BufferedDataSourceTest, Range_NotFound) { 217 TEST_F(BufferedDataSourceTest, Range_NotFound) {
221 Initialize(media::PIPELINE_ERROR_NETWORK); 218 Initialize(media::PIPELINE_ERROR_NETWORK);
222 Respond(response_generator_.Generate404()); 219 Respond(response_generator_.Generate404());
223 220
224 EXPECT_FALSE(data_source_->loading()); 221 EXPECT_FALSE(data_source_->loading());
225 Stop(); 222 Stop();
226 } 223 }
227 224
228 TEST_F(BufferedDataSourceTest, Range_NotSupported) { 225 TEST_F(BufferedDataSourceTest, Range_NotSupported) {
229 Initialize(media::PIPELINE_OK); 226 Initialize(media::PIPELINE_OK);
230 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 227 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()));
231 EXPECT_CALL(host_, SetBufferedBytes(0));
232 Respond(response_generator_.Generate200()); 228 Respond(response_generator_.Generate200());
233 229
234 EXPECT_TRUE(data_source_->loading()); 230 EXPECT_TRUE(data_source_->loading());
235 EXPECT_TRUE(data_source_->IsStreaming()); 231 EXPECT_TRUE(data_source_->IsStreaming());
236 Stop(); 232 Stop();
237 } 233 }
238 234
239 // Special carve-out for Apache versions that choose to return a 200 for 235 // Special carve-out for Apache versions that choose to return a 200 for
240 // Range:0- ("because it's more efficient" than a 206) 236 // Range:0- ("because it's more efficient" than a 206)
241 TEST_F(BufferedDataSourceTest, Range_SupportedButReturned200) { 237 TEST_F(BufferedDataSourceTest, Range_SupportedButReturned200) {
242 Initialize(media::PIPELINE_OK); 238 Initialize(media::PIPELINE_OK);
243 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 239 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()));
244 EXPECT_CALL(host_, SetBufferedBytes(0));
245 WebURLResponse response = response_generator_.Generate200(); 240 WebURLResponse response = response_generator_.Generate200();
246 response.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"), 241 response.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"),
247 WebString::fromUTF8("bytes")); 242 WebString::fromUTF8("bytes"));
248 Respond(response); 243 Respond(response);
249 244
250 EXPECT_TRUE(data_source_->loading()); 245 EXPECT_TRUE(data_source_->loading());
251 EXPECT_FALSE(data_source_->IsStreaming()); 246 EXPECT_FALSE(data_source_->IsStreaming());
252 Stop(); 247 Stop();
253 } 248 }
254 249
255 TEST_F(BufferedDataSourceTest, Range_MissingContentRange) { 250 TEST_F(BufferedDataSourceTest, Range_MissingContentRange) {
256 Initialize(media::PIPELINE_ERROR_NETWORK); 251 Initialize(media::PIPELINE_ERROR_NETWORK);
257 Respond(response_generator_.Generate206( 252 Respond(response_generator_.Generate206(
258 0, TestResponseGenerator::kNoContentRange)); 253 0, TestResponseGenerator::kNoContentRange));
259 254
260 EXPECT_FALSE(data_source_->loading()); 255 EXPECT_FALSE(data_source_->loading());
261 Stop(); 256 Stop();
262 } 257 }
263 258
264 TEST_F(BufferedDataSourceTest, Range_MissingContentLength) { 259 TEST_F(BufferedDataSourceTest, Range_MissingContentLength) {
265 Initialize(media::PIPELINE_OK); 260 Initialize(media::PIPELINE_OK);
266 261
267 // It'll manage without a Content-Length response. 262 // It'll manage without a Content-Length response.
268 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 263 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()));
269 EXPECT_CALL(host_, SetBufferedBytes(0));
270 Respond(response_generator_.Generate206( 264 Respond(response_generator_.Generate206(
271 0, TestResponseGenerator::kNoContentLength)); 265 0, TestResponseGenerator::kNoContentLength));
272 266
273 EXPECT_TRUE(data_source_->loading()); 267 EXPECT_TRUE(data_source_->loading());
274 EXPECT_FALSE(data_source_->IsStreaming()); 268 EXPECT_FALSE(data_source_->IsStreaming());
275 Stop(); 269 Stop();
276 } 270 }
277 271
278 TEST_F(BufferedDataSourceTest, Range_WrongContentRange) { 272 TEST_F(BufferedDataSourceTest, Range_WrongContentRange) {
279 Initialize(media::PIPELINE_ERROR_NETWORK); 273 Initialize(media::PIPELINE_ERROR_NETWORK);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // Read so far ahead to cause the loader to get recreated. 390 // Read so far ahead to cause the loader to get recreated.
397 BufferedResourceLoader* old_loader = loader(); 391 BufferedResourceLoader* old_loader = loader();
398 ExpectCreateResourceLoader(); 392 ExpectCreateResourceLoader();
399 ReadAt(kFarReadPosition); 393 ReadAt(kFarReadPosition);
400 Respond(response_generator_.Generate206(kFarReadPosition)); 394 Respond(response_generator_.Generate206(kFarReadPosition));
401 395
402 // Verify loader changed but still has same bitrate. 396 // Verify loader changed but still has same bitrate.
403 EXPECT_NE(old_loader, loader()); 397 EXPECT_NE(old_loader, loader());
404 EXPECT_EQ(1234, loader_bitrate()); 398 EXPECT_EQ(1234, loader_bitrate());
405 399
406 // During teardown we'll also report our final network status.
407 EXPECT_CALL(host_, SetBufferedBytes(4000000));
408
409 EXPECT_TRUE(data_source_->loading()); 400 EXPECT_TRUE(data_source_->loading());
410 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 401 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
411 Stop(); 402 Stop();
412 } 403 }
413 404
414 TEST_F(BufferedDataSourceTest, SetPlaybackRate) { 405 TEST_F(BufferedDataSourceTest, SetPlaybackRate) {
415 InitializeWith206Response(); 406 InitializeWith206Response();
416 407
417 data_source_->SetPlaybackRate(2.0f); 408 data_source_->SetPlaybackRate(2.0f);
418 message_loop_.RunAllPending(); 409 message_loop_.RunAllPending();
419 EXPECT_EQ(2.0f, data_source_playback_rate()); 410 EXPECT_EQ(2.0f, data_source_playback_rate());
420 EXPECT_EQ(2.0f, loader_playback_rate()); 411 EXPECT_EQ(2.0f, loader_playback_rate());
421 412
422 // Read so far ahead to cause the loader to get recreated. 413 // Read so far ahead to cause the loader to get recreated.
423 BufferedResourceLoader* old_loader = loader(); 414 BufferedResourceLoader* old_loader = loader();
424 ExpectCreateResourceLoader(); 415 ExpectCreateResourceLoader();
425 ReadAt(kFarReadPosition); 416 ReadAt(kFarReadPosition);
426 Respond(response_generator_.Generate206(kFarReadPosition)); 417 Respond(response_generator_.Generate206(kFarReadPosition));
427 418
428 // Verify loader changed but still has same playback rate. 419 // Verify loader changed but still has same playback rate.
429 EXPECT_NE(old_loader, loader()); 420 EXPECT_NE(old_loader, loader());
430 421
431 // During teardown we'll also report our final network status.
432 EXPECT_CALL(host_, SetBufferedBytes(4000000));
433
434 EXPECT_TRUE(data_source_->loading()); 422 EXPECT_TRUE(data_source_->loading());
435 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 423 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
436 Stop(); 424 Stop();
437 } 425 }
438 426
439 TEST_F(BufferedDataSourceTest, Read) { 427 TEST_F(BufferedDataSourceTest, Read) {
440 InitializeWith206Response(); 428 InitializeWith206Response();
441 429
442 ReadAt(0); 430 ReadAt(0);
443 431
444 // When the read completes we'll update our network status. 432 // When the read completes we'll update our network status.
445 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); 433 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
446 EXPECT_CALL(host_, SetNetworkActivity(true)); 434 EXPECT_CALL(host_, SetNetworkActivity(true));
447 EXPECT_CALL(*this, ReadCallback(kDataSize)); 435 EXPECT_CALL(*this, ReadCallback(kDataSize));
448 FinishRead(); 436 FinishRead();
449 437
450 // During teardown we'll also report our final network status. 438 // During teardown we'll also report our final network status.
451 EXPECT_CALL(host_, SetNetworkActivity(false)); 439 EXPECT_CALL(host_, SetNetworkActivity(false));
452 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); 440 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
453 441
454 EXPECT_TRUE(data_source_->loading()); 442 EXPECT_TRUE(data_source_->loading());
455 Stop(); 443 Stop();
456 } 444 }
457 445
458 } // namespace webkit_media 446 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/buffered_data_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698