OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_RENDERER_MEDIA_TEST_RESPONSE_GENERATOR_H_ | |
6 #define CONTENT_RENDERER_MEDIA_TEST_RESPONSE_GENERATOR_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "third_party/WebKit/public/platform/WebURLError.h" | |
10 #include "third_party/WebKit/public/platform/WebURLResponse.h" | |
11 #include "url/gurl.h" | |
12 | |
13 namespace content { | |
14 | |
15 // Generates WebURLErrors and WebURLResponses suitable for testing purposes. | |
16 class TestResponseGenerator { | |
17 public: | |
18 enum Flags { | |
19 kNormal = 0, | |
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. | |
24 }; | |
25 | |
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); | |
29 | |
30 // Generates a WebURLError object. | |
31 blink::WebURLError GenerateError(); | |
32 | |
33 // Generates a regular HTTP 200 response. | |
34 blink::WebURLResponse Generate200(); | |
35 | |
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); | |
39 | |
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); | |
44 | |
45 // Generates a regular HTTP 404 response. | |
46 blink::WebURLResponse Generate404(); | |
47 | |
48 // Generates a file:// response starting from |first_byte_offset| until the | |
49 // end of the resource. | |
50 // | |
51 // If |first_byte_offset| is negative a response containing no content length | |
52 // will be returned. | |
53 blink::WebURLResponse GenerateFileResponse(int64 first_byte_offset); | |
54 | |
55 int64 content_length() { return content_length_; } | |
56 | |
57 private: | |
58 GURL gurl_; | |
59 int64 content_length_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(TestResponseGenerator); | |
62 }; | |
63 | |
64 } // namespace content | |
65 | |
66 #endif // CONTENT_RENDERER_MEDIA_TEST_RESPONSE_GENERATOR_H_ | |
OLD | NEW |