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

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

Issue 9269027: Revert 118546 because it caused PrerenderHTML5VideoNetwork to timeout on windows and linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | « webkit/media/buffered_data_source.cc ('k') | webkit/media/webmediaplayer_impl.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_data_source_host.h" 8 #include "media/base/mock_data_source_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/WebView.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.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::AtLeast;
20 using ::testing::Invoke; 19 using ::testing::Invoke;
20 using ::testing::StrictMock;
21 using ::testing::NiceMock; 21 using ::testing::NiceMock;
22 22
23 using WebKit::WebFrame; 23 using WebKit::WebFrame;
24 using WebKit::WebURLLoader; 24 using WebKit::WebURLLoader;
25 using WebKit::WebURLResponse; 25 using WebKit::WebURLResponse;
26 using WebKit::WebView; 26 using WebKit::WebView;
27 27
28 using webkit_glue::MockWebFrameClient; 28 using webkit_glue::MockWebFrameClient;
29 using webkit_glue::MockWebURLLoader; 29 using webkit_glue::MockWebURLLoader;
30 30
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 class BufferedDataSourceTest : public testing::Test { 76 class BufferedDataSourceTest : public testing::Test {
77 public: 77 public:
78 BufferedDataSourceTest() 78 BufferedDataSourceTest()
79 : response_generator_(GURL("http://localhost/foo.webm"), kFileSize), 79 : response_generator_(GURL("http://localhost/foo.webm"), kFileSize),
80 view_(WebView::create(NULL)), 80 view_(WebView::create(NULL)),
81 message_loop_(MessageLoop::current()) { 81 message_loop_(MessageLoop::current()) {
82 view_->initializeMainFrame(&client_); 82 view_->initializeMainFrame(&client_);
83 83
84 data_source_ = new MockBufferedDataSource(message_loop_, 84 data_source_ = new MockBufferedDataSource(message_loop_,
85 view_->mainFrame()); 85 view_->mainFrame());
86 data_source_->set_host(&host_);
86 } 87 }
87 88
88 virtual ~BufferedDataSourceTest() { 89 virtual ~BufferedDataSourceTest() {
89 view_->close(); 90 view_->close();
90 } 91 }
91 92
92 void Initialize(media::PipelineStatus expected) { 93 void Initialize(media::PipelineStatus expected) {
93 Initialize(expected, true);
94 }
95
96 void Initialize(media::PipelineStatus expected, bool set_host) {
97 if (set_host)
98 data_source_->set_host(&host_);
99
100 ExpectCreateResourceLoader(); 94 ExpectCreateResourceLoader();
101 data_source_->Initialize(response_generator_.gurl(), 95 data_source_->Initialize(response_generator_.gurl(),
102 media::NewExpectedStatusCB(expected)); 96 media::NewExpectedStatusCB(expected));
103 message_loop_->RunAllPending(); 97 message_loop_->RunAllPending();
104 } 98 }
105 99
106 // Helper to initialize tests with a valid 206 response. 100 // Helper to initialize tests with a valid 206 response.
107 void InitializeWith206Response() { 101 void InitializeWith206Response() {
108 Initialize(media::PIPELINE_OK); 102 Initialize(media::PIPELINE_OK);
109 103
110 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())) 104 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()));
111 .Times(AtLeast(1)); 105 EXPECT_CALL(host_, SetBufferedBytes(0));
112 EXPECT_CALL(host_, SetBufferedBytes(0))
113 .Times(AtLeast(1));
114 Respond(response_generator_.Generate206(0)); 106 Respond(response_generator_.Generate206(0));
115 } 107 }
116 108
117 // Stops any active loaders and shuts down the data source. 109 // Stops any active loaders and shuts down the data source.
118 // 110 //
119 // This typically happens when the page is closed and for our purposes is 111 // This typically happens when the page is closed and for our purposes is
120 // appropriate to do when tearing down a test. 112 // appropriate to do when tearing down a test.
121 void Stop() { 113 void Stop() {
122 if (data_source_->loading()) { 114 if (data_source_->loading()) {
123 loader()->didFail(url_loader(), response_generator_.GenerateError()); 115 loader()->didFail(url_loader(), response_generator_.GenerateError());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 int loader_bitrate() { return loader()->bitrate_; } 169 int loader_bitrate() { return loader()->bitrate_; }
178 int loader_playback_rate() { return loader()->playback_rate_; } 170 int loader_playback_rate() { return loader()->playback_rate_; }
179 171
180 172
181 scoped_refptr<MockBufferedDataSource> data_source_; 173 scoped_refptr<MockBufferedDataSource> data_source_;
182 174
183 TestResponseGenerator response_generator_; 175 TestResponseGenerator response_generator_;
184 MockWebFrameClient client_; 176 MockWebFrameClient client_;
185 WebView* view_; 177 WebView* view_;
186 178
187 NiceMock<media::MockDataSourceHost> host_; 179 StrictMock<media::MockDataSourceHost> host_;
188 MessageLoop* message_loop_; 180 MessageLoop* message_loop_;
189 181
190 private: 182 private:
191 // Used for calling BufferedDataSource::Read(). 183 // Used for calling BufferedDataSource::Read().
192 uint8 buffer_[kDataSize]; 184 uint8 buffer_[kDataSize];
193 185
194 // Used for calling BufferedResourceLoader::didReceiveData(). 186 // Used for calling BufferedResourceLoader::didReceiveData().
195 char data_[kDataSize]; 187 char data_[kDataSize];
196 188
197 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); 189 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 432 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
441 Stop(); 433 Stop();
442 } 434 }
443 435
444 TEST_F(BufferedDataSourceTest, Read) { 436 TEST_F(BufferedDataSourceTest, Read) {
445 InitializeWith206Response(); 437 InitializeWith206Response();
446 438
447 ReadAt(0); 439 ReadAt(0);
448 440
449 // When the read completes we'll update our network status. 441 // When the read completes we'll update our network status.
450 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)) 442 EXPECT_CALL(host_, SetBufferedBytes(kDataSize));
451 .Times(AtLeast(1)); 443 EXPECT_CALL(host_, SetNetworkActivity(true));
452 EXPECT_CALL(host_, SetNetworkActivity(true))
453 .Times(AtLeast(1));
454 EXPECT_CALL(*this, ReadCallback(kDataSize)); 444 EXPECT_CALL(*this, ReadCallback(kDataSize));
455 FinishRead(); 445 FinishRead();
456 446
457 // During teardown we'll also report our final network status. 447 // During teardown we'll also report our final network status.
458 EXPECT_CALL(host_, SetNetworkActivity(false)); 448 EXPECT_CALL(host_, SetNetworkActivity(false));
459 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); 449 EXPECT_CALL(host_, SetBufferedBytes(kDataSize));
460 450
461 EXPECT_TRUE(data_source_->loading()); 451 EXPECT_TRUE(data_source_->loading());
462 Stop(); 452 Stop();
463 } 453 }
464 454
465 // Make sure information regarding loaded data propogates to the host even if it
466 // gets initialized before the host is set.
467 TEST_F(BufferedDataSourceTest, HostSetAfterResponse) {
468 Initialize(media::PIPELINE_OK, false);
469 Respond(response_generator_.Generate206(0));
470
471 EXPECT_CALL(host_, SetNetworkActivity(_));
472 EXPECT_CALL(host_, SetTotalBytes(_));
473 EXPECT_CALL(host_, SetBufferedBytes(_));
474 data_source_->set_host(&host_);
475
476 Stop();
477 }
478
479 } // namespace webkit_media 455 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/buffered_data_source.cc ('k') | webkit/media/webmediaplayer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698