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

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

Issue 2399463007: AssociatedURLLoader shouldn't derive from WebURLLoader (Closed)
Patch Set: Rebase Created 4 years, 1 month 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/mock_weburlloader.cc ('k') | media/blink/resource_multibuffer_data_provider.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 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"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "media/base/media_log.h" 13 #include "media/base/media_log.h"
14 #include "media/base/mock_filters.h" 14 #include "media/base/mock_filters.h"
15 #include "media/base/test_helpers.h" 15 #include "media/base/test_helpers.h"
16 #include "media/blink/buffered_data_source_host_impl.h" 16 #include "media/blink/buffered_data_source_host_impl.h"
17 #include "media/blink/mock_weburlloader.h" 17 #include "media/blink/mock_webassociatedurlloader.h"
18 #include "media/blink/multibuffer_data_source.h" 18 #include "media/blink/multibuffer_data_source.h"
19 #include "media/blink/multibuffer_reader.h" 19 #include "media/blink/multibuffer_reader.h"
20 #include "media/blink/resource_multibuffer_data_provider.h" 20 #include "media/blink/resource_multibuffer_data_provider.h"
21 #include "media/blink/test_response_generator.h" 21 #include "media/blink/test_response_generator.h"
22 #include "third_party/WebKit/public/platform/WebURLResponse.h" 22 #include "third_party/WebKit/public/platform/WebURLResponse.h"
23 #include "third_party/WebKit/public/web/WebFrameClient.h" 23 #include "third_party/WebKit/public/web/WebFrameClient.h"
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" 24 #include "third_party/WebKit/public/web/WebLocalFrame.h"
25 #include "third_party/WebKit/public/web/WebView.h" 25 #include "third_party/WebKit/public/web/WebView.h"
26 26
27 using ::testing::_; 27 using ::testing::_;
28 using ::testing::Assign; 28 using ::testing::Assign;
29 using ::testing::DoAll; 29 using ::testing::DoAll;
30 using ::testing::Invoke; 30 using ::testing::Invoke;
31 using ::testing::InvokeWithoutArgs; 31 using ::testing::InvokeWithoutArgs;
32 using ::testing::InSequence; 32 using ::testing::InSequence;
33 using ::testing::NiceMock; 33 using ::testing::NiceMock;
34 using ::testing::StrictMock; 34 using ::testing::StrictMock;
35 35
36 using blink::WebAssociatedURLLoader;
36 using blink::WebLocalFrame; 37 using blink::WebLocalFrame;
37 using blink::WebString; 38 using blink::WebString;
38 using blink::WebURLLoader;
39 using blink::WebURLResponse; 39 using blink::WebURLResponse;
40 using blink::WebView; 40 using blink::WebView;
41 41
42 namespace media { 42 namespace media {
43 43
44 class TestResourceMultiBuffer; 44 class TestResourceMultiBuffer;
45 class TestMultiBufferDataProvider; 45 class TestMultiBufferDataProvider;
46 46
47 std::set<TestMultiBufferDataProvider*> test_data_providers; 47 std::set<TestMultiBufferDataProvider*> test_data_providers;
48 48
49 class TestMultiBufferDataProvider : public ResourceMultiBufferDataProvider { 49 class TestMultiBufferDataProvider : public ResourceMultiBufferDataProvider {
50 public: 50 public:
51 TestMultiBufferDataProvider(UrlData* url_data, MultiBuffer::BlockId pos) 51 TestMultiBufferDataProvider(UrlData* url_data, MultiBuffer::BlockId pos)
52 : ResourceMultiBufferDataProvider(url_data, pos), loading_(false) { 52 : ResourceMultiBufferDataProvider(url_data, pos), loading_(false) {
53 CHECK(test_data_providers.insert(this).second); 53 CHECK(test_data_providers.insert(this).second);
54 } 54 }
55 ~TestMultiBufferDataProvider() override { 55 ~TestMultiBufferDataProvider() override {
56 CHECK_EQ(static_cast<size_t>(1), test_data_providers.erase(this)); 56 CHECK_EQ(static_cast<size_t>(1), test_data_providers.erase(this));
57 } 57 }
58 void Start() override { 58 void Start() override {
59 // Create a mock active loader. 59 // Create a mock active loader.
60 // Keep track of active loading state via loadAsynchronously() and cancel(). 60 // Keep track of active loading state via loadAsynchronously() and cancel().
61 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); 61 NiceMock<MockWebAssociatedURLLoader>* url_loader =
62 new NiceMock<MockWebAssociatedURLLoader>();
62 ON_CALL(*url_loader, cancel()) 63 ON_CALL(*url_loader, cancel())
63 .WillByDefault(Invoke([this]() { 64 .WillByDefault(Invoke([this]() {
64 // Check that we have not been destroyed first. 65 // Check that we have not been destroyed first.
65 if (test_data_providers.find(this) != test_data_providers.end()) { 66 if (test_data_providers.find(this) != test_data_providers.end()) {
66 this->loading_ = false; 67 this->loading_ = false;
67 } 68 }
68 })); 69 }));
69 loading_ = true; 70 loading_ = true;
70 active_loader_.reset( 71 active_loader_.reset(
71 new ActiveLoader(std::unique_ptr<WebURLLoader>(url_loader))); 72 new ActiveLoader(std::unique_ptr<WebAssociatedURLLoader>(url_loader)));
72 if (!on_start_.is_null()) { 73 if (!on_start_.is_null()) {
73 on_start_.Run(); 74 on_start_.Run();
74 } 75 }
75 } 76 }
76 77
77 bool loading() const { return loading_; } 78 bool loading() const { return loading_; }
78 void RunOnStart(base::Closure cb) { on_start_ = cb; } 79 void RunOnStart(base::Closure cb) { on_start_ = cb; }
79 80
80 private: 81 private:
81 bool loading_; 82 bool loading_;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 293
293 ReceiveData(kDataSize); 294 ReceiveData(kDataSize);
294 } 295 }
295 296
296 // Stops any active loaders and shuts down the data source. 297 // Stops any active loaders and shuts down the data source.
297 // 298 //
298 // This typically happens when the page is closed and for our purposes is 299 // This typically happens when the page is closed and for our purposes is
299 // appropriate to do when tearing down a test. 300 // appropriate to do when tearing down a test.
300 void Stop() { 301 void Stop() {
301 if (loading()) { 302 if (loading()) {
302 data_provider()->didFail(url_loader(), 303 data_provider()->didFail(response_generator_->GenerateError());
303 response_generator_->GenerateError());
304 base::RunLoop().RunUntilIdle(); 304 base::RunLoop().RunUntilIdle();
305 } 305 }
306 306
307 data_source_->Stop(); 307 data_source_->Stop();
308 base::RunLoop().RunUntilIdle(); 308 base::RunLoop().RunUntilIdle();
309 } 309 }
310 310
311 void Respond(const WebURLResponse& response) { 311 void Respond(const WebURLResponse& response) {
312 EXPECT_TRUE(url_loader()); 312 EXPECT_TRUE(url_loader());
313 if (!active_loader()) 313 if (!active_loader())
314 return; 314 return;
315 data_provider()->didReceiveResponse(url_loader(), response); 315 data_provider()->didReceiveResponse(response);
316 base::RunLoop().RunUntilIdle(); 316 base::RunLoop().RunUntilIdle();
317 } 317 }
318 318
319 void ReceiveDataLow(int size) { 319 void ReceiveDataLow(int size) {
320 EXPECT_TRUE(url_loader()); 320 EXPECT_TRUE(url_loader());
321 if (!url_loader()) 321 if (!url_loader())
322 return; 322 return;
323 std::unique_ptr<char[]> data(new char[size]); 323 std::unique_ptr<char[]> data(new char[size]);
324 memset(data.get(), 0xA5, size); // Arbitrary non-zero value. 324 memset(data.get(), 0xA5, size); // Arbitrary non-zero value.
325 325
326 data_provider()->didReceiveData(url_loader(), data.get(), size, size, size); 326 data_provider()->didReceiveData(data.get(), size);
327 } 327 }
328 328
329 void ReceiveData(int size) { 329 void ReceiveData(int size) {
330 ReceiveDataLow(size); 330 ReceiveDataLow(size);
331 base::RunLoop().RunUntilIdle(); 331 base::RunLoop().RunUntilIdle();
332 } 332 }
333 333
334 void FinishLoading() { 334 void FinishLoading() {
335 EXPECT_TRUE(url_loader()); 335 EXPECT_TRUE(url_loader());
336 if (!url_loader()) 336 if (!url_loader())
337 return; 337 return;
338 data_provider()->didFinishLoading(url_loader(), 0, -1); 338 data_provider()->didFinishLoading(0);
339 base::RunLoop().RunUntilIdle(); 339 base::RunLoop().RunUntilIdle();
340 } 340 }
341 341
342 void FailLoading() { 342 void FailLoading() {
343 data_provider()->didFail(url_loader(), 343 data_provider()->didFail(response_generator_->GenerateError());
344 response_generator_->GenerateError());
345 base::RunLoop().RunUntilIdle(); 344 base::RunLoop().RunUntilIdle();
346 } 345 }
347 346
348 void Restart() { 347 void Restart() {
349 EXPECT_TRUE(data_provider()); 348 EXPECT_TRUE(data_provider());
350 EXPECT_FALSE(active_loader_allownull()); 349 EXPECT_FALSE(active_loader_allownull());
351 if (!data_provider()) 350 if (!data_provider())
352 return; 351 return;
353 data_provider()->Start(); 352 data_provider()->Start();
354 } 353 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 return nullptr; 437 return nullptr;
439 return data_provider()->active_loader_.get(); 438 return data_provider()->active_loader_.get();
440 } 439 }
441 ActiveLoader* active_loader_allownull() { 440 ActiveLoader* active_loader_allownull() {
442 TestMultiBufferDataProvider* data_provider = 441 TestMultiBufferDataProvider* data_provider =
443 multibuffer()->GetProvider_allownull(); 442 multibuffer()->GetProvider_allownull();
444 if (!data_provider) 443 if (!data_provider)
445 return nullptr; 444 return nullptr;
446 return data_provider->active_loader_.get(); 445 return data_provider->active_loader_.get();
447 } 446 }
448 WebURLLoader* url_loader() { 447 WebAssociatedURLLoader* url_loader() {
449 EXPECT_TRUE(active_loader()); 448 EXPECT_TRUE(active_loader());
450 if (!active_loader()) 449 if (!active_loader())
451 return nullptr; 450 return nullptr;
452 return active_loader()->loader_.get(); 451 return active_loader()->loader_.get();
453 } 452 }
454 453
455 bool loading() { return multibuffer()->loading(); } 454 bool loading() { return multibuffer()->loading(); }
456 455
457 MultibufferDataSource::Preload preload() { return data_source_->preload_; } 456 MultibufferDataSource::Preload preload() { return data_source_->preload_; }
458 void set_preload(MultibufferDataSource::Preload preload) { 457 void set_preload(MultibufferDataSource::Preload preload) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 664
666 // Read to advance our position. 665 // Read to advance our position.
667 EXPECT_CALL(*this, ReadCallback(kDataSize)); 666 EXPECT_CALL(*this, ReadCallback(kDataSize));
668 ReadAt(0); 667 ReadAt(0);
669 668
670 // Issue a pending read but trigger an error to force a retry. 669 // Issue a pending read but trigger an error to force a retry.
671 EXPECT_CALL(*this, ReadCallback(kDataSize)); 670 EXPECT_CALL(*this, ReadCallback(kDataSize));
672 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2)); 671 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2));
673 ReadAt(kDataSize); 672 ReadAt(kDataSize);
674 base::RunLoop run_loop; 673 base::RunLoop run_loop;
675 data_provider()->didFail(url_loader(), response_generator_->GenerateError()); 674 data_provider()->didFail(response_generator_->GenerateError());
676 data_provider()->RunOnStart(run_loop.QuitClosure()); 675 data_provider()->RunOnStart(run_loop.QuitClosure());
677 run_loop.Run(); 676 run_loop.Run();
678 Respond(response_generator_->Generate206(kDataSize)); 677 Respond(response_generator_->Generate206(kDataSize));
679 ReceiveData(kDataSize); 678 ReceiveData(kDataSize);
680 FinishLoading(); 679 FinishLoading();
681 EXPECT_FALSE(loading()); 680 EXPECT_FALSE(loading());
682 Stop(); 681 Stop();
683 } 682 }
684 683
685 // Make sure that we prefetch across partial responses. (crbug.com/516589) 684 // Make sure that we prefetch across partial responses. (crbug.com/516589)
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 1371
1373 // Read to advance our position. 1372 // Read to advance our position.
1374 EXPECT_CALL(*this, ReadCallback(kDataSize)); 1373 EXPECT_CALL(*this, ReadCallback(kDataSize));
1375 ReadAt(0); 1374 ReadAt(0);
1376 1375
1377 // Issue a pending read but trigger an error to force a retry. 1376 // Issue a pending read but trigger an error to force a retry.
1378 EXPECT_CALL(*this, ReadCallback(kDataSize - 10)); 1377 EXPECT_CALL(*this, ReadCallback(kDataSize - 10));
1379 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2)); 1378 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2));
1380 ReadAt(kDataSize + 10, kDataSize - 10); 1379 ReadAt(kDataSize + 10, kDataSize - 10);
1381 base::RunLoop run_loop; 1380 base::RunLoop run_loop;
1382 data_provider()->didFail(url_loader(), response_generator_->GenerateError()); 1381 data_provider()->didFail(response_generator_->GenerateError());
1383 data_provider()->RunOnStart(run_loop.QuitClosure()); 1382 data_provider()->RunOnStart(run_loop.QuitClosure());
1384 run_loop.Run(); 1383 run_loop.Run();
1385 1384
1386 // Server responds with a redirect. 1385 // Server responds with a redirect.
1387 blink::WebURLRequest request((GURL(kHttpDifferentPathUrl))); 1386 blink::WebURLRequest request((GURL(kHttpDifferentPathUrl)));
1388 blink::WebURLResponse response((GURL(kHttpUrl))); 1387 blink::WebURLResponse response((GURL(kHttpUrl)));
1389 response.setHTTPStatusCode(307); 1388 response.setHTTPStatusCode(307);
1390 data_provider()->willFollowRedirect(url_loader(), request, response); 1389 data_provider()->willFollowRedirect(request, response);
1391 Respond(response_generator_->Generate206(kDataSize)); 1390 Respond(response_generator_->Generate206(kDataSize));
1392 ReceiveData(kDataSize); 1391 ReceiveData(kDataSize);
1393 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 3)); 1392 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 3));
1394 FinishLoading(); 1393 FinishLoading();
1395 EXPECT_FALSE(loading()); 1394 EXPECT_FALSE(loading());
1396 Stop(); 1395 Stop();
1397 } 1396 }
1398 1397
1399 TEST_F(MultibufferDataSourceTest, Http_NotStreamingAfterRedirect) { 1398 TEST_F(MultibufferDataSourceTest, Http_NotStreamingAfterRedirect) {
1400 Initialize(kHttpUrl, true); 1399 Initialize(kHttpUrl, true);
1401 1400
1402 // Server responds with a redirect. 1401 // Server responds with a redirect.
1403 blink::WebURLRequest request((GURL(kHttpDifferentPathUrl))); 1402 blink::WebURLRequest request((GURL(kHttpDifferentPathUrl)));
1404 blink::WebURLResponse response((GURL(kHttpUrl))); 1403 blink::WebURLResponse response((GURL(kHttpUrl)));
1405 response.setHTTPStatusCode(307); 1404 response.setHTTPStatusCode(307);
1406 data_provider()->willFollowRedirect(url_loader(), request, response); 1405 data_provider()->willFollowRedirect(request, response);
1407 1406
1408 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); 1407 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length()));
1409 Respond(response_generator_->Generate206(0)); 1408 Respond(response_generator_->Generate206(0));
1410 1409
1411 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize)); 1410 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize));
1412 ReceiveData(kDataSize); 1411 ReceiveData(kDataSize);
1413 1412
1414 EXPECT_FALSE(data_source_->IsStreaming()); 1413 EXPECT_FALSE(data_source_->IsStreaming());
1415 1414
1416 FinishLoading(); 1415 FinishLoading();
1417 EXPECT_FALSE(loading()); 1416 EXPECT_FALSE(loading());
1418 Stop(); 1417 Stop();
1419 } 1418 }
1420 1419
1421 TEST_F(MultibufferDataSourceTest, Http_RangeNotSatisfiableAfterRedirect) { 1420 TEST_F(MultibufferDataSourceTest, Http_RangeNotSatisfiableAfterRedirect) {
1422 Initialize(kHttpUrl, true); 1421 Initialize(kHttpUrl, true);
1423 1422
1424 // Server responds with a redirect. 1423 // Server responds with a redirect.
1425 blink::WebURLRequest request((GURL(kHttpDifferentPathUrl))); 1424 blink::WebURLRequest request((GURL(kHttpDifferentPathUrl)));
1426 blink::WebURLResponse response((GURL(kHttpUrl))); 1425 blink::WebURLResponse response((GURL(kHttpUrl)));
1427 response.setHTTPStatusCode(307); 1426 response.setHTTPStatusCode(307);
1428 data_provider()->willFollowRedirect(url_loader(), request, response); 1427 data_provider()->willFollowRedirect(request, response);
1429 1428
1430 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize)); 1429 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize));
1431 Respond(response_generator_->GenerateResponse(416)); 1430 Respond(response_generator_->GenerateResponse(416));
1432 Stop(); 1431 Stop();
1433 } 1432 }
1434 1433
1435 TEST_F(MultibufferDataSourceTest, LengthKnownAtEOF) { 1434 TEST_F(MultibufferDataSourceTest, LengthKnownAtEOF) {
1436 Initialize(kHttpUrl, true); 1435 Initialize(kHttpUrl, true);
1437 // Server responds without content-length. 1436 // Server responds without content-length.
1438 WebURLResponse response = response_generator_->Generate200(); 1437 WebURLResponse response = response_generator_->Generate200();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 const std::string etag("\"arglebargle glop-glyf?\""); 1518 const std::string etag("\"arglebargle glop-glyf?\"");
1520 response.setHTTPHeaderField(WebString::fromUTF8("Etag"), 1519 response.setHTTPHeaderField(WebString::fromUTF8("Etag"),
1521 WebString::fromUTF8(etag)); 1520 WebString::fromUTF8(etag));
1522 Respond(response); 1521 Respond(response);
1523 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize)); 1522 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize));
1524 ReceiveData(kDataSize); 1523 ReceiveData(kDataSize);
1525 1524
1526 EXPECT_EQ(url_data()->etag(), etag); 1525 EXPECT_EQ(url_data()->etag(), etag);
1527 } 1526 }
1528 } // namespace media 1527 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/mock_weburlloader.cc ('k') | media/blink/resource_multibuffer_data_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698