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

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

Issue 2362953002: Fix a timing bug in multibuffer. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « media/blink/multibuffer_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 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 310 }
311 311
312 void Respond(const WebURLResponse& response) { 312 void Respond(const WebURLResponse& response) {
313 EXPECT_TRUE(url_loader()); 313 EXPECT_TRUE(url_loader());
314 if (!active_loader()) 314 if (!active_loader())
315 return; 315 return;
316 data_provider()->didReceiveResponse(url_loader(), response); 316 data_provider()->didReceiveResponse(url_loader(), response);
317 base::RunLoop().RunUntilIdle(); 317 base::RunLoop().RunUntilIdle();
318 } 318 }
319 319
320 void ReceiveData(int size) { 320 void ReceiveDataLow(int size) {
321 EXPECT_TRUE(url_loader()); 321 EXPECT_TRUE(url_loader());
322 if (!url_loader()) 322 if (!url_loader())
323 return; 323 return;
324 std::unique_ptr<char[]> data(new char[size]); 324 std::unique_ptr<char[]> data(new char[size]);
325 memset(data.get(), 0xA5, size); // Arbitrary non-zero value. 325 memset(data.get(), 0xA5, size); // Arbitrary non-zero value.
326 326
327 data_provider()->didReceiveData(url_loader(), data.get(), size, size, size); 327 data_provider()->didReceiveData(url_loader(), data.get(), size, size, size);
328 }
329
330 void ReceiveData(int size) {
331 ReceiveDataLow(size);
328 base::RunLoop().RunUntilIdle(); 332 base::RunLoop().RunUntilIdle();
329 } 333 }
330 334
331 void FinishLoading() { 335 void FinishLoading() {
332 EXPECT_TRUE(url_loader()); 336 EXPECT_TRUE(url_loader());
333 if (!url_loader()) 337 if (!url_loader())
334 return; 338 return;
335 data_provider()->didFinishLoading(url_loader(), 0, -1); 339 data_provider()->didFinishLoading(url_loader(), 0, -1);
336 base::RunLoop().RunUntilIdle(); 340 base::RunLoop().RunUntilIdle();
337 } 341 }
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 data_source_->OnBufferingHaveEnough(false); 1255 data_source_->OnBufferingHaveEnough(false);
1252 ASSERT_TRUE(active_loader()); 1256 ASSERT_TRUE(active_loader());
1253 1257
1254 EXPECT_CALL(*this, ReadCallback(kDataSize)); 1258 EXPECT_CALL(*this, ReadCallback(kDataSize));
1255 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2)); 1259 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2));
1256 ReceiveData(kDataSize); 1260 ReceiveData(kDataSize);
1257 1261
1258 EXPECT_FALSE(active_loader_allownull()); 1262 EXPECT_FALSE(active_loader_allownull());
1259 } 1263 }
1260 1264
1265 // This test tries to trigger an edge case where the read callback
1266 // never happens because the reader is deleted before that happens.
1267 TEST_F(MultibufferDataSourceTest,
1268 ExternalResource_Response206_CancelAfterDefer2) {
1269 set_preload(MultibufferDataSource::METADATA);
1270 InitializeWith206Response();
1271
1272 EXPECT_EQ(MultibufferDataSource::METADATA, preload());
1273 EXPECT_FALSE(is_local_source());
1274
1275 EXPECT_TRUE(data_source_->range_supported());
1276 CheckReadThenDefer();
1277
1278 ReadAt(kDataSize);
1279
1280 data_source_->OnBufferingHaveEnough(false);
1281 ASSERT_TRUE(active_loader());
1282
1283 EXPECT_CALL(*this, ReadCallback(kDataSize));
1284 EXPECT_CALL(host_, AddBufferedByteRange(kDataSize, kDataSize + 2000));
1285
1286 ReceiveDataLow(2000);
1287 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2 + 2000));
1288 ReceiveDataLow(kDataSize);
1289
1290 base::RunLoop().RunUntilIdle();
1291
1292 EXPECT_FALSE(active_loader_allownull());
1293 }
1294
1261 TEST_F(MultibufferDataSourceTest, 1295 TEST_F(MultibufferDataSourceTest,
1262 ExternalResource_Response206_CancelAfterPlay) { 1296 ExternalResource_Response206_CancelAfterPlay) {
1263 set_preload(MultibufferDataSource::METADATA); 1297 set_preload(MultibufferDataSource::METADATA);
1264 InitializeWith206Response(); 1298 InitializeWith206Response();
1265 1299
1266 EXPECT_EQ(MultibufferDataSource::METADATA, preload()); 1300 EXPECT_EQ(MultibufferDataSource::METADATA, preload());
1267 EXPECT_FALSE(is_local_source()); 1301 EXPECT_FALSE(is_local_source());
1268 1302
1269 EXPECT_TRUE(data_source_->range_supported()); 1303 EXPECT_TRUE(data_source_->range_supported());
1270 CheckReadThenDefer(); 1304 CheckReadThenDefer();
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 FinishLoading(); 1506 FinishLoading();
1473 1507
1474 // Verify that if reader_ is null, DidPassCORSAccessCheck still returns true. 1508 // Verify that if reader_ is null, DidPassCORSAccessCheck still returns true.
1475 data_source_->Stop(); 1509 data_source_->Stop();
1476 base::RunLoop().RunUntilIdle(); 1510 base::RunLoop().RunUntilIdle();
1477 1511
1478 EXPECT_TRUE(data_source_->DidPassCORSAccessCheck()); 1512 EXPECT_TRUE(data_source_->DidPassCORSAccessCheck());
1479 } 1513 }
1480 1514
1481 } // namespace media 1515 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/multibuffer_data_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698