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 #ifndef MEDIA_BLINK_TEST_RESPONSE_GENERATOR_H_
6 #define MEDIA_BLINK_TEST_RESPONSE_GENERATOR_H_
8 #include "base/basictypes.h"
9 #include "third_party/WebKit/public/platform/WebURLError.h"
10 #include "third_party/WebKit/public/platform/WebURLResponse.h"
15 // Generates WebURLErrors and WebURLResponses suitable for testing purposes.
16 class TestResponseGenerator
{
20 kNoAcceptRanges
= 1 << 0, // Don't include Accept-Ranges in 206 response.
21 kNoContentRange
= 1 << 1, // Don't include Content-Range in 206 response.
22 kNoContentLength
= 1 << 2, // Don't include Content-Length in 206 response.
23 kNoContentRangeInstanceSize
= 1 << 3, // Content-Range: N-M/* in 206.
26 // Build an HTTP response generator for the given URL. |content_length| is
27 // used to generate Content-Length and Content-Range headers.
28 TestResponseGenerator(const GURL
& gurl
, int64 content_length
);
30 // Generates a WebURLError object.
31 blink::WebURLError
GenerateError();
33 // Generates a regular HTTP 200 response.
34 blink::WebURLResponse
Generate200();
36 // Generates a regular HTTP 206 response starting from |first_byte_offset|
37 // until the end of the resource.
38 blink::WebURLResponse
Generate206(int64 first_byte_offset
);
40 // Generates a custom HTTP 206 response starting from |first_byte_offset|
41 // until the end of the resource. You can tweak what gets included in the
42 // headers via |flags|.
43 blink::WebURLResponse
Generate206(int64 first_byte_offset
, Flags flags
);
45 // Generates a regular HTTP 206 response starting from |first_byte_offset|
46 // until |last_byte_offset|.
47 blink::WebURLResponse
GeneratePartial206(int64 first_byte_offset
,
48 int64 last_byte_offset
);
50 // Generates a custom HTTP 206 response starting from |first_byte_offset|
51 // until |last_byte_offset|. You can tweak what gets included in the
52 // headers via |flags|.
53 blink::WebURLResponse
GeneratePartial206(int64 first_byte_offset
,
54 int64 last_byte_offset
,
57 // Generates a regular HTTP 404 response.
58 blink::WebURLResponse
Generate404();
60 // Generates a file:// response starting from |first_byte_offset| until the
61 // end of the resource.
63 // If |first_byte_offset| is negative a response containing no content length
65 blink::WebURLResponse
GenerateFileResponse(int64 first_byte_offset
);
67 int64
content_length() { return content_length_
; }
71 int64 content_length_
;
73 DISALLOW_COPY_AND_ASSIGN(TestResponseGenerator
);
78 #endif // MEDIA_BLINK_TEST_RESPONSE_GENERATOR_H_