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

Side by Side Diff: webkit/glue/media/buffered_resource_loader_unittest.cc

Issue 6926002: Merge 83942 - Partial revert of 82061 so we keep the initial unbounded range request. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/742/src/
Patch Set: Created 9 years, 7 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/glue/media/buffered_resource_loader.cc ('k') | no next file » | 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/http/http_util.h" 10 #include "net/http/http_util.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 if (status == net::OK) { 124 if (status == net::OK) {
125 EXPECT_EQ(instance_size, loader_->content_length()); 125 EXPECT_EQ(instance_size, loader_->content_length());
126 EXPECT_EQ(instance_size, loader_->instance_size()); 126 EXPECT_EQ(instance_size, loader_->instance_size());
127 } 127 }
128 128
129 EXPECT_FALSE(loader_->range_supported()); 129 EXPECT_FALSE(loader_->range_supported());
130 } 130 }
131 131
132 void PartialResponse(int64 first_position, int64 last_position, 132 void PartialResponse(int64 first_position, int64 last_position,
133 int64 instance_size) { 133 int64 instance_size) {
134 PartialResponse(first_position, last_position, instance_size, false, true);
135 }
136
137 void PartialResponse(int64 first_position, int64 last_position,
138 int64 instance_size, bool chunked, bool accept_ranges) {
134 EXPECT_CALL(*this, StartCallback(net::OK)); 139 EXPECT_CALL(*this, StartCallback(net::OK));
135 int64 content_length = last_position - first_position + 1;
136 140
137 WebURLResponse response(gurl_); 141 WebURLResponse response(gurl_);
138 response.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"),
139 WebString::fromUTF8("bytes"));
140 response.setHTTPHeaderField(WebString::fromUTF8("Content-Range"), 142 response.setHTTPHeaderField(WebString::fromUTF8("Content-Range"),
141 WebString::fromUTF8(base::StringPrintf("bytes " 143 WebString::fromUTF8(base::StringPrintf("bytes "
142 "%" PRId64 "-%" PRId64 "/%" PRId64, 144 "%" PRId64 "-%" PRId64 "/%" PRId64,
143 first_position, 145 first_position,
144 last_position, 146 last_position,
145 instance_size))); 147 instance_size)));
148
149 // HTTP 1.1 doesn't permit Content-Length with Transfer-Encoding: chunked.
150 int64 content_length = -1;
151 if (chunked) {
152 response.setHTTPHeaderField(WebString::fromUTF8("Transfer-Encoding"),
153 WebString::fromUTF8("chunked"));
154 } else {
155 content_length = last_position - first_position + 1;
156 }
146 response.setExpectedContentLength(content_length); 157 response.setExpectedContentLength(content_length);
158
159 // A server isn't required to return Accept-Ranges even though it might.
160 if (accept_ranges) {
161 response.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"),
162 WebString::fromUTF8("bytes"));
163 }
164
147 response.setHTTPStatusCode(kHttpPartialContent); 165 response.setHTTPStatusCode(kHttpPartialContent);
148 loader_->didReceiveResponse(url_loader_, response); 166 loader_->didReceiveResponse(url_loader_, response);
167
168 // XXX: what's the difference between these two? For example in the chunked
169 // range request case, Content-Length is unspecified (because it's chunked)
170 // but Content-Range: a-b/c can be returned, where c == Content-Length
171 //
172 // Can we eliminate one?
149 EXPECT_EQ(content_length, loader_->content_length()); 173 EXPECT_EQ(content_length, loader_->content_length());
150 EXPECT_EQ(instance_size, loader_->instance_size()); 174 EXPECT_EQ(instance_size, loader_->instance_size());
175
176 // A valid partial response should always result in this being true.
151 EXPECT_TRUE(loader_->range_supported()); 177 EXPECT_TRUE(loader_->range_supported());
152 } 178 }
153 179
154 void Redirect(const char* url) { 180 void Redirect(const char* url) {
155 GURL redirectUrl(url); 181 GURL redirectUrl(url);
156 WebKit::WebURLRequest newRequest(redirectUrl); 182 WebKit::WebURLRequest newRequest(redirectUrl);
157 WebKit::WebURLResponse redirectResponse(gurl_); 183 WebKit::WebURLResponse redirectResponse(gurl_);
158 184
159 loader_->willSendRequest(url_loader_, newRequest, redirectResponse); 185 loader_->willSendRequest(url_loader_, newRequest, redirectResponse);
160 186
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 276 }
251 277
252 // Tests that a partial content response is received. 278 // Tests that a partial content response is received.
253 TEST_F(BufferedResourceLoaderTest, PartialResponse) { 279 TEST_F(BufferedResourceLoaderTest, PartialResponse) {
254 Initialize(kHttpUrl, 100, 200); 280 Initialize(kHttpUrl, 100, 200);
255 Start(); 281 Start();
256 PartialResponse(100, 200, 1024); 282 PartialResponse(100, 200, 1024);
257 StopWhenLoad(); 283 StopWhenLoad();
258 } 284 }
259 285
286 TEST_F(BufferedResourceLoaderTest, PartialResponse_Chunked) {
287 Initialize(kHttpUrl, 100, 200);
288 Start();
289 PartialResponse(100, 200, 1024, true, true);
290 StopWhenLoad();
291 }
292
293 TEST_F(BufferedResourceLoaderTest, PartialResponse_NoAcceptRanges) {
294 Initialize(kHttpUrl, 100, 200);
295 Start();
296 PartialResponse(100, 200, 1024, false, false);
297 StopWhenLoad();
298 }
299
300 TEST_F(BufferedResourceLoaderTest, PartialResponse_ChunkedNoAcceptRanges) {
301 Initialize(kHttpUrl, 100, 200);
302 Start();
303 PartialResponse(100, 200, 1024, true, false);
304 StopWhenLoad();
305 }
306
260 // Tests that an invalid partial response is received. 307 // Tests that an invalid partial response is received.
261 TEST_F(BufferedResourceLoaderTest, InvalidPartialResponse) { 308 TEST_F(BufferedResourceLoaderTest, InvalidPartialResponse) {
262 Initialize(kHttpUrl, 0, 10); 309 Initialize(kHttpUrl, 0, 10);
263 Start(); 310 Start();
264 311
265 EXPECT_CALL(*this, StartCallback(net::ERR_INVALID_RESPONSE)); 312 EXPECT_CALL(*this, StartCallback(net::ERR_INVALID_RESPONSE));
266 EXPECT_CALL(*url_loader_, cancel()) 313 EXPECT_CALL(*url_loader_, cancel())
267 .WillOnce(RequestCanceled(loader_)); 314 .WillOnce(RequestCanceled(loader_));
268 315
269 WebURLResponse response(gurl_); 316 WebURLResponse response(gurl_);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 Start(); 543 Start();
497 Redirect(kHttpRedirectToSameDomainUrl1); 544 Redirect(kHttpRedirectToSameDomainUrl1);
498 Redirect(kHttpRedirectToDifferentDomainUrl1); 545 Redirect(kHttpRedirectToDifferentDomainUrl1);
499 EXPECT_FALSE(loader_->HasSingleOrigin()); 546 EXPECT_FALSE(loader_->HasSingleOrigin());
500 StopWhenLoad(); 547 StopWhenLoad();
501 } 548 }
502 549
503 // TODO(hclam): add unit test for defer loading. 550 // TODO(hclam): add unit test for defer loading.
504 551
505 } // namespace webkit_glue 552 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/media/buffered_resource_loader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698