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

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

Issue 10698139: Write file:// tests for BufferedDataSource and fix some bugs as a result. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: remove buffered_bytes_ Created 8 years, 5 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
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Whether the resource load has starting loading but yet to been cancelled. 79 // Whether the resource load has starting loading but yet to been cancelled.
80 bool loading_; 80 bool loading_;
81 81
82 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource); 82 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource);
83 }; 83 };
84 84
85 static const int64 kFileSize = 5000000; 85 static const int64 kFileSize = 5000000;
86 static const int64 kFarReadPosition = 4000000; 86 static const int64 kFarReadPosition = 4000000;
87 static const int kDataSize = 1024; 87 static const int kDataSize = 1024;
88 88
89 static const char kHttpUrl[] = "http://localhost/foo.webm";
90 static const char kFileUrl[] = "file:///tmp/bar.webm";
91
89 class BufferedDataSourceTest : public testing::Test { 92 class BufferedDataSourceTest : public testing::Test {
90 public: 93 public:
91 BufferedDataSourceTest() 94 BufferedDataSourceTest()
92 : response_generator_(GURL("http://localhost/foo.webm"), kFileSize), 95 : view_(WebView::create(NULL)) {
93 view_(WebView::create(NULL)) {
94 view_->initializeMainFrame(&client_); 96 view_->initializeMainFrame(&client_);
95 97
96 data_source_ = new MockBufferedDataSource(&message_loop_, 98 data_source_ = new MockBufferedDataSource(&message_loop_,
97 view_->mainFrame()); 99 view_->mainFrame());
98 data_source_->set_host(&host_); 100 data_source_->set_host(&host_);
99 } 101 }
100 102
101 virtual ~BufferedDataSourceTest() { 103 virtual ~BufferedDataSourceTest() {
102 view_->close(); 104 view_->close();
103 } 105 }
104 106
105 void Initialize(media::PipelineStatus expected) { 107 void Initialize(const char* url, media::PipelineStatus expected) {
108 response_generator_.reset(new TestResponseGenerator(GURL(url), kFileSize));
109
106 ExpectCreateResourceLoader(); 110 ExpectCreateResourceLoader();
107 111 data_source_->Initialize(response_generator_->gurl(),
108 EXPECT_FALSE(data_source_->downloading());
109 data_source_->Initialize(response_generator_.gurl(),
110 BufferedResourceLoader::kUnspecified, 112 BufferedResourceLoader::kUnspecified,
111 media::NewExpectedStatusCB(expected)); 113 media::NewExpectedStatusCB(expected));
112 message_loop_.RunAllPending(); 114 message_loop_.RunAllPending();
113 EXPECT_TRUE(data_source_->downloading());
114 } 115 }
115 116
116 // Helper to initialize tests with a valid 206 response. 117 // Helper to initialize tests with a valid HTTP 206 response.
Ami GONE FROM CHROMIUM 2012/07/11 00:51:54 no such thing as a non-HTTP 206, so change doesn't
scherkus (not reviewing) 2012/07/11 01:10:56 Done.
117 void InitializeWith206Response() { 118 void InitializeWith206Response() {
118 Initialize(media::PIPELINE_OK); 119 Initialize(kHttpUrl, media::PIPELINE_OK);
120 EXPECT_TRUE(data_source_->downloading());
Ami GONE FROM CHROMIUM 2012/07/11 00:51:54 could move this back to Initialize as EXPECT_EQ(da
scherkus (not reviewing) 2012/07/11 01:10:56 I'll do it but duplicating the SchemeIs() code her
119 121
120 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 122 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
121 Respond(response_generator_.Generate206(0)); 123 Respond(response_generator_->Generate206(0));
124 }
125
126 // Helper to initialize tests with a valid file:// response.
127 void InitializeWithFileResponse() {
128 Initialize(kFileUrl, media::PIPELINE_OK);
129 EXPECT_FALSE(data_source_->downloading());
130
131 EXPECT_CALL(host_, SetTotalBytes(kFileSize));
132 EXPECT_CALL(host_, AddBufferedByteRange(0, kFileSize));
133 Respond(response_generator_->GenerateFileResponse(0));
122 } 134 }
123 135
124 // Stops any active loaders and shuts down the data source. 136 // Stops any active loaders and shuts down the data source.
125 // 137 //
126 // This typically happens when the page is closed and for our purposes is 138 // This typically happens when the page is closed and for our purposes is
127 // appropriate to do when tearing down a test. 139 // appropriate to do when tearing down a test.
128 void Stop() { 140 void Stop() {
129 if (data_source_->loading()) { 141 if (data_source_->loading()) {
130 loader()->didFail(url_loader(), response_generator_.GenerateError()); 142 loader()->didFail(url_loader(), response_generator_->GenerateError());
131 message_loop_.RunAllPending(); 143 message_loop_.RunAllPending();
132 } 144 }
133 145
134 data_source_->Stop(media::NewExpectedClosure()); 146 data_source_->Stop(media::NewExpectedClosure());
135 message_loop_.RunAllPending(); 147 message_loop_.RunAllPending();
136 } 148 }
137 149
138 void ExpectCreateResourceLoader() { 150 void ExpectCreateResourceLoader() {
139 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) 151 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _))
140 .WillOnce(Invoke(data_source_.get(), 152 .WillOnce(Invoke(data_source_.get(),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 BufferedResourceLoader::DeferStrategy defer_strategy() { 194 BufferedResourceLoader::DeferStrategy defer_strategy() {
183 return loader()->defer_strategy_; 195 return loader()->defer_strategy_;
184 } 196 }
185 int data_source_bitrate() { return data_source_->bitrate_; } 197 int data_source_bitrate() { return data_source_->bitrate_; }
186 int data_source_playback_rate() { return data_source_->playback_rate_; } 198 int data_source_playback_rate() { return data_source_->playback_rate_; }
187 int loader_bitrate() { return loader()->bitrate_; } 199 int loader_bitrate() { return loader()->bitrate_; }
188 int loader_playback_rate() { return loader()->playback_rate_; } 200 int loader_playback_rate() { return loader()->playback_rate_; }
189 201
190 scoped_refptr<MockBufferedDataSource> data_source_; 202 scoped_refptr<MockBufferedDataSource> data_source_;
191 203
192 TestResponseGenerator response_generator_; 204 scoped_ptr<TestResponseGenerator> response_generator_;
193 MockWebFrameClient client_; 205 MockWebFrameClient client_;
194 WebView* view_; 206 WebView* view_;
195 207
196 StrictMock<media::MockDataSourceHost> host_; 208 StrictMock<media::MockDataSourceHost> host_;
197 MessageLoop message_loop_; 209 MessageLoop message_loop_;
198 210
199 private: 211 private:
200 // Used for calling BufferedDataSource::Read(). 212 // Used for calling BufferedDataSource::Read().
201 uint8 buffer_[kDataSize]; 213 uint8 buffer_[kDataSize];
202 214
203 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); 215 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest);
204 }; 216 };
205 217
206 TEST_F(BufferedDataSourceTest, Range_Supported) { 218 TEST_F(BufferedDataSourceTest, Range_Supported) {
207 Initialize(media::PIPELINE_OK); 219 Initialize(kHttpUrl, media::PIPELINE_OK);
208 220
209 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 221 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
210 Respond(response_generator_.Generate206(0)); 222 Respond(response_generator_->Generate206(0));
211 223
212 EXPECT_TRUE(data_source_->loading()); 224 EXPECT_TRUE(data_source_->loading());
213 EXPECT_FALSE(data_source_->IsStreaming()); 225 EXPECT_FALSE(data_source_->IsStreaming());
214 Stop(); 226 Stop();
215 } 227 }
216 228
217 TEST_F(BufferedDataSourceTest, Range_InstanceSizeUnknown) { 229 TEST_F(BufferedDataSourceTest, Range_InstanceSizeUnknown) {
218 Initialize(media::PIPELINE_OK); 230 Initialize(kHttpUrl, media::PIPELINE_OK);
219 231
220 Respond(response_generator_.Generate206( 232 Respond(response_generator_->Generate206(
221 0, TestResponseGenerator::kNoContentRangeInstanceSize)); 233 0, TestResponseGenerator::kNoContentRangeInstanceSize));
222 234
223 EXPECT_TRUE(data_source_->loading()); 235 EXPECT_TRUE(data_source_->loading());
224 EXPECT_TRUE(data_source_->IsStreaming()); 236 EXPECT_TRUE(data_source_->IsStreaming());
225 Stop(); 237 Stop();
226 } 238 }
227 239
228 TEST_F(BufferedDataSourceTest, Range_NotFound) { 240 TEST_F(BufferedDataSourceTest, Range_NotFound) {
229 Initialize(media::PIPELINE_ERROR_NETWORK); 241 Initialize(kHttpUrl, media::PIPELINE_ERROR_NETWORK);
230 Respond(response_generator_.Generate404()); 242 Respond(response_generator_->Generate404());
231 243
232 EXPECT_FALSE(data_source_->loading()); 244 EXPECT_FALSE(data_source_->loading());
233 Stop(); 245 Stop();
234 } 246 }
235 247
236 TEST_F(BufferedDataSourceTest, Range_NotSupported) { 248 TEST_F(BufferedDataSourceTest, Range_NotSupported) {
237 Initialize(media::PIPELINE_OK); 249 Initialize(kHttpUrl, media::PIPELINE_OK);
238 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 250 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
239 Respond(response_generator_.Generate200()); 251 Respond(response_generator_->Generate200());
240 252
241 EXPECT_TRUE(data_source_->loading()); 253 EXPECT_TRUE(data_source_->loading());
242 EXPECT_TRUE(data_source_->IsStreaming()); 254 EXPECT_TRUE(data_source_->IsStreaming());
243 Stop(); 255 Stop();
244 } 256 }
245 257
246 // Special carve-out for Apache versions that choose to return a 200 for 258 // Special carve-out for Apache versions that choose to return a 200 for
247 // Range:0- ("because it's more efficient" than a 206) 259 // Range:0- ("because it's more efficient" than a 206)
248 TEST_F(BufferedDataSourceTest, Range_SupportedButReturned200) { 260 TEST_F(BufferedDataSourceTest, Range_SupportedButReturned200) {
249 Initialize(media::PIPELINE_OK); 261 Initialize(kHttpUrl, media::PIPELINE_OK);
250 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 262 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
251 WebURLResponse response = response_generator_.Generate200(); 263 WebURLResponse response = response_generator_->Generate200();
252 response.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"), 264 response.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"),
253 WebString::fromUTF8("bytes")); 265 WebString::fromUTF8("bytes"));
254 Respond(response); 266 Respond(response);
255 267
256 EXPECT_TRUE(data_source_->loading()); 268 EXPECT_TRUE(data_source_->loading());
257 EXPECT_FALSE(data_source_->IsStreaming()); 269 EXPECT_FALSE(data_source_->IsStreaming());
258 Stop(); 270 Stop();
259 } 271 }
260 272
261 TEST_F(BufferedDataSourceTest, Range_MissingContentRange) { 273 TEST_F(BufferedDataSourceTest, Range_MissingContentRange) {
262 Initialize(media::PIPELINE_ERROR_NETWORK); 274 Initialize(kHttpUrl, media::PIPELINE_ERROR_NETWORK);
263 Respond(response_generator_.Generate206( 275 Respond(response_generator_->Generate206(
264 0, TestResponseGenerator::kNoContentRange)); 276 0, TestResponseGenerator::kNoContentRange));
265 277
266 EXPECT_FALSE(data_source_->loading()); 278 EXPECT_FALSE(data_source_->loading());
267 Stop(); 279 Stop();
268 } 280 }
269 281
270 TEST_F(BufferedDataSourceTest, Range_MissingContentLength) { 282 TEST_F(BufferedDataSourceTest, Range_MissingContentLength) {
271 Initialize(media::PIPELINE_OK); 283 Initialize(kHttpUrl, media::PIPELINE_OK);
272 284
273 // It'll manage without a Content-Length response. 285 // It'll manage without a Content-Length response.
274 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 286 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
275 Respond(response_generator_.Generate206( 287 Respond(response_generator_->Generate206(
276 0, TestResponseGenerator::kNoContentLength)); 288 0, TestResponseGenerator::kNoContentLength));
277 289
278 EXPECT_TRUE(data_source_->loading()); 290 EXPECT_TRUE(data_source_->loading());
279 EXPECT_FALSE(data_source_->IsStreaming()); 291 EXPECT_FALSE(data_source_->IsStreaming());
280 Stop(); 292 Stop();
281 } 293 }
282 294
283 TEST_F(BufferedDataSourceTest, Range_WrongContentRange) { 295 TEST_F(BufferedDataSourceTest, Range_WrongContentRange) {
284 Initialize(media::PIPELINE_ERROR_NETWORK); 296 Initialize(kHttpUrl, media::PIPELINE_ERROR_NETWORK);
285 297
286 // Now it's done and will fail. 298 // Now it's done and will fail.
287 Respond(response_generator_.Generate206(1337)); 299 Respond(response_generator_->Generate206(1337));
288 300
289 EXPECT_FALSE(data_source_->loading()); 301 EXPECT_FALSE(data_source_->loading());
290 Stop(); 302 Stop();
291 } 303 }
292 304
293 // Test the case where the initial response from the server indicates that 305 // Test the case where the initial response from the server indicates that
294 // Range requests are supported, but a later request prove otherwise. 306 // Range requests are supported, but a later request prove otherwise.
295 TEST_F(BufferedDataSourceTest, Range_ServerLied) { 307 TEST_F(BufferedDataSourceTest, Range_ServerLied) {
296 InitializeWith206Response(); 308 InitializeWith206Response();
297 309
298 // Read causing a new request to be made -- we'll expect it to error. 310 // Read causing a new request to be made -- we'll expect it to error.
299 ExpectCreateResourceLoader(); 311 ExpectCreateResourceLoader();
300 ReadAt(kFarReadPosition); 312 ReadAt(kFarReadPosition);
301 313
302 // Return a 200 in response to a range request. 314 // Return a 200 in response to a range request.
303 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 315 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
304 Respond(response_generator_.Generate200()); 316 Respond(response_generator_->Generate200());
305 317
306 EXPECT_FALSE(data_source_->loading()); 318 EXPECT_FALSE(data_source_->loading());
307 Stop(); 319 Stop();
308 } 320 }
309 321
310 TEST_F(BufferedDataSourceTest, Range_AbortWhileReading) { 322 TEST_F(BufferedDataSourceTest, Http_AbortWhileReading) {
311 InitializeWith206Response(); 323 InitializeWith206Response();
312 324
313 // Make sure there's a pending read -- we'll expect it to error. 325 // Make sure there's a pending read -- we'll expect it to error.
314 ReadAt(0); 326 ReadAt(0);
315 327
316 // Abort!!! 328 // Abort!!!
317 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 329 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
318 data_source_->Abort(); 330 data_source_->Abort();
319 message_loop_.RunAllPending(); 331 message_loop_.RunAllPending();
320 332
321 EXPECT_FALSE(data_source_->loading()); 333 EXPECT_FALSE(data_source_->loading());
322 Stop(); 334 Stop();
323 } 335 }
324 336
325 TEST_F(BufferedDataSourceTest, Range_TooManyRetries) { 337 TEST_F(BufferedDataSourceTest, File_AbortWhileReading) {
338 InitializeWithFileResponse();
339
340 // Make sure there's a pending read -- we'll expect it to error.
341 ReadAt(0);
342
343 // Abort!!!
344 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
345 data_source_->Abort();
346 message_loop_.RunAllPending();
347
348 EXPECT_FALSE(data_source_->loading());
349 Stop();
350 }
351
352 TEST_F(BufferedDataSourceTest, Http_Retry) {
353 InitializeWith206Response();
354
355 // Read to advance our position.
356 EXPECT_CALL(*this, ReadCallback(kDataSize));
357 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
358 ReadAt(0);
359 ReceiveData(kDataSize);
360
361 // Issue a pending read but terminate the connection to force a retry.
362 ReadAt(kDataSize);
363 ExpectCreateResourceLoader();
364 FinishLoading();
365 Respond(response_generator_->Generate206(kDataSize));
366
367 // Complete the read.
368 EXPECT_CALL(*this, ReadCallback(kDataSize));
369 EXPECT_CALL(host_, AddBufferedByteRange(kDataSize, (kDataSize * 2) - 1));
370 ReceiveData(kDataSize);
371
372 EXPECT_TRUE(data_source_->loading());
373 Stop();
374 }
375
376 TEST_F(BufferedDataSourceTest, File_Retry) {
377 InitializeWithFileResponse();
378
379 // Read to advance our position.
380 EXPECT_CALL(*this, ReadCallback(kDataSize));
381 ReadAt(0);
382 ReceiveData(kDataSize);
383
384 // Issue a pending read but terminate the connection to force a retry.
385 ReadAt(kDataSize);
386 ExpectCreateResourceLoader();
387 FinishLoading();
388 Respond(response_generator_->GenerateFileResponse(kDataSize));
389
390 // Complete the read.
391 EXPECT_CALL(*this, ReadCallback(kDataSize));
392 ReceiveData(kDataSize);
393
394 EXPECT_TRUE(data_source_->loading());
395 Stop();
396 }
397
398 TEST_F(BufferedDataSourceTest, Http_TooManyRetries) {
326 InitializeWith206Response(); 399 InitializeWith206Response();
327 400
328 // Make sure there's a pending read -- we'll expect it to error. 401 // Make sure there's a pending read -- we'll expect it to error.
329 ReadAt(0); 402 ReadAt(0);
330 403
331 // It'll try three times. 404 // It'll try three times.
332 ExpectCreateResourceLoader(); 405 ExpectCreateResourceLoader();
333 FinishLoading(); 406 FinishLoading();
334 Respond(response_generator_.Generate206(0)); 407 Respond(response_generator_->Generate206(0));
335 408
336 ExpectCreateResourceLoader(); 409 ExpectCreateResourceLoader();
337 FinishLoading(); 410 FinishLoading();
338 Respond(response_generator_.Generate206(0)); 411 Respond(response_generator_->Generate206(0));
339 412
340 ExpectCreateResourceLoader(); 413 ExpectCreateResourceLoader();
341 FinishLoading(); 414 FinishLoading();
342 Respond(response_generator_.Generate206(0)); 415 Respond(response_generator_->Generate206(0));
343 416
344 // It'll error after this. 417 // It'll error after this.
345 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 418 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
346 FinishLoading(); 419 FinishLoading();
347 420
348 EXPECT_FALSE(data_source_->loading()); 421 EXPECT_FALSE(data_source_->loading());
349 Stop(); 422 Stop();
350 } 423 }
351 424
425 TEST_F(BufferedDataSourceTest, File_TooManyRetries) {
426 InitializeWithFileResponse();
427
428 // Make sure there's a pending read -- we'll expect it to error.
429 ReadAt(0);
430
431 // It'll try three times.
432 ExpectCreateResourceLoader();
433 FinishLoading();
434 Respond(response_generator_->GenerateFileResponse(0));
435
436 ExpectCreateResourceLoader();
437 FinishLoading();
438 Respond(response_generator_->GenerateFileResponse(0));
439
440 ExpectCreateResourceLoader();
441 FinishLoading();
442 Respond(response_generator_->GenerateFileResponse(0));
443
444 // It'll error after this.
445 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
446 FinishLoading();
447
448 EXPECT_FALSE(data_source_->loading());
449 Stop();
450 }
451
452 TEST_F(BufferedDataSourceTest, File_InstanceSizeUnknown) {
453 Initialize(kFileUrl, media::PIPELINE_ERROR_NETWORK);
454 EXPECT_FALSE(data_source_->downloading());
455
456 Respond(response_generator_->GenerateFileResponse(-1));
457
458 EXPECT_FALSE(data_source_->loading());
459 Stop();
460 }
461
462 TEST_F(BufferedDataSourceTest, File_Successful) {
463 InitializeWithFileResponse();
464
465 EXPECT_TRUE(data_source_->loading());
466 Stop();
467 }
468
352 static void SetTrue(bool* value) { 469 static void SetTrue(bool* value) {
353 *value = true; 470 *value = true;
354 } 471 }
355 472
356 // This test makes sure that Stop() does not require a task to run on 473 // This test makes sure that Stop() does not require a task to run on
357 // |message_loop_| before it calls its callback. This prevents accidental 474 // |message_loop_| before it calls its callback. This prevents accidental
358 // introduction of a pipeline teardown deadlock. The pipeline owner blocks 475 // introduction of a pipeline teardown deadlock. The pipeline owner blocks
359 // the render message loop while waiting for Stop() to complete. Since this 476 // the render message loop while waiting for Stop() to complete. Since this
360 // object runs on the render message loop, Stop() will not complete if it 477 // object runs on the render message loop, Stop() will not complete if it
361 // requires a task to run on the the message loop that is being blocked. 478 // requires a task to run on the the message loop that is being blocked.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 512
396 data_source_->SetBitrate(1234); 513 data_source_->SetBitrate(1234);
397 message_loop_.RunAllPending(); 514 message_loop_.RunAllPending();
398 EXPECT_EQ(1234, data_source_bitrate()); 515 EXPECT_EQ(1234, data_source_bitrate());
399 EXPECT_EQ(1234, loader_bitrate()); 516 EXPECT_EQ(1234, loader_bitrate());
400 517
401 // Read so far ahead to cause the loader to get recreated. 518 // Read so far ahead to cause the loader to get recreated.
402 BufferedResourceLoader* old_loader = loader(); 519 BufferedResourceLoader* old_loader = loader();
403 ExpectCreateResourceLoader(); 520 ExpectCreateResourceLoader();
404 ReadAt(kFarReadPosition); 521 ReadAt(kFarReadPosition);
405 Respond(response_generator_.Generate206(kFarReadPosition)); 522 Respond(response_generator_->Generate206(kFarReadPosition));
406 523
407 // Verify loader changed but still has same bitrate. 524 // Verify loader changed but still has same bitrate.
408 EXPECT_NE(old_loader, loader()); 525 EXPECT_NE(old_loader, loader());
409 EXPECT_EQ(1234, loader_bitrate()); 526 EXPECT_EQ(1234, loader_bitrate());
410 527
411 EXPECT_TRUE(data_source_->loading()); 528 EXPECT_TRUE(data_source_->loading());
412 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 529 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
413 Stop(); 530 Stop();
414 } 531 }
415 532
416 TEST_F(BufferedDataSourceTest, SetPlaybackRate) { 533 TEST_F(BufferedDataSourceTest, SetPlaybackRate) {
417 InitializeWith206Response(); 534 InitializeWith206Response();
418 535
419 data_source_->SetPlaybackRate(2.0f); 536 data_source_->SetPlaybackRate(2.0f);
420 message_loop_.RunAllPending(); 537 message_loop_.RunAllPending();
421 EXPECT_EQ(2.0f, data_source_playback_rate()); 538 EXPECT_EQ(2.0f, data_source_playback_rate());
422 EXPECT_EQ(2.0f, loader_playback_rate()); 539 EXPECT_EQ(2.0f, loader_playback_rate());
423 540
424 // Read so far ahead to cause the loader to get recreated. 541 // Read so far ahead to cause the loader to get recreated.
425 BufferedResourceLoader* old_loader = loader(); 542 BufferedResourceLoader* old_loader = loader();
426 ExpectCreateResourceLoader(); 543 ExpectCreateResourceLoader();
427 ReadAt(kFarReadPosition); 544 ReadAt(kFarReadPosition);
428 Respond(response_generator_.Generate206(kFarReadPosition)); 545 Respond(response_generator_->Generate206(kFarReadPosition));
429 546
430 // Verify loader changed but still has same playback rate. 547 // Verify loader changed but still has same playback rate.
431 EXPECT_NE(old_loader, loader()); 548 EXPECT_NE(old_loader, loader());
432 549
433 EXPECT_TRUE(data_source_->loading()); 550 EXPECT_TRUE(data_source_->loading());
434 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 551 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
435 Stop(); 552 Stop();
436 } 553 }
437 554
438 TEST_F(BufferedDataSourceTest, Read) { 555 TEST_F(BufferedDataSourceTest, Http_Read) {
439 InitializeWith206Response(); 556 InitializeWith206Response();
440 557
441 ReadAt(0); 558 ReadAt(0);
442 559
443 // Receive first half of the read. 560 // Receive first half of the read.
444 EXPECT_CALL(host_, AddBufferedByteRange(0, (kDataSize / 2) - 1)); 561 EXPECT_CALL(host_, AddBufferedByteRange(0, (kDataSize / 2) - 1));
445 ReceiveData(kDataSize / 2); 562 ReceiveData(kDataSize / 2);
446 563
447 // Receive last half of the read. 564 // Receive last half of the read.
448 EXPECT_CALL(*this, ReadCallback(kDataSize)); 565 EXPECT_CALL(*this, ReadCallback(kDataSize));
449 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); 566 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
450 ReceiveData(kDataSize / 2); 567 ReceiveData(kDataSize / 2);
451 568
452 EXPECT_TRUE(data_source_->downloading()); 569 EXPECT_TRUE(data_source_->downloading());
453 Stop(); 570 Stop();
454 } 571 }
455 572
573 TEST_F(BufferedDataSourceTest, File_Read) {
574 InitializeWithFileResponse();
575
576 ReadAt(0);
577
578 // Receive first half of the read but no buffering update.
579 ReceiveData(kDataSize / 2);
580
581 // Receive last half of the read but no buffering update.
582 EXPECT_CALL(*this, ReadCallback(kDataSize));
583 ReceiveData(kDataSize / 2);
584
585 Stop();
586 }
587
456 } // namespace webkit_media 588 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698