| Index: net/http/http_util_unittest.cc
|
| diff --git a/net/http/http_util_unittest.cc b/net/http/http_util_unittest.cc
|
| index 54acf68d3c3d52c3bc28aa4b0f9ee3603ac098cd..9cbd8c9f36fcdae49d1c21ab27dc48da18af3174 100644
|
| --- a/net/http/http_util_unittest.cc
|
| +++ b/net/http/http_util_unittest.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/strings/string_util.h"
|
| +#include "net/http/http_response_headers.h"
|
| #include "net/http/http_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -100,6 +101,51 @@ TEST(HttpUtilTest, IsSafeHeader) {
|
| }
|
| }
|
|
|
| +TEST(HttpUtilTest, UpdateResponseHeaderWithRange) {
|
| + const struct {
|
| + const char* orig_headers;
|
| + const char* expected_headers;
|
| + } tests[] = {
|
| + { "HTTP/1.1 200 OK\n"
|
| + "Content-Length: 450\n",
|
| +
|
| + "HTTP/1.1 206 Partial Content\n"
|
| + "Content-Range: bytes 3-5/450\n"
|
| + "Content-Length: 3\n",
|
| + },
|
| + { "HTTP/1.1 200 OK\n"
|
| + "Content-Length: 5\n",
|
| +
|
| + "HTTP/1.1 206 Partial Content\n"
|
| + "Content-Range: bytes 3-5/5\n"
|
| + "Content-Length: 3\n",
|
| + },
|
| + };
|
| + const net::HttpByteRange invalid;
|
| + const net::HttpByteRange valid = net::HttpByteRange::Bounded(3, 5);
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
|
| + std::string orig_headers(tests[i].orig_headers);
|
| + std::replace(orig_headers.begin(), orig_headers.end(), '\n', '\0');
|
| + scoped_refptr<net::HttpResponseHeaders> parsed(
|
| + new net::HttpResponseHeaders(orig_headers + '\0'));
|
| + int64 content_size = parsed->GetContentLength();
|
| + std::string resulting_headers;
|
| +
|
| + // With invalid range.
|
| + EXPECT_FALSE(HttpUtil::UpdateResponseHeadersWithRange(
|
| + invalid, content_size, true, parsed.get()));
|
| + parsed->GetNormalizedHeaders(&resulting_headers);
|
| + EXPECT_EQ(std::string(tests[i].orig_headers), resulting_headers);
|
| +
|
| + // With valid (3,5) range.
|
| + EXPECT_TRUE(HttpUtil::UpdateResponseHeadersWithRange(
|
| + valid, content_size, true, parsed.get()));
|
| + parsed->GetNormalizedHeaders(&resulting_headers);
|
| + EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
|
| + }
|
| +}
|
| +
|
| TEST(HttpUtilTest, HasHeader) {
|
| static const struct {
|
| const char* headers;
|
|
|