OLD | NEW |
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "content/public/common/url_constants.h" | 7 #include "content/public/common/url_constants.h" |
8 #include "content/renderer/media/buffered_data_source.h" | 8 #include "content/renderer/media/buffered_data_source.h" |
9 #include "content/renderer/media/test_response_generator.h" | 9 #include "content/renderer/media/test_response_generator.h" |
10 #include "content/test/mock_webframeclient.h" | 10 #include "content/test/mock_webframeclient.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // Stops any active loaders and shuts down the data source. | 171 // Stops any active loaders and shuts down the data source. |
172 // | 172 // |
173 // This typically happens when the page is closed and for our purposes is | 173 // This typically happens when the page is closed and for our purposes is |
174 // appropriate to do when tearing down a test. | 174 // appropriate to do when tearing down a test. |
175 void Stop() { | 175 void Stop() { |
176 if (data_source_->loading()) { | 176 if (data_source_->loading()) { |
177 loader()->didFail(url_loader(), response_generator_->GenerateError()); | 177 loader()->didFail(url_loader(), response_generator_->GenerateError()); |
178 message_loop_.RunUntilIdle(); | 178 message_loop_.RunUntilIdle(); |
179 } | 179 } |
180 | 180 |
181 data_source_->Stop(); | 181 data_source_->Stop(media::NewExpectedClosure()); |
182 message_loop_.RunUntilIdle(); | 182 message_loop_.RunUntilIdle(); |
183 } | 183 } |
184 | 184 |
185 void ExpectCreateResourceLoader() { | 185 void ExpectCreateResourceLoader() { |
186 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) | 186 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) |
187 .WillOnce(Invoke(data_source_.get(), | 187 .WillOnce(Invoke(data_source_.get(), |
188 &MockBufferedDataSource::CreateMockResourceLoader)); | 188 &MockBufferedDataSource::CreateMockResourceLoader)); |
189 message_loop_.RunUntilIdle(); | 189 message_loop_.RunUntilIdle(); |
190 } | 190 } |
191 | 191 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 498 } |
499 | 499 |
500 TEST_F(BufferedDataSourceTest, File_Successful) { | 500 TEST_F(BufferedDataSourceTest, File_Successful) { |
501 InitializeWithFileResponse(); | 501 InitializeWithFileResponse(); |
502 | 502 |
503 EXPECT_TRUE(data_source_->loading()); | 503 EXPECT_TRUE(data_source_->loading()); |
504 EXPECT_FALSE(data_source_->IsStreaming()); | 504 EXPECT_FALSE(data_source_->IsStreaming()); |
505 Stop(); | 505 Stop(); |
506 } | 506 } |
507 | 507 |
| 508 static void SetTrue(bool* value) { |
| 509 *value = true; |
| 510 } |
| 511 |
| 512 // This test makes sure that Stop() does not require a task to run on |
| 513 // |message_loop_| before it calls its callback. This prevents accidental |
| 514 // introduction of a pipeline teardown deadlock. The pipeline owner blocks |
| 515 // the render message loop while waiting for Stop() to complete. Since this |
| 516 // object runs on the render message loop, Stop() will not complete if it |
| 517 // requires a task to run on the the message loop that is being blocked. |
| 518 TEST_F(BufferedDataSourceTest, StopDoesNotUseMessageLoopForCallback) { |
| 519 InitializeWith206Response(); |
| 520 |
| 521 // Stop() the data source, using a callback that lets us verify that it was |
| 522 // called before Stop() returns. This is to make sure that the callback does |
| 523 // not require |message_loop_| to execute tasks before being called. |
| 524 bool stop_done_called = false; |
| 525 EXPECT_TRUE(data_source_->loading()); |
| 526 data_source_->Stop(base::Bind(&SetTrue, &stop_done_called)); |
| 527 |
| 528 // Verify that the callback was called inside the Stop() call. |
| 529 EXPECT_TRUE(stop_done_called); |
| 530 message_loop_.RunUntilIdle(); |
| 531 } |
| 532 |
508 TEST_F(BufferedDataSourceTest, StopDuringRead) { | 533 TEST_F(BufferedDataSourceTest, StopDuringRead) { |
509 InitializeWith206Response(); | 534 InitializeWith206Response(); |
510 | 535 |
511 uint8 buffer[256]; | 536 uint8 buffer[256]; |
512 data_source_->Read(0, arraysize(buffer), buffer, base::Bind( | 537 data_source_->Read(0, arraysize(buffer), buffer, base::Bind( |
513 &BufferedDataSourceTest::ReadCallback, base::Unretained(this))); | 538 &BufferedDataSourceTest::ReadCallback, base::Unretained(this))); |
514 | 539 |
515 // The outstanding read should fail before the stop callback runs. | 540 // The outstanding read should fail before the stop callback runs. |
516 { | 541 { |
517 InSequence s; | 542 InSequence s; |
518 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 543 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
519 data_source_->Stop(); | 544 data_source_->Stop(media::NewExpectedClosure()); |
520 } | 545 } |
521 message_loop_.RunUntilIdle(); | 546 message_loop_.RunUntilIdle(); |
522 } | 547 } |
523 | 548 |
524 TEST_F(BufferedDataSourceTest, DefaultValues) { | 549 TEST_F(BufferedDataSourceTest, DefaultValues) { |
525 InitializeWith206Response(); | 550 InitializeWith206Response(); |
526 | 551 |
527 // Ensure we have sane values for default loading scenario. | 552 // Ensure we have sane values for default loading scenario. |
528 EXPECT_EQ(AUTO, preload()); | 553 EXPECT_EQ(AUTO, preload()); |
529 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); | 554 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 data_source_->MediaIsPlaying(); | 796 data_source_->MediaIsPlaying(); |
772 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); | 797 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
773 set_might_be_reused_from_cache_in_future(false); | 798 set_might_be_reused_from_cache_in_future(false); |
774 data_source_->MediaIsPaused(); | 799 data_source_->MediaIsPaused(); |
775 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); | 800 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
776 | 801 |
777 Stop(); | 802 Stop(); |
778 } | 803 } |
779 | 804 |
780 } // namespace content | 805 } // namespace content |
OLD | NEW |