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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "media/base/media_log.h" | 6 #include "media/base/media_log.h" |
7 #include "media/base/mock_callback.h" | 7 #include "media/base/mock_callback.h" |
8 #include "media/base/mock_filter_host.h" | 8 #include "media/base/mock_filter_host.h" |
9 #include "media/base/mock_filters.h" | 9 #include "media/base/mock_filters.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 ExpectCreateResourceLoader(); | 103 ExpectCreateResourceLoader(); |
104 data_source_->Initialize(response_generator_.gurl().spec(), | 104 data_source_->Initialize(response_generator_.gurl().spec(), |
105 media::NewExpectedStatusCB(expected)); | 105 media::NewExpectedStatusCB(expected)); |
106 message_loop_->RunAllPending(); | 106 message_loop_->RunAllPending(); |
107 } | 107 } |
108 | 108 |
109 // Helper to initialize tests with a valid 206 response. | 109 // Helper to initialize tests with a valid 206 response. |
110 void InitializeWith206Response() { | 110 void InitializeWith206Response() { |
111 Initialize(media::PIPELINE_OK); | 111 Initialize(media::PIPELINE_OK); |
112 | 112 |
113 EXPECT_CALL(host_, SetLoaded(false)); | |
114 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); | 113 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); |
115 EXPECT_CALL(host_, SetBufferedBytes(0)); | 114 EXPECT_CALL(host_, SetBufferedBytes(0)); |
116 Respond(response_generator_.Generate206(0)); | 115 Respond(response_generator_.Generate206(0)); |
117 } | 116 } |
118 | 117 |
119 // Stops any active loaders and shuts down the data source. | 118 // Stops any active loaders and shuts down the data source. |
120 // | 119 // |
121 // This typically happens when the page is closed and for our purposes is | 120 // This typically happens when the page is closed and for our purposes is |
122 // appropriate to do when tearing down a test. | 121 // appropriate to do when tearing down a test. |
123 void Stop() { | 122 void Stop() { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 190 |
192 // Used for calling BufferedResourceLoader::didReceiveData(). | 191 // Used for calling BufferedResourceLoader::didReceiveData(). |
193 char data_[kDataSize]; | 192 char data_[kDataSize]; |
194 | 193 |
195 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); | 194 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); |
196 }; | 195 }; |
197 | 196 |
198 TEST_F(BufferedDataSourceTest, Range_Supported) { | 197 TEST_F(BufferedDataSourceTest, Range_Supported) { |
199 Initialize(media::PIPELINE_OK); | 198 Initialize(media::PIPELINE_OK); |
200 | 199 |
201 EXPECT_CALL(host_, SetLoaded(false)); | |
202 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); | 200 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); |
203 EXPECT_CALL(host_, SetBufferedBytes(0)); | 201 EXPECT_CALL(host_, SetBufferedBytes(0)); |
204 Respond(response_generator_.Generate206(0)); | 202 Respond(response_generator_.Generate206(0)); |
205 | 203 |
206 EXPECT_TRUE(data_source_->loading()); | 204 EXPECT_TRUE(data_source_->loading()); |
207 Stop(); | 205 Stop(); |
208 } | 206 } |
209 | 207 |
210 TEST_F(BufferedDataSourceTest, Range_NotFound) { | 208 TEST_F(BufferedDataSourceTest, Range_NotFound) { |
211 Initialize(media::PIPELINE_ERROR_NETWORK); | 209 Initialize(media::PIPELINE_ERROR_NETWORK); |
(...skipping 14 matching lines...) Expand all Loading... |
226 TEST_F(BufferedDataSourceTest, Range_NotSupported) { | 224 TEST_F(BufferedDataSourceTest, Range_NotSupported) { |
227 Initialize(media::PIPELINE_OK); | 225 Initialize(media::PIPELINE_OK); |
228 | 226 |
229 // It'll try again. | 227 // It'll try again. |
230 // | 228 // |
231 // TODO(scherkus): try to reuse existing connection http://crbug.com/105231 | 229 // TODO(scherkus): try to reuse existing connection http://crbug.com/105231 |
232 ExpectCreateResourceLoader(); | 230 ExpectCreateResourceLoader(); |
233 Respond(response_generator_.Generate200()); | 231 Respond(response_generator_.Generate200()); |
234 | 232 |
235 // Now it'll succeed. | 233 // Now it'll succeed. |
236 EXPECT_CALL(host_, SetLoaded(false)); | |
237 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); | 234 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); |
238 EXPECT_CALL(host_, SetBufferedBytes(0)); | 235 EXPECT_CALL(host_, SetBufferedBytes(0)); |
239 EXPECT_CALL(host_, SetStreaming(true)); | |
240 Respond(response_generator_.Generate200()); | 236 Respond(response_generator_.Generate200()); |
241 | 237 |
242 EXPECT_TRUE(data_source_->loading()); | 238 EXPECT_TRUE(data_source_->loading()); |
| 239 EXPECT_TRUE(data_source_->IsStreaming()); |
243 Stop(); | 240 Stop(); |
244 } | 241 } |
245 | 242 |
246 TEST_F(BufferedDataSourceTest, Range_MissingContentRange) { | 243 TEST_F(BufferedDataSourceTest, Range_MissingContentRange) { |
247 Initialize(media::PIPELINE_ERROR_NETWORK); | 244 Initialize(media::PIPELINE_ERROR_NETWORK); |
248 | 245 |
249 // It'll try again. | 246 // It'll try again. |
250 // | 247 // |
251 // TODO(scherkus): don't try again on errors http://crbug.com/105230 | 248 // TODO(scherkus): don't try again on errors http://crbug.com/105230 |
252 ExpectCreateResourceLoader(); | 249 ExpectCreateResourceLoader(); |
253 Respond(response_generator_.Generate206( | 250 Respond(response_generator_.Generate206( |
254 0, TestResponseGenerator::kNoContentRange)); | 251 0, TestResponseGenerator::kNoContentRange)); |
255 | 252 |
256 // Now it's done and will fail. | 253 // Now it's done and will fail. |
257 Respond(response_generator_.Generate206( | 254 Respond(response_generator_.Generate206( |
258 0, TestResponseGenerator::kNoContentRange)); | 255 0, TestResponseGenerator::kNoContentRange)); |
259 | 256 |
260 EXPECT_FALSE(data_source_->loading()); | 257 EXPECT_FALSE(data_source_->loading()); |
261 Stop(); | 258 Stop(); |
262 } | 259 } |
263 | 260 |
264 TEST_F(BufferedDataSourceTest, Range_MissingContentLength) { | 261 TEST_F(BufferedDataSourceTest, Range_MissingContentLength) { |
265 Initialize(media::PIPELINE_OK); | 262 Initialize(media::PIPELINE_OK); |
266 | 263 |
267 // It'll manage without a Content-Length response. | 264 // It'll manage without a Content-Length response. |
268 EXPECT_CALL(host_, SetLoaded(false)); | |
269 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); | 265 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); |
270 EXPECT_CALL(host_, SetBufferedBytes(0)); | 266 EXPECT_CALL(host_, SetBufferedBytes(0)); |
271 Respond(response_generator_.Generate206( | 267 Respond(response_generator_.Generate206( |
272 0, TestResponseGenerator::kNoContentLength)); | 268 0, TestResponseGenerator::kNoContentLength)); |
273 | 269 |
274 EXPECT_TRUE(data_source_->loading()); | 270 EXPECT_TRUE(data_source_->loading()); |
275 Stop(); | 271 Stop(); |
276 } | 272 } |
277 | 273 |
278 TEST_F(BufferedDataSourceTest, Range_WrongContentRange) { | 274 TEST_F(BufferedDataSourceTest, Range_WrongContentRange) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 445 |
450 // During teardown we'll also report our final network status. | 446 // During teardown we'll also report our final network status. |
451 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); | 447 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); |
452 EXPECT_CALL(host_, SetNetworkActivity(false)); | 448 EXPECT_CALL(host_, SetNetworkActivity(false)); |
453 | 449 |
454 EXPECT_TRUE(data_source_->loading()); | 450 EXPECT_TRUE(data_source_->loading()); |
455 Stop(); | 451 Stop(); |
456 } | 452 } |
457 | 453 |
458 } // namespace webkit_media | 454 } // namespace webkit_media |
OLD | NEW |