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

Side by Side Diff: webkit/glue/media/buffered_resource_loader_unittest.cc

Issue 8224028: Numerous fixes to audio/video buffered resource loading. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "media/base/media_log.h" 11 #include "media/base/media_log.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/http/http_request_headers.h" 13 #include "net/http/http_request_headers.h"
14 #include "net/http/http_util.h" 14 #include "net/http/http_util.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
21 #include "webkit/glue/media/buffered_resource_loader.h" 21 #include "webkit/glue/media/buffered_resource_loader.h"
22 #include "webkit/mocks/mock_webframeclient.h" 22 #include "webkit/mocks/mock_webframeclient.h"
23 #include "webkit/mocks/mock_weburlloader.h" 23 #include "webkit/mocks/mock_weburlloader.h"
24 24
25 using ::testing::_;
26 using ::testing::Assign;
27 using ::testing::AtLeast;
28 using ::testing::DeleteArg;
29 using ::testing::DoAll;
30 using ::testing::InSequence; 25 using ::testing::InSequence;
31 using ::testing::Invoke;
32 using ::testing::InvokeWithoutArgs;
33 using ::testing::NotNull;
34 using ::testing::Return; 26 using ::testing::Return;
35 using ::testing::ReturnRef;
36 using ::testing::SetArgumentPointee;
37 using ::testing::StrictMock;
38 using ::testing::Truly; 27 using ::testing::Truly;
39 using ::testing::NiceMock; 28 using ::testing::NiceMock;
40 using ::testing::WithArgs;
41 29
42 using WebKit::WebString; 30 using WebKit::WebString;
43 using WebKit::WebURLError; 31 using WebKit::WebURLError;
44 using WebKit::WebURLResponse; 32 using WebKit::WebURLResponse;
45 using WebKit::WebView; 33 using WebKit::WebView;
46 34
47 namespace webkit_glue { 35 namespace webkit_glue {
48 36
49 static const char* kHttpUrl = "http://test"; 37 static const char* kHttpUrl = "http://test";
50 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; 38 static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 virtual ~BufferedResourceLoaderTest() { 81 virtual ~BufferedResourceLoaderTest() {
94 view_->close(); 82 view_->close();
95 } 83 }
96 84
97 void Initialize(const char* url, int first_position, int last_position) { 85 void Initialize(const char* url, int first_position, int last_position) {
98 gurl_ = GURL(url); 86 gurl_ = GURL(url);
99 first_position_ = first_position; 87 first_position_ = first_position;
100 last_position_ = last_position; 88 last_position_ = last_position;
101 89
102 url_loader_ = new NiceMock<MockWebURLLoader>(); 90 url_loader_ = new NiceMock<MockWebURLLoader>();
103 loader_ = new BufferedResourceLoader(gurl_, 91 loader_ = new BufferedResourceLoader(
104 first_position_, last_position_, 92 gurl_, first_position_, last_position_,
105 new media::MediaLog()); 93 BufferedResourceLoader::kThresholdDefer, 0, 0,
94 new media::MediaLog());
106 loader_->SetURLLoaderForTest(url_loader_); 95 loader_->SetURLLoaderForTest(url_loader_);
107 } 96 }
108 97
109 void SetLoaderBuffer(size_t forward_capacity, size_t backward_capacity) { 98 void SetLoaderBuffer(size_t forward_capacity, size_t backward_capacity) {
110 loader_->buffer_.reset( 99 loader_->buffer_.reset(
111 new media::SeekableBuffer(backward_capacity, forward_capacity)); 100 new media::SeekableBuffer(backward_capacity, forward_capacity));
112 } 101 }
113 102
114 void Start() { 103 void Start() {
115 InSequence s; 104 InSequence s;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 void ReadLoader(int64 position, int size, uint8* buffer) { 218 void ReadLoader(int64 position, int size, uint8* buffer) {
230 loader_->Read(position, size, buffer, 219 loader_->Read(position, size, buffer,
231 NewCallback(this, &BufferedResourceLoaderTest::ReadCallback)); 220 NewCallback(this, &BufferedResourceLoaderTest::ReadCallback));
232 } 221 }
233 222
234 // Verifies that data in buffer[0...size] is equal to data_[pos...pos+size]. 223 // Verifies that data in buffer[0...size] is equal to data_[pos...pos+size].
235 void VerifyBuffer(uint8* buffer, int pos, int size) { 224 void VerifyBuffer(uint8* buffer, int pos, int size) {
236 EXPECT_EQ(0, memcmp(buffer, data_ + pos, size)); 225 EXPECT_EQ(0, memcmp(buffer, data_ + pos, size));
237 } 226 }
238 227
228 void ConfirmLoaderBufferBackwardCapacity(size_t expected_backward_capacity) {
229 EXPECT_EQ(loader_->buffer_->backward_capacity(),
230 expected_backward_capacity);
231 }
232
239 void ConfirmLoaderBufferForwardCapacity(size_t expected_forward_capacity) { 233 void ConfirmLoaderBufferForwardCapacity(size_t expected_forward_capacity) {
240 EXPECT_EQ(loader_->buffer_->forward_capacity(), expected_forward_capacity); 234 EXPECT_EQ(loader_->buffer_->forward_capacity(), expected_forward_capacity);
241 } 235 }
242 236
243 void ConfirmLoaderDeferredState(bool expectedVal) { 237 void ConfirmLoaderDeferredState(bool expectedVal) {
244 EXPECT_EQ(loader_->deferred_, expectedVal); 238 EXPECT_EQ(loader_->deferred_, expectedVal);
245 } 239 }
246 240
247 void CheckBufferWindowIsNotTooBig() { 241 // Makes sure the |loader_| buffer window is in a reasonable range.
248 // An arbitrarily chosen, reasonable limit. 242 void CheckBufferWindowBounds() {
243 // Corresponds to value defined in buffered_resource_loader.cc.
244 static const size_t kMinBufferCapacity = 2 * 1024 * 1024;
245 EXPECT_GE(loader_->buffer_->forward_capacity(), kMinBufferCapacity);
246 EXPECT_GE(loader_->buffer_->backward_capacity(), kMinBufferCapacity);
247
248 // Corresponds to value defined in buffered_resource_loader.cc.
249 static const size_t kMaxBufferCapacity = 20 * 1024 * 1024; 249 static const size_t kMaxBufferCapacity = 20 * 1024 * 1024;
250 EXPECT_LE(loader_->buffer_->forward_capacity(), kMaxBufferCapacity); 250 EXPECT_LE(loader_->buffer_->forward_capacity(), kMaxBufferCapacity);
251 EXPECT_LE(loader_->buffer_->backward_capacity(), kMaxBufferCapacity); 251 EXPECT_LE(loader_->buffer_->backward_capacity(), kMaxBufferCapacity);
252 } 252 }
253 253
254 void CheckBufferWindowIsNotTooSmall() {
255 EXPECT_GT(loader_->buffer_->forward_capacity(), 0u);
256 EXPECT_GT(loader_->buffer_->backward_capacity(), 0u);
257 }
258
259 // Makes sure the |loader_| buffer window is in a reasonable range.
260 void CheckBufferWindowBounds() {
261 CheckBufferWindowIsNotTooSmall();
262 CheckBufferWindowIsNotTooBig();
263 }
264
265 // Updates the |loader_|'s |playback_rate| and |bitrate|, then returns via the
266 // output parameters the resultant change in the forward and backward capacity
267 // of |loader_|'s buffer window.
268 void InvokeChangeInBufferWindow(float playback_rate, int bitrate,
269 int* out_forward_capacity_delta,
270 int* out_backward_capacity_delta) {
271 CheckBufferWindowBounds();
272 size_t old_forward_capacity = loader_->buffer_->forward_capacity();
273 size_t old_backward_capacity = loader_->buffer_->backward_capacity();
274
275 loader_->SetPlaybackRate(playback_rate);
276 loader_->SetBitrate(bitrate);
277 CheckBufferWindowBounds();
278
279 *out_forward_capacity_delta =
280 loader_->buffer_->forward_capacity() - old_forward_capacity;
281 *out_backward_capacity_delta =
282 loader_->buffer_->backward_capacity() - old_backward_capacity;
283 }
284
285 MOCK_METHOD1(StartCallback, void(int error)); 254 MOCK_METHOD1(StartCallback, void(int error));
286 MOCK_METHOD1(ReadCallback, void(int error)); 255 MOCK_METHOD1(ReadCallback, void(int error));
287 MOCK_METHOD0(NetworkCallback, void()); 256 MOCK_METHOD0(NetworkCallback, void());
288 257
289 protected: 258 protected:
290 GURL gurl_; 259 GURL gurl_;
291 int64 first_position_; 260 int64 first_position_;
292 int64 last_position_; 261 int64 last_position_;
293 262
294 scoped_refptr<BufferedResourceLoader> loader_; 263 scoped_refptr<BufferedResourceLoader> loader_;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 ReadLoader(30, 10, buffer); 407 ReadLoader(30, 10, buffer);
439 } 408 }
440 409
441 // Tests the logic of expanding the data buffer for large reads. 410 // Tests the logic of expanding the data buffer for large reads.
442 TEST_F(BufferedResourceLoaderTest, ReadExtendBuffer) { 411 TEST_F(BufferedResourceLoaderTest, ReadExtendBuffer) {
443 Initialize(kHttpUrl, 10, 0x014FFFFFF); 412 Initialize(kHttpUrl, 10, 0x014FFFFFF);
444 SetLoaderBuffer(10, 20); 413 SetLoaderBuffer(10, 20);
445 Start(); 414 Start();
446 PartialResponse(10, 0x014FFFFFF, 0x01500000); 415 PartialResponse(10, 0x014FFFFFF, 0x01500000);
447 416
417 // Don't test for network callbacks (covered by *Strategy tests).
418 EXPECT_CALL(*this, NetworkCallback())
419 .WillRepeatedly(Return());
420
448 uint8 buffer[20]; 421 uint8 buffer[20];
449 InSequence s; 422 InSequence s;
450 423
451 // Write more than forward capacity and read it back. Ensure forward capacity 424 // Write more than forward capacity and read it back. Ensure forward capacity
452 // gets reset. 425 // gets reset.
453 EXPECT_CALL(*this, NetworkCallback());
454 WriteLoader(10, 20); 426 WriteLoader(10, 20);
455 EXPECT_CALL(*this, ReadCallback(20)); 427 EXPECT_CALL(*this, ReadCallback(20));
456 ReadLoader(10, 20, buffer); 428 ReadLoader(10, 20, buffer);
457 429
458 VerifyBuffer(buffer, 10, 20); 430 VerifyBuffer(buffer, 10, 20);
459 ConfirmLoaderBufferForwardCapacity(10); 431 ConfirmLoaderBufferForwardCapacity(10);
460 432
461 // Make and outstanding read request larger than forward capacity. Ensure 433 // Make and outstanding read request larger than forward capacity. Ensure
462 // forward capacity gets extended. 434 // forward capacity gets extended.
463 EXPECT_CALL(*this, NetworkCallback());
464 ReadLoader(30, 20, buffer); 435 ReadLoader(30, 20, buffer);
465 436
466 ConfirmLoaderBufferForwardCapacity(20); 437 ConfirmLoaderBufferForwardCapacity(20);
467 438
468 // Fulfill outstanding request. Ensure forward capacity gets reset. 439 // Fulfill outstanding request. Ensure forward capacity gets reset.
469 EXPECT_CALL(*this, ReadCallback(20)); 440 EXPECT_CALL(*this, ReadCallback(20));
470 EXPECT_CALL(*this, NetworkCallback());
471 WriteLoader(30, 20); 441 WriteLoader(30, 20);
472 442
473 VerifyBuffer(buffer, 30, 20); 443 VerifyBuffer(buffer, 30, 20);
474 ConfirmLoaderBufferForwardCapacity(10); 444 ConfirmLoaderBufferForwardCapacity(10);
475 445
476 // Try to read further ahead than kForwardWaitThreshold allows. Ensure 446 // Try to read further ahead than kForwardWaitThreshold allows. Ensure
477 // forward capacity is not changed. 447 // forward capacity is not changed.
478 EXPECT_CALL(*this, NetworkCallback());
479 EXPECT_CALL(*this, ReadCallback(net::ERR_CACHE_MISS)); 448 EXPECT_CALL(*this, ReadCallback(net::ERR_CACHE_MISS));
480 ReadLoader(0x00300000, 1, buffer); 449 ReadLoader(0x00300000, 1, buffer);
481 450
482 ConfirmLoaderBufferForwardCapacity(10); 451 ConfirmLoaderBufferForwardCapacity(10);
483 452
484 // Try to read more than maximum forward capacity. Ensure forward capacity is 453 // Try to read more than maximum forward capacity. Ensure forward capacity is
485 // not changed. 454 // not changed.
486 EXPECT_CALL(*this, ReadCallback(net::ERR_FAILED)); 455 EXPECT_CALL(*this, ReadCallback(net::ERR_FAILED));
487 ReadLoader(30, 0x01400001, buffer); 456 ReadLoader(30, 0x01400001, buffer);
488 457
489 ConfirmLoaderBufferForwardCapacity(10); 458 ConfirmLoaderBufferForwardCapacity(10);
490 459
491 StopWhenLoad(); 460 StopWhenLoad();
492 } 461 }
493 462
494 TEST_F(BufferedResourceLoaderTest, ReadOutsideBuffer) { 463 TEST_F(BufferedResourceLoaderTest, ReadOutsideBuffer) {
495 Initialize(kHttpUrl, 10, 0x00FFFFFF); 464 Initialize(kHttpUrl, 10, 0x00FFFFFF);
496 loader_->UpdateDeferStrategy(BufferedResourceLoader::kThresholdDefer);
497 Start(); 465 Start();
498 PartialResponse(10, 0x00FFFFFF, 0x01000000); 466 PartialResponse(10, 0x00FFFFFF, 0x01000000);
499 467
500 uint8 buffer[10]; 468 uint8 buffer[10];
501 InSequence s; 469 InSequence s;
502 470
503 // Read very far ahead will get a cache miss. 471 // Read very far ahead will get a cache miss.
504 EXPECT_CALL(*this, ReadCallback(net::ERR_CACHE_MISS)); 472 EXPECT_CALL(*this, ReadCallback(net::ERR_CACHE_MISS));
505 ReadLoader(0x00FFFFFF, 1, buffer); 473 ReadLoader(0x00FFFFFF, 1, buffer);
506 474
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 655
688 // Test redirect to the same domain and then to a different domain. 656 // Test redirect to the same domain and then to a different domain.
689 Initialize(kHttpUrl, -1, -1); 657 Initialize(kHttpUrl, -1, -1);
690 Start(); 658 Start();
691 Redirect(kHttpRedirectToSameDomainUrl1); 659 Redirect(kHttpRedirectToSameDomainUrl1);
692 Redirect(kHttpRedirectToDifferentDomainUrl1); 660 Redirect(kHttpRedirectToDifferentDomainUrl1);
693 EXPECT_FALSE(loader_->HasSingleOrigin()); 661 EXPECT_FALSE(loader_->HasSingleOrigin());
694 StopWhenLoad(); 662 StopWhenLoad();
695 } 663 }
696 664
697 TEST_F(BufferedResourceLoaderTest, BufferWindow_Bitrate_Set) { 665 TEST_F(BufferedResourceLoaderTest, BufferWindow_Default) {
698 Initialize(kHttpUrl, -1, -1);
699 Start();
700 loader_->SetBitrate(1024 * 8);
701 CheckBufferWindowBounds();
702 StopWhenLoad();
703 }
704
705 TEST_F(BufferedResourceLoaderTest, BufferWindow_Bitrate_Increase) {
706 Initialize(kHttpUrl, -1, -1); 666 Initialize(kHttpUrl, -1, -1);
707 Start(); 667 Start();
708 668
709 static const int kBitrate = 1024 * 8; 669 // Test ensures that default construction of a BufferedResourceLoader has sane
710 static const float kPlaybackRate = 1.0; 670 // values.
711 loader_->SetBitrate(kBitrate); 671 //
712 loader_->SetPlaybackRate(kPlaybackRate); 672 // Please do not change these values in order to make a test pass! Instead,
713 673 // start a conversation on what the default buffer window capacities should
714 static const int kNewBitrate = 1024 * 1024 * 8; 674 // be.
715 int forward_capacity_delta; 675 ConfirmLoaderBufferBackwardCapacity(2 * 1024 * 1024);
716 int backward_capacity_delta; 676 ConfirmLoaderBufferForwardCapacity(2 * 1024 * 1024);
717 InvokeChangeInBufferWindow(kPlaybackRate, kNewBitrate,
718 &forward_capacity_delta, &backward_capacity_delta);
719
720 EXPECT_GT(forward_capacity_delta, 0);
721 EXPECT_GT(backward_capacity_delta, 0);
722 677
723 StopWhenLoad(); 678 StopWhenLoad();
724 } 679 }
725 680
726 TEST_F(BufferedResourceLoaderTest, BufferWindow_Bitrate_Decrease) { 681 TEST_F(BufferedResourceLoaderTest, BufferWindow_Bitrate_Unknown) {
727 Initialize(kHttpUrl, -1, -1);
728 Start();
729
730 static const int kBitrate = 1024 * 1024 * 8;
731 static const float kPlaybackRate = 1.0;
732 loader_->SetBitrate(kBitrate);
733 loader_->SetPlaybackRate(kPlaybackRate);
734
735 static const int kNewBitrate = 1024 * 8;
736 int forward_capacity_delta;
737 int backward_capacity_delta;
738 InvokeChangeInBufferWindow(kPlaybackRate, kNewBitrate,
739 &forward_capacity_delta, &backward_capacity_delta);
740
741 EXPECT_LT(forward_capacity_delta, 0);
742 EXPECT_LT(backward_capacity_delta, 0);
743
744 StopWhenLoad();
745 }
746
747 TEST_F(BufferedResourceLoaderTest, BufferWindow_SetVeryLarge) {
748 Initialize(kHttpUrl, -1, -1);
749 Start();
750
751 loader_->SetPlaybackRate(1.0);
752 loader_->SetBitrate(100 * 1024 * 1024);
753 CheckBufferWindowBounds();
754
755 loader_->SetBitrate(1024 * 1024 * 8);
756 loader_->SetPlaybackRate(10000.0);
757 CheckBufferWindowBounds();
758
759 loader_->SetPlaybackRate(-10000.0);
760 CheckBufferWindowBounds();
761 StopWhenLoad();
762 }
763
764 TEST_F(BufferedResourceLoaderTest, BufferWindow_SetVerySmall) {
765 Initialize(kHttpUrl, -1, -1);
766 Start();
767 loader_->SetBitrate(1);
768 CheckBufferWindowBounds();
769
770 // Only check for too big of buffer size in very small playback case; a buffer
771 // window of 0 is reasonable if playback is crawling.
772 loader_->SetPlaybackRate(-0.01f);
773 CheckBufferWindowIsNotTooBig();
774 loader_->SetPlaybackRate(0.01f);
775 CheckBufferWindowIsNotTooBig();
776 StopWhenLoad();
777 }
778
779 TEST_F(BufferedResourceLoaderTest, BufferWindow_SetUnknownBitrate) {
780 Initialize(kHttpUrl, -1, -1); 682 Initialize(kHttpUrl, -1, -1);
781 Start(); 683 Start();
782 loader_->SetBitrate(0); 684 loader_->SetBitrate(0);
783 CheckBufferWindowBounds(); 685 CheckBufferWindowBounds();
784 StopWhenLoad(); 686 StopWhenLoad();
785 } 687 }
786 688
787 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlaybackRate_Increase) { 689 TEST_F(BufferedResourceLoaderTest, BufferWindow_Bitrate_TooLow) {
788 Initialize(kHttpUrl, -1, -1); 690 Initialize(kHttpUrl, -1, -1);
789 Start(); 691 Start();
790 692 loader_->SetBitrate(1024 * 8); // 1 Kbps.
791 static const int kBitrate = 1024 * 8;
792 static const float kPlaybackRate = 1.0;
793 loader_->SetBitrate(kBitrate);
794 loader_->SetPlaybackRate(kPlaybackRate);
795
796 static const float kNewPlaybackRate = 1.5;
797 int forward_capacity_delta;
798 int backward_capacity_delta;
799 InvokeChangeInBufferWindow(kNewPlaybackRate, kBitrate,
800 &forward_capacity_delta, &backward_capacity_delta);
801
802 EXPECT_GT(forward_capacity_delta, 0);
803 EXPECT_GT(backward_capacity_delta, 0);
804
805 StopWhenLoad();
806 }
807
808 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlaybackRate_Decrease) {
vrk (LEFT CHROMIUM) 2011/10/11 18:23:21 I like the clean-up! One comment is that the unit
809 Initialize(kHttpUrl, -1, -1);
810 Start();
811
812 static const int kBitrate = 1024 * 8;
813 static const float kPlaybackRate = 1.0;
814 loader_->SetBitrate(kBitrate);
815 loader_->SetPlaybackRate(kPlaybackRate);
816
817 static const float kNewPlaybackRate = 0.5;
818 int forward_capacity_delta;
819 int backward_capacity_delta;
820 InvokeChangeInBufferWindow(kNewPlaybackRate, kBitrate,
821 &forward_capacity_delta, &backward_capacity_delta);
822
823 EXPECT_LT(forward_capacity_delta, 0);
824 EXPECT_LT(backward_capacity_delta, 0);
825
826 StopWhenLoad();
827 }
828
829 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlaybackRate_Backwards) {
830 Initialize(kHttpUrl, -1, -1);
831 Start();
832 loader_->SetPlaybackRate(-1.0);
833 CheckBufferWindowBounds(); 693 CheckBufferWindowBounds();
834 StopWhenLoad(); 694 StopWhenLoad();
835 } 695 }
836 696
837 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlayPause) { 697 TEST_F(BufferedResourceLoaderTest, BufferWindow_Bitrate_JustRight) {
838 Initialize(kHttpUrl, -1, -1); 698 Initialize(kHttpUrl, -1, -1);
839 Start(); 699 Start();
840 700 loader_->SetBitrate(2 * 1024 * 1024 * 8); // 2 Mbps.
841 static const int kBitrate = 1024 * 8; 701 CheckBufferWindowBounds();
842 static const float kPlaybackRate = 1.0;
843 loader_->SetBitrate(kBitrate);
844 loader_->SetPlaybackRate(kPlaybackRate);
845
846 static const float kPausedPlaybackRate = 0.0;
847 int forward_capacity_delta;
848 int backward_capacity_delta;
849 InvokeChangeInBufferWindow(kPausedPlaybackRate, kBitrate,
850 &forward_capacity_delta, &backward_capacity_delta);
851
852 EXPECT_EQ(forward_capacity_delta, 0);
853 EXPECT_EQ(backward_capacity_delta, 0);
854
855 StopWhenLoad(); 702 StopWhenLoad();
856 } 703 }
857 704
858 // TODO(hclam): add unit test for defer loading. 705 TEST_F(BufferedResourceLoaderTest, BufferWindow_Bitrate_TooHigh) {
706 Initialize(kHttpUrl, -1, -1);
707 Start();
708 loader_->SetBitrate(100 * 1024 * 1024 * 8); // 100 Mbps.
709 CheckBufferWindowBounds();
710 StopWhenLoad();
711 }
712
713 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlaybackRate_Negative) {
714 Initialize(kHttpUrl, -1, -1);
715 Start();
716 loader_->SetPlaybackRate(-10);
717 CheckBufferWindowBounds();
718 StopWhenLoad();
719 }
720
721 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlaybackRate_Zero) {
722 Initialize(kHttpUrl, -1, -1);
723 Start();
724 loader_->SetPlaybackRate(0);
725 CheckBufferWindowBounds();
726 StopWhenLoad();
727 }
728
729 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlaybackRate_TooLow) {
acolwell GONE FROM CHROMIUM 2011/10/11 16:18:01 Not a fan of the _TooLow, _JustRight, and _TooHigh
scherkus (not reviewing) 2011/10/11 20:13:19 Done.
730 Initialize(kHttpUrl, -1, -1);
731 Start();
732 loader_->SetPlaybackRate(0.1);
733 CheckBufferWindowBounds();
734 StopWhenLoad();
735 }
736
737 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlaybackRate_JustRight) {
738 Initialize(kHttpUrl, -1, -1);
739 Start();
740 loader_->SetPlaybackRate(10);
741 CheckBufferWindowBounds();
742 StopWhenLoad();
743 }
744
745 TEST_F(BufferedResourceLoaderTest, BufferWindow_PlaybackRate_TooHigh) {
746 Initialize(kHttpUrl, -1, -1);
747 Start();
748 loader_->SetPlaybackRate(100);
749 CheckBufferWindowBounds();
750 StopWhenLoad();
751 }
859 752
860 } // namespace webkit_glue 753 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698