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

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

Issue 8667002: Split a portion of BufferedResourceLoader into a separate class ActiveLoader. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: Created 9 years 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 "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"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
12 #include "webkit/media/buffered_data_source.h" 12 #include "webkit/media/buffered_data_source.h"
13 #include "webkit/media/response_generator.h" 13 #include "webkit/media/response_generator.h"
14 #include "webkit/mocks/mock_webframeclient.h" 14 #include "webkit/mocks/mock_webframeclient.h"
15 #include "webkit/mocks/mock_weburlloader.h" 15 #include "webkit/mocks/mock_weburlloader.h"
16 16
17 using ::testing::_; 17 using ::testing::_;
18 using ::testing::Assign; 18 using ::testing::Assign;
19 using ::testing::Invoke; 19 using ::testing::Invoke;
20 using ::testing::Mock;
21 using ::testing::StrictMock; 20 using ::testing::StrictMock;
22 using ::testing::NiceMock; 21 using ::testing::NiceMock;
23 22
24 using WebKit::WebFrame; 23 using WebKit::WebFrame;
25 using WebKit::WebURLResponse; 24 using WebKit::WebURLResponse;
26 using WebKit::WebView; 25 using WebKit::WebView;
27 26
28 using webkit_glue::MockWebFrameClient; 27 using webkit_glue::MockWebFrameClient;
29 using webkit_glue::MockWebURLLoader; 28 using webkit_glue::MockWebURLLoader;
30 29
(...skipping 17 matching lines...) Expand all
48 BufferedDataSource::CreateResourceLoader(first_byte_position, 47 BufferedDataSource::CreateResourceLoader(first_byte_position,
49 last_byte_position); 48 last_byte_position);
50 49
51 // Keep track of active loading state via loadAsynchronously() and cancel(). 50 // Keep track of active loading state via loadAsynchronously() and cancel().
52 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); 51 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>();
53 ON_CALL(*url_loader, loadAsynchronously(_, _)) 52 ON_CALL(*url_loader, loadAsynchronously(_, _))
54 .WillByDefault(Assign(&loading_, true)); 53 .WillByDefault(Assign(&loading_, true));
55 ON_CALL(*url_loader, cancel()) 54 ON_CALL(*url_loader, cancel())
56 .WillByDefault(Assign(&loading_, false)); 55 .WillByDefault(Assign(&loading_, false));
57 56
58 // TODO(scherkus): this is a real leak detected by http://crbug.com/100914
59 // but the fix will have to wait for a more invasive follow up patch.
60 //
61 // If you're curious what the fix is, we no longer need the reference
62 // counting added to BufferedResourceLoader in r23274 since we started
63 // using WebURLLoader in r69429.
64 Mock::AllowLeak(url_loader);
65
66 loader->SetURLLoaderForTest(url_loader); 57 loader->SetURLLoaderForTest(url_loader);
67 return loader; 58 return loader;
68 } 59 }
69 60
70 bool loading() { return loading_; } 61 bool loading() { return loading_; }
71 void set_loading(bool loading) { loading_ = loading; } 62 void set_loading(bool loading) { loading_ = loading; }
72 63
73 private: 64 private:
74 // Whether the resource load has starting loading but yet to been cancelled. 65 // Whether the resource load has starting loading but yet to been cancelled.
75 bool loading_; 66 bool loading_;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 base::Unretained(this))); 157 base::Unretained(this)));
167 message_loop_->RunAllPending(); 158 message_loop_->RunAllPending();
168 } 159 }
169 160
170 // Accessors for private variables on |data_source_|. 161 // Accessors for private variables on |data_source_|.
171 BufferedResourceLoader* loader() { 162 BufferedResourceLoader* loader() {
172 return data_source_->loader_.get(); 163 return data_source_->loader_.get();
173 } 164 }
174 NiceMock<MockWebURLLoader>* url_loader() { 165 NiceMock<MockWebURLLoader>* url_loader() {
175 return static_cast<NiceMock<MockWebURLLoader>*>( 166 return static_cast<NiceMock<MockWebURLLoader>*>(
176 loader()->url_loader_.get()); 167 loader()->active_loader_->loader_.get());
177 } 168 }
178 169
179 media::Preload preload() { return data_source_->preload_; } 170 media::Preload preload() { return data_source_->preload_; }
180 BufferedResourceLoader::DeferStrategy defer_strategy() { 171 BufferedResourceLoader::DeferStrategy defer_strategy() {
181 return loader()->defer_strategy_; 172 return loader()->defer_strategy_;
182 } 173 }
183 int data_source_bitrate() { return data_source_->bitrate_; } 174 int data_source_bitrate() { return data_source_->bitrate_; }
184 int data_source_playback_rate() { return data_source_->playback_rate_; } 175 int data_source_playback_rate() { return data_source_->playback_rate_; }
185 int loader_bitrate() { return loader()->bitrate_; } 176 int loader_bitrate() { return loader()->bitrate_; }
186 int loader_playback_rate() { return loader()->playback_rate_; } 177 int loader_playback_rate() { return loader()->playback_rate_; }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 369
379 // Read so far ahead to cause the loader to get recreated. 370 // Read so far ahead to cause the loader to get recreated.
380 BufferedResourceLoader* old_loader = loader(); 371 BufferedResourceLoader* old_loader = loader();
381 ExpectCreateResourceLoader(); 372 ExpectCreateResourceLoader();
382 ReadAtWithError(4000000); 373 ReadAtWithError(4000000);
383 Respond(responses_.Generate206(4000000)); 374 Respond(responses_.Generate206(4000000));
384 375
385 // Verify loader changed but still has same bitrate. 376 // Verify loader changed but still has same bitrate.
386 EXPECT_NE(old_loader, loader()); 377 EXPECT_NE(old_loader, loader());
387 EXPECT_EQ(1234, loader_bitrate()); 378 EXPECT_EQ(1234, loader_bitrate());
379
380 // During teardown we'll also report our final network status.
381 EXPECT_CALL(host_, SetBufferedBytes(4000000));
388 Stop(); 382 Stop();
389 } 383 }
390 384
391 TEST_F(BufferedDataSourceTest, SetPlaybackRate) { 385 TEST_F(BufferedDataSourceTest, SetPlaybackRate) {
392 InitializeWith206Response(); 386 InitializeWith206Response();
393 387
394 data_source_->SetPlaybackRate(2.0f); 388 data_source_->SetPlaybackRate(2.0f);
395 message_loop_->RunAllPending(); 389 message_loop_->RunAllPending();
396 EXPECT_EQ(2.0f, data_source_playback_rate()); 390 EXPECT_EQ(2.0f, data_source_playback_rate());
397 EXPECT_EQ(2.0f, loader_playback_rate()); 391 EXPECT_EQ(2.0f, loader_playback_rate());
398 392
399 // Read so far ahead to cause the loader to get recreated. 393 // Read so far ahead to cause the loader to get recreated.
400 BufferedResourceLoader* old_loader = loader(); 394 BufferedResourceLoader* old_loader = loader();
401 ExpectCreateResourceLoader(); 395 ExpectCreateResourceLoader();
402 ReadAtWithError(4000000); 396 ReadAtWithError(4000000);
403 Respond(responses_.Generate206(4000000)); 397 Respond(responses_.Generate206(4000000));
404 398
405 // Verify loader changed but still has same bitrate. 399 // Verify loader changed but still has same bitrate.
406 EXPECT_NE(old_loader, loader()); 400 EXPECT_NE(old_loader, loader());
401
402 // During teardown we'll also report our final network status.
403 EXPECT_CALL(host_, SetBufferedBytes(4000000));
407 Stop(); 404 Stop();
408 } 405 }
409 406
410 TEST_F(BufferedDataSourceTest, Read) { 407 TEST_F(BufferedDataSourceTest, Read) {
411 InitializeWith206Response(); 408 InitializeWith206Response();
412 409
413 ReadAt(0); 410 ReadAt(0);
414 411
415 // When the read completes we'll update our network status. 412 // When the read completes we'll update our network status.
416 EXPECT_CALL(host_, SetBufferedBytes(1024)); 413 EXPECT_CALL(host_, SetBufferedBytes(1024));
417 EXPECT_CALL(host_, SetNetworkActivity(true)); 414 EXPECT_CALL(host_, SetNetworkActivity(true));
418 FinishRead(); 415 FinishRead();
419 416
420 // During teardown we'll also report our final network status. 417 // During teardown we'll also report our final network status.
421 EXPECT_CALL(host_, SetBufferedBytes(1024)); 418 EXPECT_CALL(host_, SetBufferedBytes(1024));
422 EXPECT_CALL(host_, SetNetworkActivity(false)); 419 EXPECT_CALL(host_, SetNetworkActivity(false));
423 Stop(); 420 Stop();
424 } 421 }
425 422
426 } // namespace webkit_media 423 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698