Index: content/renderer/media/buffered_data_source_unittest.cc |
diff --git a/content/renderer/media/buffered_data_source_unittest.cc b/content/renderer/media/buffered_data_source_unittest.cc |
index 37ff6f8782d1f69a2dda78cbc1283659eababdab..403a93b8308ea8d2ed8690c02d8f836b2229a9a7 100644 |
--- a/content/renderer/media/buffered_data_source_unittest.cc |
+++ b/content/renderer/media/buffered_data_source_unittest.cc |
@@ -110,7 +110,9 @@ static const char kFileUrl[] = "file:///tmp/bar.webm"; |
class BufferedDataSourceTest : public testing::Test { |
public: |
BufferedDataSourceTest() |
- : view_(WebView::create(NULL)), frame_(WebLocalFrame::create(&client_)) { |
+ : view_(WebView::create(NULL)), |
+ frame_(WebLocalFrame::create(&client_)), |
+ preload_(AUTO) { |
view_->setMainFrame(frame_); |
} |
@@ -128,6 +130,7 @@ class BufferedDataSourceTest : public testing::Test { |
message_loop_.message_loop_proxy(), |
view_->mainFrame()->toWebLocalFrame(), |
&host_)); |
+ data_source_->SetPreload(preload_); |
response_generator_.reset(new TestResponseGenerator(gurl, kFileSize)); |
ExpectCreateResourceLoader(); |
@@ -140,6 +143,14 @@ class BufferedDataSourceTest : public testing::Test { |
EXPECT_EQ(data_source_->downloading(), is_http); |
} |
+ // Helper to initialize tests with a valid 200 response. |
+ void InitializeWith200Response() { |
+ Initialize(kHttpUrl, true); |
+ |
+ EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); |
+ Respond(response_generator_->Generate200()); |
+ } |
+ |
// Helper to initialize tests with a valid 206 response. |
void InitializeWith206Response() { |
Initialize(kHttpUrl, true); |
@@ -215,6 +226,7 @@ class BufferedDataSourceTest : public testing::Test { |
} |
Preload preload() { return data_source_->preload_; } |
+ void set_preload(Preload preload) { preload_ = preload; } |
BufferedResourceLoader::DeferStrategy defer_strategy() { |
return loader()->defer_strategy_; |
} |
@@ -222,6 +234,10 @@ class BufferedDataSourceTest : public testing::Test { |
int data_source_playback_rate() { return data_source_->playback_rate_; } |
int loader_bitrate() { return loader()->bitrate_; } |
int loader_playback_rate() { return loader()->playback_rate_; } |
+ bool is_local_source() { return data_source_->assume_fully_buffered(); } |
+ void set_might_be_reused_from_cache_in_future(bool value) { |
+ loader()->might_be_reused_from_cache_in_future_ = value; |
+ } |
scoped_ptr<MockBufferedDataSource> data_source_; |
@@ -237,14 +253,13 @@ class BufferedDataSourceTest : public testing::Test { |
// Used for calling BufferedDataSource::Read(). |
uint8 buffer_[kDataSize]; |
+ Preload preload_; |
+ |
DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); |
}; |
TEST_F(BufferedDataSourceTest, Range_Supported) { |
- Initialize(kHttpUrl, true); |
- |
- EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); |
- Respond(response_generator_->Generate206(0)); |
+ InitializeWith206Response(); |
EXPECT_TRUE(data_source_->loading()); |
EXPECT_FALSE(data_source_->IsStreaming()); |
@@ -271,9 +286,7 @@ TEST_F(BufferedDataSourceTest, Range_NotFound) { |
} |
TEST_F(BufferedDataSourceTest, Range_NotSupported) { |
- Initialize(kHttpUrl, true); |
- EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); |
- Respond(response_generator_->Generate200()); |
+ InitializeWith200Response(); |
EXPECT_TRUE(data_source_->loading()); |
EXPECT_TRUE(data_source_->IsStreaming()); |
@@ -672,4 +685,121 @@ TEST_F(BufferedDataSourceTest, File_FinishLoading) { |
Stop(); |
} |
+TEST_F(BufferedDataSourceTest, LocalResource_DeferStrategy) { |
+ InitializeWithFileResponse(); |
+ |
+ EXPECT_EQ(AUTO, preload()); |
+ EXPECT_TRUE(is_local_source()); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPlaying(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPaused(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ Stop(); |
+} |
+ |
+TEST_F(BufferedDataSourceTest, LocalResource_PreloadMetadata_DeferStrategy) { |
+ set_preload(METADATA); |
+ InitializeWithFileResponse(); |
+ |
+ EXPECT_EQ(METADATA, preload()); |
+ EXPECT_TRUE(is_local_source()); |
+ EXPECT_EQ(BufferedResourceLoader::kReadThenDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPlaying(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPaused(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ Stop(); |
+} |
+ |
+TEST_F(BufferedDataSourceTest, ExternalResource_Reponse200_DeferStrategy) { |
+ InitializeWith200Response(); |
+ |
+ EXPECT_EQ(AUTO, preload()); |
+ EXPECT_FALSE(is_local_source()); |
+ EXPECT_FALSE(loader()->range_supported()); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPlaying(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPaused(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ Stop(); |
+} |
+ |
+TEST_F(BufferedDataSourceTest, |
+ ExternalResource_Response200_PreloadMetadata_DeferStrategy) { |
+ set_preload(METADATA); |
+ InitializeWith200Response(); |
+ |
+ EXPECT_EQ(METADATA, preload()); |
+ EXPECT_FALSE(is_local_source()); |
+ EXPECT_FALSE(loader()->range_supported()); |
+ EXPECT_EQ(BufferedResourceLoader::kReadThenDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPlaying(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPaused(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ Stop(); |
+} |
+ |
+TEST_F(BufferedDataSourceTest, ExternalResource_Reponse206_DeferStrategy) { |
+ InitializeWith206Response(); |
+ |
+ EXPECT_EQ(AUTO, preload()); |
+ EXPECT_FALSE(is_local_source()); |
+ EXPECT_TRUE(loader()->range_supported()); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPlaying(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ set_might_be_reused_from_cache_in_future(true); |
+ data_source_->MediaIsPaused(); |
+ EXPECT_EQ(BufferedResourceLoader::kNeverDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPlaying(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ set_might_be_reused_from_cache_in_future(false); |
+ data_source_->MediaIsPaused(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ Stop(); |
+} |
+ |
+TEST_F(BufferedDataSourceTest, |
+ ExternalResource_Response206_PreloadMetadata_DeferStrategy) { |
+ set_preload(METADATA); |
+ InitializeWith206Response(); |
+ |
+ EXPECT_EQ(METADATA, preload()); |
+ EXPECT_FALSE(is_local_source()); |
+ EXPECT_TRUE(loader()->range_supported()); |
+ EXPECT_EQ(BufferedResourceLoader::kReadThenDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPlaying(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ set_might_be_reused_from_cache_in_future(true); |
+ data_source_->MediaIsPaused(); |
+ EXPECT_EQ(BufferedResourceLoader::kNeverDefer, defer_strategy()); |
+ |
+ data_source_->MediaIsPlaying(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ set_might_be_reused_from_cache_in_future(false); |
+ data_source_->MediaIsPaused(); |
+ EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
+ |
+ Stop(); |
+} |
+ |
} // namespace content |