Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / blink / test_response_generator.cc
blobde7b5d5bce6b78c49df4a3ea0f4670cb4a61099a
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/blink/test_response_generator.h"
7 #include "base/format_macros.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h"
10 #include "net/base/net_errors.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
13 using blink::WebString;
14 using blink::WebURLError;
15 using blink::WebURLResponse;
17 namespace media {
19 TestResponseGenerator::TestResponseGenerator(const GURL& gurl,
20 int64 content_length)
21 : gurl_(gurl),
22 content_length_(content_length) {
25 WebURLError TestResponseGenerator::GenerateError() {
26 WebURLError error;
27 error.reason = net::ERR_ABORTED;
28 error.domain = WebString::fromUTF8(net::kErrorDomain);
29 return error;
32 WebURLResponse TestResponseGenerator::Generate200() {
33 WebURLResponse response(gurl_);
34 response.setHTTPStatusCode(200);
36 response.setHTTPHeaderField(
37 WebString::fromUTF8("Content-Length"),
38 WebString::fromUTF8(base::Int64ToString(content_length_)));
39 response.setExpectedContentLength(content_length_);
40 return response;
43 WebURLResponse TestResponseGenerator::Generate206(int64 first_byte_offset) {
44 return Generate206(first_byte_offset, kNormal);
47 WebURLResponse TestResponseGenerator::Generate206(int64 first_byte_offset,
48 Flags flags) {
49 int64 range_content_length = content_length_ - first_byte_offset;
50 int64 last_byte_offset = content_length_ - 1;
52 WebURLResponse response(gurl_);
53 response.setHTTPStatusCode(206);
55 if ((flags & kNoAcceptRanges) == 0) {
56 response.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"),
57 WebString::fromUTF8("bytes"));
60 if ((flags & kNoContentRange) == 0) {
61 std::string content_range = base::StringPrintf(
62 "bytes %" PRId64 "-%" PRId64 "/",
63 first_byte_offset, last_byte_offset);
64 if (flags & kNoContentRangeInstanceSize)
65 content_range += "*";
66 else
67 content_range += base::StringPrintf("%" PRId64, content_length_);
68 response.setHTTPHeaderField(WebString::fromUTF8("Content-Range"),
69 WebString::fromUTF8(content_range));
72 if ((flags & kNoContentLength) == 0) {
73 response.setHTTPHeaderField(
74 WebString::fromUTF8("Content-Length"),
75 WebString::fromUTF8(base::Int64ToString(range_content_length)));
76 response.setExpectedContentLength(range_content_length);
78 return response;
81 WebURLResponse TestResponseGenerator::Generate404() {
82 WebURLResponse response(gurl_);
83 response.setHTTPStatusCode(404);
84 return response;
87 WebURLResponse TestResponseGenerator::GenerateFileResponse(
88 int64 first_byte_offset) {
89 WebURLResponse response(gurl_);
90 response.setHTTPStatusCode(0);
92 if (first_byte_offset >= 0) {
93 response.setExpectedContentLength(content_length_ - first_byte_offset);
94 } else {
95 response.setExpectedContentLength(-1);
97 return response;
100 } // namespace media