Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 6 |
| 7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
| 8 #include "media/base/mock_callback.h" | 8 #include "media/base/mock_callback.h" |
| 9 #include "media/base/mock_filter_host.h" | 9 #include "media/base/mock_filter_host.h" |
| 10 #include "media/base/mock_filters.h" | 10 #include "media/base/mock_filters.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 ReadDataSourceTimesOut(20, 10); | 485 ReadDataSourceTimesOut(20, 10); |
| 486 StopDataSource(); | 486 StopDataSource(); |
| 487 } | 487 } |
| 488 | 488 |
| 489 TEST_F(BufferedDataSourceTest, FileHasLoadedState) { | 489 TEST_F(BufferedDataSourceTest, FileHasLoadedState) { |
| 490 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); | 490 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); |
| 491 ReadDataSourceTimesOut(20, 10); | 491 ReadDataSourceTimesOut(20, 10); |
| 492 StopDataSource(); | 492 StopDataSource(); |
| 493 } | 493 } |
| 494 | 494 |
| 495 // This test makes sure that Stop() does not require a task to run on | |
| 496 // |message_loop_| before it calls its callback. This prevents accidental | |
| 497 // introduction of a pipeline teardown deadlock. The pipeline owner blocks | |
| 498 // the render message loop while waiting for Stop() to complete. Since this | |
| 499 // object runs on the render message loop, Stop() will not complete if it | |
| 500 // requires a task to run on the the message loop that is being blocked. | |
| 501 TEST_F(BufferedDataSourceTest, StopDoesNotUseMessageLoopForCallback) { | |
| 502 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); | |
| 503 | |
| 504 // Create a callback that lets us verify that it was called before | |
| 505 // Stop() returns. This is to make sure that the callback does not | |
| 506 // require |message_loop_| to execute tasks before being called. | |
| 507 media::MockCallback* stop_callback = media::NewExpectedCallback(); | |
| 508 bool stop_done_called = false; | |
| 509 ON_CALL(*stop_callback, RunWithParams(_)) | |
|
scherkus (not reviewing)
2011/01/26 03:04:10
nice usage :)
to confirm this keeps the expectati
acolwell GONE FROM CHROMIUM
2011/01/26 17:41:05
Thanks.
| |
| 510 .WillByDefault(Assign(&stop_done_called, true)); | |
| 511 | |
| 512 // Stop() the data source like normal. | |
| 513 data_source_->Stop(stop_callback); | |
| 514 | |
| 515 // Verify that the callback was called inside the Stop() call. | |
| 516 EXPECT_TRUE(stop_done_called); | |
| 517 | |
| 518 message_loop_->RunAllPending(); | |
| 519 } | |
| 520 | |
| 521 TEST_F(BufferedDataSourceTest, AbortDuringPendingRead) { | |
| 522 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); | |
| 523 | |
| 524 // Setup a way to verify that Read() is not called on the loader. | |
| 525 // We are doing this to make sure that the ReadTask() is still on | |
| 526 // the message loop queue when Abort() is called. | |
| 527 bool read_called = false; | |
| 528 ON_CALL(*loader_, Read(_, _, _ , _)) | |
| 529 .WillByDefault(DoAll(Assign(&read_called, true), | |
| 530 DeleteArg<3>())); | |
| 531 | |
| 532 // Initiate a Read() on the data source, but don't allow the | |
| 533 // message loop to run. | |
| 534 data_source_->Read( | |
| 535 0, 10, buffer_, | |
| 536 NewCallback(static_cast<BufferedDataSourceTest*>(this), | |
| 537 &BufferedDataSourceTest::ReadCallback)); | |
| 538 | |
| 539 // Call Abort() with the read pending. | |
| 540 EXPECT_CALL(*this, ReadCallback(-1)); | |
| 541 EXPECT_CALL(*loader_, Stop()); | |
| 542 data_source_->Abort(); | |
| 543 | |
| 544 // Verify that Read()'s after the Abort() issue callback with an error. | |
| 545 EXPECT_CALL(*this, ReadCallback(-1)); | |
| 546 data_source_->Read( | |
| 547 0, 10, buffer_, | |
| 548 NewCallback(static_cast<BufferedDataSourceTest*>(this), | |
| 549 &BufferedDataSourceTest::ReadCallback)); | |
| 550 | |
| 551 // Stop() the data source like normal. | |
| 552 data_source_->Stop(media::NewExpectedCallback()); | |
| 553 | |
| 554 // Allow cleanup task to run. | |
| 555 message_loop_->RunAllPending(); | |
| 556 | |
| 557 // Verify that Read() was not called on the loader. | |
| 558 EXPECT_FALSE(read_called); | |
| 559 } | |
| 560 | |
| 495 } // namespace webkit_glue | 561 } // namespace webkit_glue |
| OLD | NEW |