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

Side by Side Diff: webkit/glue/media/buffered_data_source_unittest.cc

Issue 6815012: Only make Range requests when the desired range doesn't cover the whole file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests Created 9 years, 8 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
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/test/test_timeouts.h" 7 #include "base/test/test_timeouts.h"
8 #include "media/base/mock_callback.h" 8 #include "media/base/mock_callback.h"
9 #include "media/base/mock_filter_host.h" 9 #include "media/base/mock_filter_host.h"
10 #include "media/base/mock_filters.h" 10 #include "media/base/mock_filters.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 MOCK_METHOD3(Start, void(net::CompletionCallback* read_callback, 71 MOCK_METHOD3(Start, void(net::CompletionCallback* read_callback,
72 NetworkEventCallback* network_callback, 72 NetworkEventCallback* network_callback,
73 WebFrame* frame)); 73 WebFrame* frame));
74 MOCK_METHOD0(Stop, void()); 74 MOCK_METHOD0(Stop, void());
75 MOCK_METHOD4(Read, void(int64 position, int read_size, uint8* buffer, 75 MOCK_METHOD4(Read, void(int64 position, int read_size, uint8* buffer,
76 net::CompletionCallback* callback)); 76 net::CompletionCallback* callback));
77 MOCK_METHOD0(content_length, int64()); 77 MOCK_METHOD0(content_length, int64());
78 MOCK_METHOD0(instance_size, int64()); 78 MOCK_METHOD0(instance_size, int64());
79 MOCK_METHOD0(partial_response, bool()); 79 MOCK_METHOD0(range_supported, bool());
80 MOCK_METHOD0(network_activity, bool()); 80 MOCK_METHOD0(network_activity, bool());
81 MOCK_METHOD0(url, const GURL&()); 81 MOCK_METHOD0(url, const GURL&());
82 MOCK_METHOD0(GetBufferedFirstBytePosition, int64()); 82 MOCK_METHOD0(GetBufferedFirstBytePosition, int64());
83 MOCK_METHOD0(GetBufferedLastBytePosition, int64()); 83 MOCK_METHOD0(GetBufferedLastBytePosition, int64());
84 84
85 protected: 85 protected:
86 ~MockBufferedResourceLoader() {} 86 ~MockBufferedResourceLoader() {}
87 87
88 DISALLOW_COPY_AND_ASSIGN(MockBufferedResourceLoader); 88 DISALLOW_COPY_AND_ASSIGN(MockBufferedResourceLoader);
89 }; 89 };
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 } 158 }
159 159
160 // Attach a static function that deletes the memory referred by the 160 // Attach a static function that deletes the memory referred by the
161 // "callback" parameter. 161 // "callback" parameter.
162 ON_CALL(*loader_, Read(_, _, _ , _)) 162 ON_CALL(*loader_, Read(_, _, _ , _))
163 .WillByDefault(DeleteArg<3>()); 163 .WillByDefault(DeleteArg<3>());
164 164
165 ON_CALL(*loader_, instance_size()) 165 ON_CALL(*loader_, instance_size())
166 .WillByDefault(Return(instance_size)); 166 .WillByDefault(Return(instance_size));
167 ON_CALL(*loader_, partial_response()) 167
168 // range_supported() return true if we expect to get a partial response.
169 ON_CALL(*loader_, range_supported())
Ami GONE FROM CHROMIUM 2011/04/08 03:02:10 Is there a test here for the case of a lying serve
acolwell GONE FROM CHROMIUM 2011/04/18 22:09:56 Done. Added ServerLiesAboutRangeSupport test to si
168 .WillByDefault(Return(partial_response)); 170 .WillByDefault(Return(partial_response));
171
169 ON_CALL(*loader_, url()) 172 ON_CALL(*loader_, url())
170 .WillByDefault(ReturnRef(gurl_)); 173 .WillByDefault(ReturnRef(gurl_));
171 media::PipelineStatus expected_init_status = media::PIPELINE_OK; 174 media::PipelineStatus expected_init_status = media::PIPELINE_OK;
172 if (initialized_ok) { 175 if (initialized_ok) {
173 // Expected loaded or not. 176 // Expected loaded or not.
174 EXPECT_CALL(host_, SetLoaded(loaded)); 177 EXPECT_CALL(host_, SetLoaded(loaded));
175 178
176 // TODO(hclam): The condition for streaming needs to be adjusted. 179 // TODO(hclam): The condition for streaming needs to be adjusted.
177 if (instance_size != -1 && (loaded || partial_response)) { 180 if (instance_size != -1 && (loaded || partial_response)) {
178 EXPECT_CALL(host_, SetTotalBytes(instance_size)); 181 EXPECT_CALL(host_, SetTotalBytes(instance_size));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 NiceMock<MockBufferedResourceLoader> *new_loader = 297 NiceMock<MockBufferedResourceLoader> *new_loader =
295 new NiceMock<MockBufferedResourceLoader>(); 298 new NiceMock<MockBufferedResourceLoader>();
296 EXPECT_CALL(*data_source_, CreateResourceLoader(position, -1)) 299 EXPECT_CALL(*data_source_, CreateResourceLoader(position, -1))
297 .WillOnce(Return(new_loader)); 300 .WillOnce(Return(new_loader));
298 301
299 // 3. Then the new loader will be started. 302 // 3. Then the new loader will be started.
300 EXPECT_CALL(*new_loader, Start(NotNull(), NotNull(), NotNull())) 303 EXPECT_CALL(*new_loader, Start(NotNull(), NotNull(), NotNull()))
301 .WillOnce(DoAll(Assign(&error_, net::OK), 304 .WillOnce(DoAll(Assign(&error_, net::OK),
302 Invoke(this, 305 Invoke(this,
303 &BufferedDataSourceTest::InvokeStartCallback))); 306 &BufferedDataSourceTest::InvokeStartCallback)));
304 EXPECT_CALL(*new_loader, partial_response()) 307 EXPECT_CALL(*new_loader, range_supported())
305 .WillRepeatedly(Return(loader_->partial_response())); 308 .WillRepeatedly(Return(loader_->range_supported()));
306 309
307 // 4. Then again a read request is made to the new loader. 310 // 4. Then again a read request is made to the new loader.
308 EXPECT_CALL(*new_loader, Read(position, size, NotNull(), NotNull())) 311 EXPECT_CALL(*new_loader, Read(position, size, NotNull(), NotNull()))
309 .WillOnce(DoAll(Assign(&error_, size), 312 .WillOnce(DoAll(Assign(&error_, size),
310 Invoke(this, 313 Invoke(this,
311 &BufferedDataSourceTest::InvokeReadCallback))); 314 &BufferedDataSourceTest::InvokeReadCallback)));
312 315
313 EXPECT_CALL(*this, ReadCallback(size)); 316 EXPECT_CALL(*this, ReadCallback(size));
314 317
315 data_source_->Read( 318 data_source_->Read(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 EXPECT_CALL(*data_source_, CreateResourceLoader(position, -1)) 363 EXPECT_CALL(*data_source_, CreateResourceLoader(position, -1))
361 .WillOnce(Return(new_loader)); 364 .WillOnce(Return(new_loader));
362 365
363 // 3. Then the new loader will be started and respond to queries about 366 // 3. Then the new loader will be started and respond to queries about
364 // whether this is a partial response using the value of the previous 367 // whether this is a partial response using the value of the previous
365 // loader. 368 // loader.
366 EXPECT_CALL(*new_loader, Start(NotNull(), NotNull(), NotNull())) 369 EXPECT_CALL(*new_loader, Start(NotNull(), NotNull(), NotNull()))
367 .WillOnce(DoAll(Assign(&error_, net::OK), 370 .WillOnce(DoAll(Assign(&error_, net::OK),
368 Invoke(this, 371 Invoke(this,
369 &BufferedDataSourceTest::InvokeStartCallback))); 372 &BufferedDataSourceTest::InvokeStartCallback)));
370 EXPECT_CALL(*new_loader, partial_response()) 373 EXPECT_CALL(*new_loader, range_supported())
371 .WillRepeatedly(Return(loader_->partial_response())); 374 .WillRepeatedly(Return(loader_->range_supported()));
372 375
373 // 4. Then again a read request is made to the new loader. 376 // 4. Then again a read request is made to the new loader.
374 EXPECT_CALL(*new_loader, Read(position, size, NotNull(), NotNull())) 377 EXPECT_CALL(*new_loader, Read(position, size, NotNull(), NotNull()))
375 .WillOnce(DoAll(Assign(&error_, size), 378 .WillOnce(DoAll(Assign(&error_, size),
376 Invoke(this, 379 Invoke(this,
377 &BufferedDataSourceTest::InvokeReadCallback), 380 &BufferedDataSourceTest::InvokeReadCallback),
378 InvokeWithoutArgs(message_loop_, 381 InvokeWithoutArgs(message_loop_,
379 &MessageLoop::Quit))); 382 &MessageLoop::Quit)));
380 383
381 EXPECT_CALL(*this, ReadCallback(size)); 384 EXPECT_CALL(*this, ReadCallback(size));
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 data_source_->Stop(media::NewExpectedCallback()); 552 data_source_->Stop(media::NewExpectedCallback());
550 553
551 // Allow cleanup task to run. 554 // Allow cleanup task to run.
552 message_loop_->RunAllPending(); 555 message_loop_->RunAllPending();
553 556
554 // Verify that Read() was not called on the loader. 557 // Verify that Read() was not called on the loader.
555 EXPECT_FALSE(read_called); 558 EXPECT_FALSE(read_called);
556 } 559 }
557 560
558 } // namespace webkit_glue 561 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698