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

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: fixes 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
« no previous file with comments | « webkit/media/active_loader.cc ('k') | webkit/media/buffered_resource_loader.h » ('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) 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/mocks/mock_webframeclient.h" 13 #include "webkit/mocks/mock_webframeclient.h"
14 #include "webkit/mocks/mock_weburlloader.h" 14 #include "webkit/mocks/mock_weburlloader.h"
15 #include "webkit/media/test_response_generator.h" 15 #include "webkit/media/test_response_generator.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::WebURLLoader; 24 using WebKit::WebURLLoader;
26 using WebKit::WebURLResponse; 25 using WebKit::WebURLResponse;
27 using WebKit::WebView; 26 using WebKit::WebView;
28 27
29 using webkit_glue::MockWebFrameClient; 28 using webkit_glue::MockWebFrameClient;
30 using webkit_glue::MockWebURLLoader; 29 using webkit_glue::MockWebURLLoader;
(...skipping 18 matching lines...) Expand all
49 BufferedDataSource::CreateResourceLoader(first_byte_position, 48 BufferedDataSource::CreateResourceLoader(first_byte_position,
50 last_byte_position); 49 last_byte_position);
51 50
52 // Keep track of active loading state via loadAsynchronously() and cancel(). 51 // Keep track of active loading state via loadAsynchronously() and cancel().
53 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); 52 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>();
54 ON_CALL(*url_loader, loadAsynchronously(_, _)) 53 ON_CALL(*url_loader, loadAsynchronously(_, _))
55 .WillByDefault(Assign(&loading_, true)); 54 .WillByDefault(Assign(&loading_, true));
56 ON_CALL(*url_loader, cancel()) 55 ON_CALL(*url_loader, cancel())
57 .WillByDefault(Assign(&loading_, false)); 56 .WillByDefault(Assign(&loading_, false));
58 57
59 // TODO(scherkus): this is a real leak detected by http://crbug.com/100914
60 // but the fix will have to wait for a more invasive follow up patch.
61 //
62 // If you're curious what the fix is, we no longer need the reference
63 // counting added to BufferedResourceLoader in r23274 since we started
64 // using WebURLLoader in r69429.
65 Mock::AllowLeak(url_loader);
66
67 loader->SetURLLoaderForTest(url_loader); 58 loader->SetURLLoaderForTest(url_loader);
68 return loader; 59 return loader;
69 } 60 }
70 61
71 bool loading() { return loading_; } 62 bool loading() { return loading_; }
72 void set_loading(bool loading) { loading_ = loading; } 63 void set_loading(bool loading) { loading_ = loading; }
73 64
74 private: 65 private:
75 // Whether the resource load has starting loading but yet to been cancelled. 66 // Whether the resource load has starting loading but yet to been cancelled.
76 bool loading_; 67 bool loading_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 MOCK_METHOD1(ReadCallback, void(size_t size)); 147 MOCK_METHOD1(ReadCallback, void(size_t size));
157 148
158 void ReadAt(int64 position) { 149 void ReadAt(int64 position) {
159 data_source_->Read(position, kDataSize, buffer_, 150 data_source_->Read(position, kDataSize, buffer_,
160 base::Bind(&BufferedDataSourceTest::ReadCallback, 151 base::Bind(&BufferedDataSourceTest::ReadCallback,
161 base::Unretained(this))); 152 base::Unretained(this)));
162 message_loop_->RunAllPending(); 153 message_loop_->RunAllPending();
163 } 154 }
164 155
165 // Accessors for private variables on |data_source_|. 156 // Accessors for private variables on |data_source_|.
166 BufferedResourceLoader* loader() { return data_source_->loader_.get(); } 157 BufferedResourceLoader* loader() {
167 WebURLLoader* url_loader() { return loader()->url_loader_.get(); } 158 return data_source_->loader_.get();
159 }
160 WebURLLoader* url_loader() {
161 return loader()->active_loader_->loader_.get();
162 }
168 163
169 media::Preload preload() { return data_source_->preload_; } 164 media::Preload preload() { return data_source_->preload_; }
170 BufferedResourceLoader::DeferStrategy defer_strategy() { 165 BufferedResourceLoader::DeferStrategy defer_strategy() {
171 return loader()->defer_strategy_; 166 return loader()->defer_strategy_;
172 } 167 }
173 int data_source_bitrate() { return data_source_->bitrate_; } 168 int data_source_bitrate() { return data_source_->bitrate_; }
174 int data_source_playback_rate() { return data_source_->playback_rate_; } 169 int data_source_playback_rate() { return data_source_->playback_rate_; }
175 int loader_bitrate() { return loader()->bitrate_; } 170 int loader_bitrate() { return loader()->bitrate_; }
176 int loader_playback_rate() { return loader()->playback_rate_; } 171 int loader_playback_rate() { return loader()->playback_rate_; }
177 172
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 // Read so far ahead to cause the loader to get recreated. 397 // Read so far ahead to cause the loader to get recreated.
403 BufferedResourceLoader* old_loader = loader(); 398 BufferedResourceLoader* old_loader = loader();
404 ExpectCreateResourceLoader(); 399 ExpectCreateResourceLoader();
405 ReadAt(kFarReadPosition); 400 ReadAt(kFarReadPosition);
406 Respond(response_generator_.Generate206(kFarReadPosition)); 401 Respond(response_generator_.Generate206(kFarReadPosition));
407 402
408 // Verify loader changed but still has same bitrate. 403 // Verify loader changed but still has same bitrate.
409 EXPECT_NE(old_loader, loader()); 404 EXPECT_NE(old_loader, loader());
410 EXPECT_EQ(1234, loader_bitrate()); 405 EXPECT_EQ(1234, loader_bitrate());
411 406
407 // During teardown we'll also report our final network status.
408 EXPECT_CALL(host_, SetNetworkActivity(true));
409 EXPECT_CALL(host_, SetBufferedBytes(4000000));
410
412 EXPECT_TRUE(data_source_->loading()); 411 EXPECT_TRUE(data_source_->loading());
413 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 412 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
414 Stop(); 413 Stop();
415 } 414 }
416 415
417 TEST_F(BufferedDataSourceTest, SetPlaybackRate) { 416 TEST_F(BufferedDataSourceTest, SetPlaybackRate) {
418 InitializeWith206Response(); 417 InitializeWith206Response();
419 418
420 data_source_->SetPlaybackRate(2.0f); 419 data_source_->SetPlaybackRate(2.0f);
421 message_loop_->RunAllPending(); 420 message_loop_->RunAllPending();
422 EXPECT_EQ(2.0f, data_source_playback_rate()); 421 EXPECT_EQ(2.0f, data_source_playback_rate());
423 EXPECT_EQ(2.0f, loader_playback_rate()); 422 EXPECT_EQ(2.0f, loader_playback_rate());
424 423
425 // Read so far ahead to cause the loader to get recreated. 424 // Read so far ahead to cause the loader to get recreated.
426 BufferedResourceLoader* old_loader = loader(); 425 BufferedResourceLoader* old_loader = loader();
427 ExpectCreateResourceLoader(); 426 ExpectCreateResourceLoader();
428 ReadAt(kFarReadPosition); 427 ReadAt(kFarReadPosition);
429 Respond(response_generator_.Generate206(kFarReadPosition)); 428 Respond(response_generator_.Generate206(kFarReadPosition));
430 429
431 // Verify loader changed but still has same playback rate. 430 // Verify loader changed but still has same playback rate.
432 EXPECT_NE(old_loader, loader()); 431 EXPECT_NE(old_loader, loader());
433 432
433 // During teardown we'll also report our final network status.
434 EXPECT_CALL(host_, SetNetworkActivity(true));
435 EXPECT_CALL(host_, SetBufferedBytes(4000000));
436
434 EXPECT_TRUE(data_source_->loading()); 437 EXPECT_TRUE(data_source_->loading());
435 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 438 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
436 Stop(); 439 Stop();
437 } 440 }
438 441
439 TEST_F(BufferedDataSourceTest, Read) { 442 TEST_F(BufferedDataSourceTest, Read) {
440 InitializeWith206Response(); 443 InitializeWith206Response();
441 444
442 ReadAt(0); 445 ReadAt(0);
443 446
444 // When the read completes we'll update our network status. 447 // When the read completes we'll update our network status.
445 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); 448 EXPECT_CALL(host_, SetBufferedBytes(kDataSize));
446 EXPECT_CALL(host_, SetNetworkActivity(true)); 449 EXPECT_CALL(host_, SetNetworkActivity(true));
447 EXPECT_CALL(*this, ReadCallback(kDataSize)); 450 EXPECT_CALL(*this, ReadCallback(kDataSize));
448 FinishRead(); 451 FinishRead();
449 452
450 // During teardown we'll also report our final network status. 453 // During teardown we'll also report our final network status.
451 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); 454 EXPECT_CALL(host_, SetBufferedBytes(kDataSize));
452 EXPECT_CALL(host_, SetNetworkActivity(false)); 455 //EXPECT_CALL(host_, SetNetworkActivity(false));
453 456
454 EXPECT_TRUE(data_source_->loading()); 457 EXPECT_TRUE(data_source_->loading());
455 Stop(); 458 Stop();
456 } 459 }
457 460
458 } // namespace webkit_media 461 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/active_loader.cc ('k') | webkit/media/buffered_resource_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698