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

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

Issue 6350001: Replace MockFilterCallback with MockCallback and simplify unit tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: forgot some files Created 9 years, 11 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 | « media/media.gyp ('k') | webkit/glue/media/simple_data_source_unittest.cc » ('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 (c) 2010 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_filter_host.h" 9 #include "media/base/mock_filter_host.h"
9 #include "media/base/mock_filters.h" 10 #include "media/base/mock_filters.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" 12 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
13 #include "webkit/glue/media/buffered_data_source.h" 14 #include "webkit/glue/media/buffered_data_source.h"
14 #include "webkit/mocks/mock_webframe.h" 15 #include "webkit/mocks/mock_webframe.h"
15 16
16 using ::testing::_; 17 using ::testing::_;
17 using ::testing::Assign; 18 using ::testing::Assign;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // return OK. 161 // return OK.
161 initialized_ok = true; 162 initialized_ok = true;
162 } 163 }
163 } 164 }
164 165
165 // Attach a static function that deletes the memory referred by the 166 // Attach a static function that deletes the memory referred by the
166 // "callback" parameter. 167 // "callback" parameter.
167 ON_CALL(*loader_, Read(_, _, _ , _)) 168 ON_CALL(*loader_, Read(_, _, _ , _))
168 .WillByDefault(DeleteArg<3>()); 169 .WillByDefault(DeleteArg<3>());
169 170
170 StrictMock<media::MockFilterCallback> callback;
171 ON_CALL(*loader_, instance_size()) 171 ON_CALL(*loader_, instance_size())
172 .WillByDefault(Return(instance_size)); 172 .WillByDefault(Return(instance_size));
173 ON_CALL(*loader_, partial_response()) 173 ON_CALL(*loader_, partial_response())
174 .WillByDefault(Return(partial_response)); 174 .WillByDefault(Return(partial_response));
175 ON_CALL(*loader_, url()) 175 ON_CALL(*loader_, url())
176 .WillByDefault(ReturnRef(gurl_)); 176 .WillByDefault(ReturnRef(gurl_));
177 if (initialized_ok) { 177 if (initialized_ok) {
178 // Expected loaded or not. 178 // Expected loaded or not.
179 EXPECT_CALL(host_, SetLoaded(loaded)); 179 EXPECT_CALL(host_, SetLoaded(loaded));
180 180
181 // TODO(hclam): The condition for streaming needs to be adjusted. 181 // TODO(hclam): The condition for streaming needs to be adjusted.
182 if (instance_size != -1 && (loaded || partial_response)) { 182 if (instance_size != -1 && (loaded || partial_response)) {
183 EXPECT_CALL(host_, SetTotalBytes(instance_size)); 183 EXPECT_CALL(host_, SetTotalBytes(instance_size));
184 if (loaded) 184 if (loaded)
185 EXPECT_CALL(host_, SetBufferedBytes(instance_size)); 185 EXPECT_CALL(host_, SetBufferedBytes(instance_size));
186 else 186 else
187 EXPECT_CALL(host_, SetBufferedBytes(0)); 187 EXPECT_CALL(host_, SetBufferedBytes(0));
188 } else { 188 } else {
189 EXPECT_CALL(host_, SetStreaming(true)); 189 EXPECT_CALL(host_, SetStreaming(true));
190 } 190 }
191
192 EXPECT_CALL(callback, OnFilterCallback());
193 EXPECT_CALL(callback, OnCallbackDestroyed());
194 } else { 191 } else {
195 EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK)); 192 EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK));
196 EXPECT_CALL(*loader_, Stop()); 193 EXPECT_CALL(*loader_, Stop());
197 EXPECT_CALL(callback, OnFilterCallback());
198 EXPECT_CALL(callback, OnCallbackDestroyed());
199 } 194 }
200 195
201 // Actual initialization of the data source. 196 // Actual initialization of the data source.
202 data_source_->Initialize(url, callback.NewCallback()); 197 data_source_->Initialize(url, media::NewExpectedCallback());
203 message_loop_->RunAllPending(); 198 message_loop_->RunAllPending();
204 199
205 if (initialized_ok) { 200 if (initialized_ok) {
206 // Verify the size of the data source. 201 // Verify the size of the data source.
207 int64 size; 202 int64 size;
208 if (instance_size != -1 && (loaded || partial_response)) { 203 if (instance_size != -1 && (loaded || partial_response)) {
209 EXPECT_TRUE(data_source_->GetSize(&size)); 204 EXPECT_TRUE(data_source_->GetSize(&size));
210 EXPECT_EQ(instance_size, size); 205 EXPECT_EQ(instance_size, size);
211 } else { 206 } else {
212 EXPECT_TRUE(data_source_->IsStreaming()); 207 EXPECT_TRUE(data_source_->IsStreaming());
213 } 208 }
214 } 209 }
215 } 210 }
216 211
217 void StopDataSource() { 212 void StopDataSource() {
218 if (loader_) { 213 if (loader_) {
219 InSequence s; 214 InSequence s;
220 EXPECT_CALL(*loader_, Stop()); 215 EXPECT_CALL(*loader_, Stop());
221 } 216 }
222 217
223 StrictMock<media::MockFilterCallback> callback; 218 data_source_->Stop(media::NewExpectedCallback());
224 EXPECT_CALL(callback, OnFilterCallback());
225 EXPECT_CALL(callback, OnCallbackDestroyed());
226 data_source_->Stop(callback.NewCallback());
227 message_loop_->RunAllPending(); 219 message_loop_->RunAllPending();
228 } 220 }
229 221
230 void InvokeStartCallback( 222 void InvokeStartCallback(
231 net::CompletionCallback* callback, 223 net::CompletionCallback* callback,
232 BufferedResourceLoader::NetworkEventCallback* network_callback, 224 BufferedResourceLoader::NetworkEventCallback* network_callback,
233 WebFrame* frame) { 225 WebFrame* frame) {
234 callback->RunWithParams(Tuple1<int>(error_)); 226 callback->RunWithParams(Tuple1<int>(error_));
235 delete callback; 227 delete callback;
236 // TODO(hclam): Save this callback. 228 // TODO(hclam): Save this callback.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 StopDataSource(); 487 StopDataSource();
496 } 488 }
497 489
498 TEST_F(BufferedDataSourceTest, FileHasLoadedState) { 490 TEST_F(BufferedDataSourceTest, FileHasLoadedState) {
499 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); 491 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED);
500 ReadDataSourceTimesOut(20, 10); 492 ReadDataSourceTimesOut(20, 10);
501 StopDataSource(); 493 StopDataSource();
502 } 494 }
503 495
504 } // namespace webkit_glue 496 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « media/media.gyp ('k') | webkit/glue/media/simple_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698