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

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

Issue 10692106: Split BufferedResourceLoader's network callback into separate loading state and progress callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix stuff Created 8 years, 5 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
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 "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "media/base/media_log.h" 7 #include "media/base/media_log.h"
8 #include "media/base/mock_callback.h" 8 #include "media/base/mock_callback.h"
9 #include "media/base/mock_data_source_host.h" 9 #include "media/base/mock_data_source_host.h"
10 #include "media/base/mock_filters.h" 10 #include "media/base/mock_filters.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 "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h"
13 #include "webkit/media/buffered_data_source.h" 13 #include "webkit/media/buffered_data_source.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 #include "webkit/media/test_response_generator.h" 16 #include "webkit/media/test_response_generator.h"
17 17
18 using ::testing::_; 18 using ::testing::_;
19 using ::testing::Assign; 19 using ::testing::Assign;
20 using ::testing::Invoke; 20 using ::testing::Invoke;
21 using ::testing::NiceMock;
21 using ::testing::StrictMock; 22 using ::testing::StrictMock;
22 using ::testing::NiceMock;
23 23
24 using WebKit::WebFrame; 24 using WebKit::WebFrame;
25 using WebKit::WebString; 25 using WebKit::WebString;
26 using WebKit::WebURLLoader; 26 using WebKit::WebURLLoader;
27 using WebKit::WebURLResponse; 27 using WebKit::WebURLResponse;
28 using WebKit::WebView; 28 using WebKit::WebView;
29 29
30 using webkit_glue::MockWebFrameClient; 30 using webkit_glue::MockWebFrameClient;
31 using webkit_glue::MockWebURLLoader; 31 using webkit_glue::MockWebURLLoader;
32 32
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 view_->mainFrame()); 97 view_->mainFrame());
98 data_source_->set_host(&host_); 98 data_source_->set_host(&host_);
99 } 99 }
100 100
101 virtual ~BufferedDataSourceTest() { 101 virtual ~BufferedDataSourceTest() {
102 view_->close(); 102 view_->close();
103 } 103 }
104 104
105 void Initialize(media::PipelineStatus expected) { 105 void Initialize(media::PipelineStatus expected) {
106 ExpectCreateResourceLoader(); 106 ExpectCreateResourceLoader();
107
108 EXPECT_FALSE(data_source_->downloading());
107 data_source_->Initialize(response_generator_.gurl(), 109 data_source_->Initialize(response_generator_.gurl(),
108 BufferedResourceLoader::kUnspecified, 110 BufferedResourceLoader::kUnspecified,
109 media::NewExpectedStatusCB(expected)); 111 media::NewExpectedStatusCB(expected));
110 message_loop_.RunAllPending(); 112 message_loop_.RunAllPending();
113 EXPECT_TRUE(data_source_->downloading());
111 } 114 }
112 115
113 // Helper to initialize tests with a valid 206 response. 116 // Helper to initialize tests with a valid 206 response.
114 void InitializeWith206Response() { 117 void InitializeWith206Response() {
115 Initialize(media::PIPELINE_OK); 118 Initialize(media::PIPELINE_OK);
116 119
117 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 120 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()));
118 Respond(response_generator_.Generate206(0)); 121 Respond(response_generator_.Generate206(0));
119 } 122 }
120 123
(...skipping 16 matching lines...) Expand all
137 .WillOnce(Invoke(data_source_.get(), 140 .WillOnce(Invoke(data_source_.get(),
138 &MockBufferedDataSource::CreateMockResourceLoader)); 141 &MockBufferedDataSource::CreateMockResourceLoader));
139 message_loop_.RunAllPending(); 142 message_loop_.RunAllPending();
140 } 143 }
141 144
142 void Respond(const WebURLResponse& response) { 145 void Respond(const WebURLResponse& response) {
143 loader()->didReceiveResponse(url_loader(), response); 146 loader()->didReceiveResponse(url_loader(), response);
144 message_loop_.RunAllPending(); 147 message_loop_.RunAllPending();
145 } 148 }
146 149
147 void FinishRead() { 150 void ReceiveData(int size) {
148 loader()->didReceiveData(url_loader(), data_, kDataSize, kDataSize); 151 scoped_array<char> data(new char[size]);
152 memset(data.get(), 0xA5, size); // Arbitrary non-zero value.
153
154 loader()->didReceiveData(url_loader(), data.get(), size, size);
149 message_loop_.RunAllPending(); 155 message_loop_.RunAllPending();
150 } 156 }
151 157
152 void FinishLoading() { 158 void FinishLoading() {
153 data_source_->set_loading(false); 159 data_source_->set_loading(false);
154 loader()->didFinishLoading(url_loader(), 0); 160 loader()->didFinishLoading(url_loader(), 0);
155 message_loop_.RunAllPending(); 161 message_loop_.RunAllPending();
156 } 162 }
157 163
158 MOCK_METHOD1(ReadCallback, void(int size)); 164 MOCK_METHOD1(ReadCallback, void(int size));
(...skipping 28 matching lines...) Expand all
187 MockWebFrameClient client_; 193 MockWebFrameClient client_;
188 WebView* view_; 194 WebView* view_;
189 195
190 StrictMock<media::MockDataSourceHost> host_; 196 StrictMock<media::MockDataSourceHost> host_;
191 MessageLoop message_loop_; 197 MessageLoop message_loop_;
192 198
193 private: 199 private:
194 // Used for calling BufferedDataSource::Read(). 200 // Used for calling BufferedDataSource::Read().
195 uint8 buffer_[kDataSize]; 201 uint8 buffer_[kDataSize];
196 202
197 // Used for calling BufferedResourceLoader::didReceiveData().
198 char data_[kDataSize];
199
200 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); 203 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest);
201 }; 204 };
202 205
203 TEST_F(BufferedDataSourceTest, Range_Supported) { 206 TEST_F(BufferedDataSourceTest, Range_Supported) {
204 Initialize(media::PIPELINE_OK); 207 Initialize(media::PIPELINE_OK);
205 208
206 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); 209 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length()));
207 Respond(response_generator_.Generate206(0)); 210 Respond(response_generator_.Generate206(0));
208 211
209 EXPECT_TRUE(data_source_->loading()); 212 EXPECT_TRUE(data_source_->loading());
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 EXPECT_TRUE(data_source_->loading()); 433 EXPECT_TRUE(data_source_->loading());
431 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 434 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
432 Stop(); 435 Stop();
433 } 436 }
434 437
435 TEST_F(BufferedDataSourceTest, Read) { 438 TEST_F(BufferedDataSourceTest, Read) {
436 InitializeWith206Response(); 439 InitializeWith206Response();
437 440
438 ReadAt(0); 441 ReadAt(0);
439 442
440 // When the read completes we'll update our network status. 443 // Receive first half of the read.
444 EXPECT_CALL(host_, AddBufferedByteRange(0, (kDataSize / 2) - 1));
445 ReceiveData(kDataSize / 2);
446
447 // Receive last half of the read.
448 EXPECT_CALL(*this, ReadCallback(kDataSize));
441 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); 449 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
442 EXPECT_CALL(*this, ReadCallback(kDataSize)); 450 ReceiveData(kDataSize / 2);
443 FinishRead();
444 EXPECT_TRUE(data_source_->downloading());
445
446 // During teardown we'll also report our final network status.
447 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
448 451
449 EXPECT_TRUE(data_source_->downloading()); 452 EXPECT_TRUE(data_source_->downloading());
450 Stop(); 453 Stop();
451 EXPECT_FALSE(data_source_->downloading()); 454 // XXXXXXXXXXXX Should we report something on didFail? The idea here is that
455 // by calling Stop() on the object no more CBs should execute
456 EXPECT_TRUE(data_source_->downloading());
scherkus (not reviewing) 2012/07/09 20:35:48 ATTN!
Ami GONE FROM CHROMIUM 2012/07/10 02:40:14 This change seems wrong. Why are we still downloa
Ami GONE FROM CHROMIUM 2012/07/10 02:40:14 Shouldn't BDS be firing a ReadCB(kReadError) in ca
scherkus (not reviewing) 2012/07/10 03:22:20 It does and we cover that case somewhat indirectly
scherkus (not reviewing) 2012/07/10 03:22:20 We're not really "downloading" per se -- it's our
452 } 457 }
453 458
454 } // namespace webkit_media 459 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698