| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/stringprintf.h" |
| 11 #include "media/base/filters.h" | 12 #include "media/base/filters.h" |
| 12 #include "media/base/mock_filter_host.h" | 13 #include "media/base/mock_filter_host.h" |
| 13 #include "media/base/mock_filters.h" | 14 #include "media/base/mock_filters.h" |
| 14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 15 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 16 #include "webkit/glue/media/buffered_data_source.h" | 17 #include "webkit/glue/media/buffered_data_source.h" |
| 17 #include "webkit/glue/media/mock_media_resource_loader_bridge_factory.h" | 18 #include "webkit/glue/media/mock_media_resource_loader_bridge_factory.h" |
| 18 #include "webkit/glue/mock_resource_loader_bridge.h" | 19 #include "webkit/glue/mock_resource_loader_bridge.h" |
| 19 | 20 |
| 20 using ::testing::_; | 21 using ::testing::_; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 .WillOnce(Return(bridge_.get())); | 93 .WillOnce(Return(bridge_.get())); |
| 93 EXPECT_CALL(*bridge_, Start(loader_.get())); | 94 EXPECT_CALL(*bridge_, Start(loader_.get())); |
| 94 loader_->Start( | 95 loader_->Start( |
| 95 NewCallback(this, &BufferedResourceLoaderTest::StartCallback), | 96 NewCallback(this, &BufferedResourceLoaderTest::StartCallback), |
| 96 NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback)); | 97 NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void FullResponse(int64 instance_size) { | 100 void FullResponse(int64 instance_size) { |
| 100 EXPECT_CALL(*this, StartCallback(net::OK)); | 101 EXPECT_CALL(*this, StartCallback(net::OK)); |
| 101 ResourceLoaderBridge::ResponseInfo info; | 102 ResourceLoaderBridge::ResponseInfo info; |
| 102 std::string header = StringPrintf("HTTP/1.1 200 OK\n" | 103 std::string header = base::StringPrintf("HTTP/1.1 200 OK\n" |
| 103 "Content-Length: %" PRId64, | 104 "Content-Length: %" PRId64, |
| 104 instance_size); | 105 instance_size); |
| 105 replace(header.begin(), header.end(), '\n', '\0'); | 106 replace(header.begin(), header.end(), '\n', '\0'); |
| 106 info.headers = new net::HttpResponseHeaders(header); | 107 info.headers = new net::HttpResponseHeaders(header); |
| 107 info.content_length = instance_size; | 108 info.content_length = instance_size; |
| 108 loader_->OnReceivedResponse(info, false); | 109 loader_->OnReceivedResponse(info, false); |
| 109 EXPECT_EQ(instance_size, loader_->content_length()); | 110 EXPECT_EQ(instance_size, loader_->content_length()); |
| 110 EXPECT_EQ(instance_size, loader_->instance_size()); | 111 EXPECT_EQ(instance_size, loader_->instance_size()); |
| 111 EXPECT_FALSE(loader_->partial_response()); | 112 EXPECT_FALSE(loader_->partial_response()); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void PartialResponse(int64 first_position, int64 last_position, | 115 void PartialResponse(int64 first_position, int64 last_position, |
| 115 int64 instance_size) { | 116 int64 instance_size) { |
| 116 EXPECT_CALL(*this, StartCallback(net::OK)); | 117 EXPECT_CALL(*this, StartCallback(net::OK)); |
| 117 int64 content_length = last_position - first_position + 1; | 118 int64 content_length = last_position - first_position + 1; |
| 118 ResourceLoaderBridge::ResponseInfo info; | 119 ResourceLoaderBridge::ResponseInfo info; |
| 119 std::string header = StringPrintf("HTTP/1.1 206 Partial Content\n" | 120 std::string header = base::StringPrintf("HTTP/1.1 206 Partial Content\n" |
| 120 "Content-Range: bytes " | 121 "Content-Range: bytes " |
| 121 "%" PRId64 "-%" PRId64 "/%" PRId64, | 122 "%" PRId64 "-%" PRId64 "/%" PRId64, |
| 122 first_position, | 123 first_position, |
| 123 last_position, | 124 last_position, |
| 124 instance_size); | 125 instance_size); |
| 125 replace(header.begin(), header.end(), '\n', '\0'); | 126 replace(header.begin(), header.end(), '\n', '\0'); |
| 126 info.headers = new net::HttpResponseHeaders(header); | 127 info.headers = new net::HttpResponseHeaders(header); |
| 127 info.content_length = content_length; | 128 info.content_length = content_length; |
| 128 loader_->OnReceivedResponse(info, false); | 129 loader_->OnReceivedResponse(info, false); |
| 129 EXPECT_EQ(content_length, loader_->content_length()); | 130 EXPECT_EQ(content_length, loader_->content_length()); |
| 130 EXPECT_EQ(instance_size, loader_->instance_size()); | 131 EXPECT_EQ(instance_size, loader_->instance_size()); |
| 131 EXPECT_TRUE(loader_->partial_response()); | 132 EXPECT_TRUE(loader_->partial_response()); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void StopWhenLoad() { | 135 void StopWhenLoad() { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 Initialize(kHttpUrl, 0, 10); | 262 Initialize(kHttpUrl, 0, 10); |
| 262 Start(); | 263 Start(); |
| 263 | 264 |
| 264 EXPECT_CALL(*this, StartCallback(net::ERR_INVALID_RESPONSE)); | 265 EXPECT_CALL(*this, StartCallback(net::ERR_INVALID_RESPONSE)); |
| 265 EXPECT_CALL(*bridge_, Cancel()) | 266 EXPECT_CALL(*bridge_, Cancel()) |
| 266 .WillOnce(RequestCanceled(loader_)); | 267 .WillOnce(RequestCanceled(loader_)); |
| 267 EXPECT_CALL(*bridge_, OnDestroy()) | 268 EXPECT_CALL(*bridge_, OnDestroy()) |
| 268 .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); | 269 .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); |
| 269 | 270 |
| 270 ResourceLoaderBridge::ResponseInfo info; | 271 ResourceLoaderBridge::ResponseInfo info; |
| 271 std::string header = StringPrintf("HTTP/1.1 206 Partial Content\n" | 272 std::string header = base::StringPrintf("HTTP/1.1 206 Partial Content\n" |
| 272 "Content-Range: bytes %d-%d/%d", | 273 "Content-Range: bytes %d-%d/%d", |
| 273 1, 10, 1024); | 274 1, 10, 1024); |
| 274 replace(header.begin(), header.end(), '\n', '\0'); | 275 replace(header.begin(), header.end(), '\n', '\0'); |
| 275 info.headers = new net::HttpResponseHeaders(header); | 276 info.headers = new net::HttpResponseHeaders(header); |
| 276 info.content_length = 10; | 277 info.content_length = 10; |
| 277 loader_->OnReceivedResponse(info, false); | 278 loader_->OnReceivedResponse(info, false); |
| 278 } | 279 } |
| 279 | 280 |
| 280 // Tests the logic of sliding window for data buffering and reading. | 281 // Tests the logic of sliding window for data buffering and reading. |
| 281 TEST_F(BufferedResourceLoaderTest, BufferAndRead) { | 282 TEST_F(BufferedResourceLoaderTest, BufferAndRead) { |
| 282 Initialize(kHttpUrl, 10, 29); | 283 Initialize(kHttpUrl, 10, 29); |
| 283 Start(); | 284 Start(); |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 StopDataSource(); | 927 StopDataSource(); |
| 927 } | 928 } |
| 928 | 929 |
| 929 TEST_F(BufferedDataSourceTest, FileHasLoadedState) { | 930 TEST_F(BufferedDataSourceTest, FileHasLoadedState) { |
| 930 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); | 931 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); |
| 931 ReadDataSourceTimesOut(20, 10); | 932 ReadDataSourceTimesOut(20, 10); |
| 932 StopDataSource(); | 933 StopDataSource(); |
| 933 } | 934 } |
| 934 | 935 |
| 935 } // namespace webkit_glue | 936 } // namespace webkit_glue |
| OLD | NEW |