diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 21:59:16 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 21:59:16 +0000 |
commit | 9830942170ffdfa01625dc1b34fcc3138e873071 (patch) | |
tree | d3077810b2f5b79466824009aadbfd01703270ac /webkit/media/test_response_generator.cc | |
parent | 84f4dc00fe3211465900921ab044cc95606c8f85 (diff) | |
download | chromium_src-9830942170ffdfa01625dc1b34fcc3138e873071.zip chromium_src-9830942170ffdfa01625dc1b34fcc3138e873071.tar.gz chromium_src-9830942170ffdfa01625dc1b34fcc3138e873071.tar.bz2 |
Rewrite BufferedDataSource tests to use real BufferedResourceLoader objects.
The new tests expose the very real memory leak described in bug 100914. The fix for the leak is non trivial and will be addressed in a follow up patch.
BUG=100914
Review URL: http://codereview.chromium.org/8649002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/media/test_response_generator.cc')
-rw-r--r-- | webkit/media/test_response_generator.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/webkit/media/test_response_generator.cc b/webkit/media/test_response_generator.cc new file mode 100644 index 0000000..b3138c0 --- /dev/null +++ b/webkit/media/test_response_generator.cc @@ -0,0 +1,84 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/media/test_response_generator.h" + +#include "base/format_macros.h" +#include "base/string_number_conversions.h" +#include "base/stringprintf.h" +#include "net/base/net_errors.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" + +using WebKit::WebString; +using WebKit::WebURLError; +using WebKit::WebURLResponse; + +namespace webkit_media { + +TestResponseGenerator::TestResponseGenerator(const GURL& gurl, + int64 content_length) + : gurl_(gurl), + content_length_(content_length) { +} + +WebURLError TestResponseGenerator::GenerateError() { + WebURLError error; + error.reason = net::ERR_ABORTED; + error.domain = WebString::fromUTF8(net::kErrorDomain); + return error; +} + +WebURLResponse TestResponseGenerator::Generate200() { + WebURLResponse response(gurl_); + response.setHTTPStatusCode(200); + + response.setHTTPHeaderField( + WebString::fromUTF8("Content-Length"), + WebString::fromUTF8(base::Int64ToString(content_length_))); + response.setExpectedContentLength(content_length_); + return response; +} + +WebURLResponse TestResponseGenerator::Generate206(int64 first_byte_offset) { + return Generate206(first_byte_offset, kNormal); +} + +WebURLResponse TestResponseGenerator::Generate206(int64 first_byte_offset, + Flags flags) { + int64 range_content_length = content_length_ - first_byte_offset; + int64 last_byte_offset = content_length_ - 1; + + WebURLResponse response(gurl_); + response.setHTTPStatusCode(206); + + if ((flags & kNoAcceptRanges) == 0) { + response.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"), + WebString::fromUTF8("bytes")); + } + + if ((flags & kNoContentRange) == 0) { + std::string content_range = base::StringPrintf( + "bytes %" PRId64 "-%" PRId64 "/%" PRId64, + first_byte_offset, last_byte_offset, content_length_); + response.setHTTPHeaderField(WebString::fromUTF8("Content-Range"), + WebString::fromUTF8(content_range)); + } + + if ((flags & kNoContentLength) == 0) { + response.setHTTPHeaderField( + WebString::fromUTF8("Content-Length"), + WebString::fromUTF8(base::Int64ToString(range_content_length))); + response.setExpectedContentLength(range_content_length); + } + return response; +} + +WebURLResponse TestResponseGenerator::Generate404() { + WebURLResponse response(gurl_); + response.setHTTPStatusCode(404); + return response; +} + +} // namespace webkit_media |