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

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

Powered by Google App Engine
This is Rietveld 408576698