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

Side by Side Diff: content/renderer/media/buffered_data_source_unittest.cc

Issue 435023002: Revert "Revert 285479 "Make DataSource::Stop() synchronous."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/buffered_data_source.cc ('k') | media/base/data_source.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 "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
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(media::NewExpectedClosure()); 181 data_source_->Stop();
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
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
533 TEST_F(BufferedDataSourceTest, StopDuringRead) { 508 TEST_F(BufferedDataSourceTest, StopDuringRead) {
534 InitializeWith206Response(); 509 InitializeWith206Response();
535 510
536 uint8 buffer[256]; 511 uint8 buffer[256];
537 data_source_->Read(0, arraysize(buffer), buffer, base::Bind( 512 data_source_->Read(0, arraysize(buffer), buffer, base::Bind(
538 &BufferedDataSourceTest::ReadCallback, base::Unretained(this))); 513 &BufferedDataSourceTest::ReadCallback, base::Unretained(this)));
539 514
540 // The outstanding read should fail before the stop callback runs. 515 // The outstanding read should fail before the stop callback runs.
541 { 516 {
542 InSequence s; 517 InSequence s;
543 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 518 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
544 data_source_->Stop(media::NewExpectedClosure()); 519 data_source_->Stop();
545 } 520 }
546 message_loop_.RunUntilIdle(); 521 message_loop_.RunUntilIdle();
547 } 522 }
548 523
549 TEST_F(BufferedDataSourceTest, DefaultValues) { 524 TEST_F(BufferedDataSourceTest, DefaultValues) {
550 InitializeWith206Response(); 525 InitializeWith206Response();
551 526
552 // Ensure we have sane values for default loading scenario. 527 // Ensure we have sane values for default loading scenario.
553 EXPECT_EQ(AUTO, preload()); 528 EXPECT_EQ(AUTO, preload());
554 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); 529 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy());
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 data_source_->MediaIsPlaying(); 771 data_source_->MediaIsPlaying();
797 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); 772 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy());
798 set_might_be_reused_from_cache_in_future(false); 773 set_might_be_reused_from_cache_in_future(false);
799 data_source_->MediaIsPaused(); 774 data_source_->MediaIsPaused();
800 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); 775 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy());
801 776
802 Stop(); 777 Stop();
803 } 778 }
804 779
805 } // namespace content 780 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/buffered_data_source.cc ('k') | media/base/data_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698