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

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

Issue 9113023: Fire canplaythrough as soon as download defers to fix autoplay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT 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;
19 using ::testing::Invoke; 20 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_);
87 } 86 }
88 87
89 virtual ~BufferedDataSourceTest() { 88 virtual ~BufferedDataSourceTest() {
90 view_->close(); 89 view_->close();
91 } 90 }
92 91
93 void Initialize(media::PipelineStatus expected) { 92 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
94 ExpectCreateResourceLoader(); 100 ExpectCreateResourceLoader();
95 data_source_->Initialize(response_generator_.gurl().spec(), 101 data_source_->Initialize(response_generator_.gurl().spec(),
96 media::NewExpectedStatusCB(expected)); 102 media::NewExpectedStatusCB(expected));
97 message_loop_->RunAllPending(); 103 message_loop_->RunAllPending();
98 } 104 }
99 105
100 // Helper to initialize tests with a valid 206 response. 106 // Helper to initialize tests with a valid 206 response.
101 void InitializeWith206Response() { 107 void InitializeWith206Response() {
102 Initialize(media::PIPELINE_OK); 108 Initialize(media::PIPELINE_OK);
103 109
104 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 110 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()))
105 EXPECT_CALL(host_, SetBufferedBytes(0)); 111 .Times(AtLeast(1));
112 EXPECT_CALL(host_, SetBufferedBytes(0))
113 .Times(AtLeast(1));
106 Respond(response_generator_.Generate206(0)); 114 Respond(response_generator_.Generate206(0));
107 } 115 }
108 116
109 // Stops any active loaders and shuts down the data source. 117 // Stops any active loaders and shuts down the data source.
110 // 118 //
111 // This typically happens when the page is closed and for our purposes is 119 // This typically happens when the page is closed and for our purposes is
112 // appropriate to do when tearing down a test. 120 // appropriate to do when tearing down a test.
113 void Stop() { 121 void Stop() {
114 if (data_source_->loading()) { 122 if (data_source_->loading()) {
115 loader()->didFail(url_loader(), response_generator_.GenerateError()); 123 loader()->didFail(url_loader(), response_generator_.GenerateError());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 int loader_bitrate() { return loader()->bitrate_; } 177 int loader_bitrate() { return loader()->bitrate_; }
170 int loader_playback_rate() { return loader()->playback_rate_; } 178 int loader_playback_rate() { return loader()->playback_rate_; }
171 179
172 180
173 scoped_refptr<MockBufferedDataSource> data_source_; 181 scoped_refptr<MockBufferedDataSource> data_source_;
174 182
175 TestResponseGenerator response_generator_; 183 TestResponseGenerator response_generator_;
176 MockWebFrameClient client_; 184 MockWebFrameClient client_;
177 WebView* view_; 185 WebView* view_;
178 186
179 StrictMock<media::MockDataSourceHost> host_; 187 NiceMock<media::MockDataSourceHost> host_;
180 MessageLoop* message_loop_; 188 MessageLoop* message_loop_;
181 189
182 private: 190 private:
183 // Used for calling BufferedDataSource::Read(). 191 // Used for calling BufferedDataSource::Read().
184 uint8 buffer_[kDataSize]; 192 uint8 buffer_[kDataSize];
185 193
186 // Used for calling BufferedResourceLoader::didReceiveData(). 194 // Used for calling BufferedResourceLoader::didReceiveData().
187 char data_[kDataSize]; 195 char data_[kDataSize];
188 196
189 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); 197 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 442 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
435 Stop(); 443 Stop();
436 } 444 }
437 445
438 TEST_F(BufferedDataSourceTest, Read) { 446 TEST_F(BufferedDataSourceTest, Read) {
439 InitializeWith206Response(); 447 InitializeWith206Response();
440 448
441 ReadAt(0); 449 ReadAt(0);
442 450
443 // When the read completes we'll update our network status. 451 // When the read completes we'll update our network status.
444 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); 452 EXPECT_CALL(host_, SetBufferedBytes(kDataSize))
445 EXPECT_CALL(host_, SetNetworkActivity(true)); 453 .Times(AtLeast(1));
454 EXPECT_CALL(host_, SetNetworkActivity(true))
455 .Times(AtLeast(1));
446 EXPECT_CALL(*this, ReadCallback(kDataSize)); 456 EXPECT_CALL(*this, ReadCallback(kDataSize));
447 FinishRead(); 457 FinishRead();
448 458
449 // During teardown we'll also report our final network status. 459 // During teardown we'll also report our final network status.
450 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); 460 EXPECT_CALL(host_, SetBufferedBytes(kDataSize));
451 //EXPECT_CALL(host_, SetNetworkActivity(false)); 461 //EXPECT_CALL(host_, SetNetworkActivity(false));
452 462
453 EXPECT_TRUE(data_source_->loading()); 463 EXPECT_TRUE(data_source_->loading());
454 Stop(); 464 Stop();
455 } 465 }
456 466
467 // Make sure information regarding loaded data propogates to the host even if it
468 // gets initialized before the host is set.
469 TEST_F(BufferedDataSourceTest, HostSetAfterResponse) {
470 Initialize(media::PIPELINE_OK, false);
471 Respond(response_generator_.Generate206(0));
472
473 EXPECT_CALL(host_, SetNetworkActivity(_));
474 EXPECT_CALL(host_, SetTotalBytes(_));
475 EXPECT_CALL(host_, SetBufferedBytes(_));
476 data_source_->set_host(&host_);
477
478 Stop();
479 }
480
457 } // namespace webkit_media 481 } // 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