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

Side by Side Diff: media/blink/multibuffer_data_source_unittest.cc

Issue 2910553002: fully cache small audio/video (Closed)
Patch Set: comment added Created 3 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 view_->SetMainFrame(frame); 232 view_->SetMainFrame(frame);
233 url_index_ = make_linked_ptr(new TestUrlIndex(frame)); 233 url_index_ = make_linked_ptr(new TestUrlIndex(frame));
234 } 234 }
235 235
236 virtual ~MultibufferDataSourceTest() { view_->Close(); } 236 virtual ~MultibufferDataSourceTest() { view_->Close(); }
237 237
238 MOCK_METHOD1(OnInitialize, void(bool)); 238 MOCK_METHOD1(OnInitialize, void(bool));
239 239
240 void InitializeWithCORS(const char* url, 240 void InitializeWithCORS(const char* url,
241 bool expected, 241 bool expected,
242 UrlData::CORSMode cors_mode) { 242 UrlData::CORSMode cors_mode,
243 size_t file_size = kFileSize) {
243 GURL gurl(url); 244 GURL gurl(url);
244 data_source_.reset(new MockMultibufferDataSource( 245 data_source_.reset(new MockMultibufferDataSource(
245 gurl, cors_mode, message_loop_.task_runner(), url_index_, 246 gurl, cors_mode, message_loop_.task_runner(), url_index_,
246 view_->MainFrame()->ToWebLocalFrame(), &host_)); 247 view_->MainFrame()->ToWebLocalFrame(), &host_));
247 data_source_->SetPreload(preload_); 248 data_source_->SetPreload(preload_);
248 249
249 response_generator_.reset(new TestResponseGenerator(gurl, kFileSize)); 250 response_generator_.reset(new TestResponseGenerator(gurl, file_size));
250 EXPECT_CALL(*this, OnInitialize(expected)); 251 EXPECT_CALL(*this, OnInitialize(expected));
251 data_source_->Initialize(base::Bind( 252 data_source_->Initialize(base::Bind(
252 &MultibufferDataSourceTest::OnInitialize, base::Unretained(this))); 253 &MultibufferDataSourceTest::OnInitialize, base::Unretained(this)));
253 base::RunLoop().RunUntilIdle(); 254 base::RunLoop().RunUntilIdle();
254 255
255 // Not really loading until after OnInitialize is called. 256 // Not really loading until after OnInitialize is called.
256 EXPECT_EQ(data_source_->downloading(), false); 257 EXPECT_EQ(data_source_->downloading(), false);
257 } 258 }
258 259
259 void Initialize(const char* url, bool expected) { 260 void Initialize(const char* url,
260 InitializeWithCORS(url, expected, UrlData::CORS_UNSPECIFIED); 261 bool expected,
262 size_t file_size = kFileSize) {
263 InitializeWithCORS(url, expected, UrlData::CORS_UNSPECIFIED, file_size);
261 } 264 }
262 265
263 // Helper to initialize tests with a valid 200 response. 266 // Helper to initialize tests with a valid 200 response.
264 void InitializeWith200Response() { 267 void InitializeWith200Response() {
265 Initialize(kHttpUrl, true); 268 Initialize(kHttpUrl, true);
266 269
267 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); 270 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
268 Respond(response_generator_->Generate200()); 271 Respond(response_generator_->Generate200());
269 272
270 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize)); 273 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize));
271 ReceiveData(kDataSize); 274 ReceiveData(kDataSize);
272 } 275 }
273 276
274 // Helper to initialize tests with a valid 206 response. 277 // Helper to initialize tests with a valid 206 response.
275 void InitializeWith206Response() { 278 void InitializeWith206Response(size_t file_size = kFileSize) {
276 Initialize(kHttpUrl, true); 279 Initialize(kHttpUrl, true, file_size);
277 280
278 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); 281 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
279 Respond(response_generator_->Generate206(0)); 282 Respond(response_generator_->Generate206(0));
280 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize)); 283 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize));
281 ReceiveData(kDataSize); 284 ReceiveData(kDataSize);
282 } 285 }
283 286
284 // Helper to initialize tests with a valid file:// response. 287 // Helper to initialize tests with a valid file:// response.
285 void InitializeWithFileResponse() { 288 void InitializeWithFileResponse() {
286 Initialize(kFileUrl, true); 289 Initialize(kFileUrl, true);
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 response.SetHTTPHeaderField(WebString::FromUTF8("Etag"), 1511 response.SetHTTPHeaderField(WebString::FromUTF8("Etag"),
1509 WebString::FromUTF8(etag)); 1512 WebString::FromUTF8(etag));
1510 Respond(response); 1513 Respond(response);
1511 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize)); 1514 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize));
1512 ReceiveData(kDataSize); 1515 ReceiveData(kDataSize);
1513 1516
1514 EXPECT_EQ(url_data()->etag(), etag); 1517 EXPECT_EQ(url_data()->etag(), etag);
1515 } 1518 }
1516 1519
1517 TEST_F(MultibufferDataSourceTest, CheckBufferSizes) { 1520 TEST_F(MultibufferDataSourceTest, CheckBufferSizes) {
1518 InitializeWith206Response(); 1521 InitializeWith206Response(1 << 30); // 1 gb
1519 1522
1520 data_source_->SetBitrate(1 << 20); // 1 mbit / s 1523 data_source_->SetBitrate(1 << 20); // 1 mbit / s
1521 base::RunLoop().RunUntilIdle(); 1524 base::RunLoop().RunUntilIdle();
1522 EXPECT_EQ(1 << 20, data_source_bitrate()); 1525 EXPECT_EQ(1 << 20, data_source_bitrate());
1523 EXPECT_EQ(2 << 20, preload_low()); 1526 EXPECT_EQ(2 << 20, preload_low());
1524 EXPECT_EQ(3 << 20, preload_high()); 1527 EXPECT_EQ(3 << 20, preload_high());
1525 EXPECT_EQ(25 << 20, max_buffer_forward()); 1528 EXPECT_EQ(25 << 20, max_buffer_forward());
1526 EXPECT_EQ(2 << 20, max_buffer_backward()); 1529 EXPECT_EQ(2 << 20, max_buffer_backward());
1527 EXPECT_EQ(1572864 /* 1.5Mb */, buffer_size()); 1530 EXPECT_EQ(1572864 /* 1.5Mb */, buffer_size());
1528 1531
(...skipping 27 matching lines...) Expand all
1556 data_source_->SetBitrate(80 << 20); // 80 mbit / s 1559 data_source_->SetBitrate(80 << 20); // 80 mbit / s
1557 base::RunLoop().RunUntilIdle(); 1560 base::RunLoop().RunUntilIdle();
1558 EXPECT_EQ(80 << 20, data_source_bitrate()); 1561 EXPECT_EQ(80 << 20, data_source_bitrate());
1559 EXPECT_EQ(50 << 20, preload_low()); 1562 EXPECT_EQ(50 << 20, preload_low());
1560 EXPECT_EQ(51 << 20, preload_high()); 1563 EXPECT_EQ(51 << 20, preload_high());
1561 EXPECT_EQ(51 << 20, max_buffer_forward()); 1564 EXPECT_EQ(51 << 20, max_buffer_forward());
1562 EXPECT_EQ(20 << 20, max_buffer_backward()); 1565 EXPECT_EQ(20 << 20, max_buffer_backward());
1563 EXPECT_EQ(71 << 20, buffer_size()); 1566 EXPECT_EQ(71 << 20, buffer_size());
1564 } 1567 }
1565 1568
1569 TEST_F(MultibufferDataSourceTest, CheckBufferSizeForSmallFiles) {
1570 InitializeWith206Response();
1571
1572 data_source_->SetBitrate(1 << 20); // 1 mbit / s
1573 base::RunLoop().RunUntilIdle();
1574 EXPECT_EQ(1 << 20, data_source_bitrate());
1575 EXPECT_EQ(2 << 20, preload_low());
1576 EXPECT_EQ(3 << 20, preload_high());
1577 EXPECT_EQ(25 << 20, max_buffer_forward());
1578 EXPECT_EQ(kFileSize * 2, max_buffer_backward());
1579 EXPECT_EQ(5013504 /* file size rounted up to blocks size */, buffer_size());
1580
1581 data_source_->SetBitrate(80 << 20); // 80 mbit / s
1582 base::RunLoop().RunUntilIdle();
1583 EXPECT_EQ(80 << 20, data_source_bitrate());
1584 EXPECT_EQ(50 << 20, preload_low());
1585 EXPECT_EQ(51 << 20, preload_high());
1586 EXPECT_EQ(51 << 20, max_buffer_forward());
1587 EXPECT_EQ(20 << 20, max_buffer_backward());
1588 EXPECT_EQ(5013504 /* file size rounted up to blocks size */, buffer_size());
1589 }
1590
1566 // Provoke an edge case where the loading state may not end up transitioning 1591 // Provoke an edge case where the loading state may not end up transitioning
1567 // back to "idle" when we're done loading. 1592 // back to "idle" when we're done loading.
1568 TEST_F(MultibufferDataSourceTest, Http_CheckLoadingTransition) { 1593 TEST_F(MultibufferDataSourceTest, Http_CheckLoadingTransition) {
1569 GURL gurl(kHttpUrl); 1594 GURL gurl(kHttpUrl);
1570 data_source_.reset(new MockMultibufferDataSource( 1595 data_source_.reset(new MockMultibufferDataSource(
1571 gurl, UrlData::CORS_UNSPECIFIED, message_loop_.task_runner(), url_index_, 1596 gurl, UrlData::CORS_UNSPECIFIED, message_loop_.task_runner(), url_index_,
1572 view_->MainFrame()->ToWebLocalFrame(), &host_)); 1597 view_->MainFrame()->ToWebLocalFrame(), &host_));
1573 data_source_->SetPreload(preload_); 1598 data_source_->SetPreload(preload_);
1574 1599
1575 response_generator_.reset(new TestResponseGenerator(gurl, kDataSize * 1)); 1600 response_generator_.reset(new TestResponseGenerator(gurl, kDataSize * 1));
(...skipping 21 matching lines...) Expand all
1597 base::Bind(&MultibufferDataSourceTest::ReadCallback, 1622 base::Bind(&MultibufferDataSourceTest::ReadCallback,
1598 base::Unretained(this))); 1623 base::Unretained(this)));
1599 base::RunLoop().RunUntilIdle(); 1624 base::RunLoop().RunUntilIdle();
1600 1625
1601 // Make sure we're not downloading anymore. 1626 // Make sure we're not downloading anymore.
1602 EXPECT_EQ(data_source_->downloading(), false); 1627 EXPECT_EQ(data_source_->downloading(), false);
1603 Stop(); 1628 Stop();
1604 } 1629 }
1605 1630
1606 } // namespace media 1631 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/multibuffer_data_source.cc ('k') | media/blink/resource_multibuffer_data_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698