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

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

Issue 2357773003: Fix a timing bug in multibuffer. (Closed)
Patch Set: comments addressed Created 4 years, 3 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 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 data_source_->OnBufferingHaveEnough(false); 1256 data_source_->OnBufferingHaveEnough(false);
1253 ASSERT_TRUE(active_loader()); 1257 ASSERT_TRUE(active_loader());
1254 1258
1255 EXPECT_CALL(*this, ReadCallback(kDataSize)); 1259 EXPECT_CALL(*this, ReadCallback(kDataSize));
1256 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2)); 1260 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2));
1257 ReceiveData(kDataSize); 1261 ReceiveData(kDataSize);
1258 1262
1259 EXPECT_FALSE(active_loader_allownull()); 1263 EXPECT_FALSE(active_loader_allownull());
1260 } 1264 }
1261 1265
1266 // This test tries to trigger an edge case where the read callback
1267 // never happens because the reader is deleted before that happens.
1268 TEST_F(MultibufferDataSourceTest,
1269 ExternalResource_Response206_CancelAfterDefer2) {
1270 set_preload(MultibufferDataSource::METADATA);
1271 InitializeWith206Response();
1272
1273 EXPECT_EQ(MultibufferDataSource::METADATA, preload());
1274 EXPECT_FALSE(is_local_source());
1275
1276 EXPECT_TRUE(data_source_->range_supported());
1277 CheckReadThenDefer();
1278
1279 ReadAt(kDataSize);
1280
1281 data_source_->OnBufferingHaveEnough(false);
1282 ASSERT_TRUE(active_loader());
1283
1284 EXPECT_CALL(*this, ReadCallback(kDataSize));
1285 EXPECT_CALL(host_, AddBufferedByteRange(kDataSize, kDataSize + 2000));
1286
1287 ReceiveDataLow(2000);
1288 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2 + 2000));
1289 ReceiveDataLow(kDataSize);
1290
1291 base::RunLoop().RunUntilIdle();
1292
1293 EXPECT_FALSE(active_loader_allownull());
1294 }
1295
1262 TEST_F(MultibufferDataSourceTest, 1296 TEST_F(MultibufferDataSourceTest,
1263 ExternalResource_Response206_CancelAfterPlay) { 1297 ExternalResource_Response206_CancelAfterPlay) {
1264 set_preload(MultibufferDataSource::METADATA); 1298 set_preload(MultibufferDataSource::METADATA);
1265 InitializeWith206Response(); 1299 InitializeWith206Response();
1266 1300
1267 EXPECT_EQ(MultibufferDataSource::METADATA, preload()); 1301 EXPECT_EQ(MultibufferDataSource::METADATA, preload());
1268 EXPECT_FALSE(is_local_source()); 1302 EXPECT_FALSE(is_local_source());
1269 1303
1270 EXPECT_TRUE(data_source_->range_supported()); 1304 EXPECT_TRUE(data_source_->range_supported());
1271 CheckReadThenDefer(); 1305 CheckReadThenDefer();
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 const std::string etag("\"arglebargle glop-glyf?\""); 1521 const std::string etag("\"arglebargle glop-glyf?\"");
1488 response.setHTTPHeaderField(WebString::fromUTF8("Etag"), 1522 response.setHTTPHeaderField(WebString::fromUTF8("Etag"),
1489 WebString::fromUTF8(etag)); 1523 WebString::fromUTF8(etag));
1490 Respond(response); 1524 Respond(response);
1491 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize)); 1525 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize));
1492 ReceiveData(kDataSize); 1526 ReceiveData(kDataSize);
1493 1527
1494 EXPECT_EQ(url_data()->etag(), etag); 1528 EXPECT_EQ(url_data()->etag(), etag);
1495 } 1529 }
1496 } // namespace media 1530 } // 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