OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 WEBKIT_MEDIA_TEST_RESPONSE_GENERATOR_H_ |
| 6 #define WEBKIT_MEDIA_TEST_RESPONSE_GENERATOR_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "googleurl/src/gurl.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 12 |
| 13 namespace webkit_media { |
| 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 }; |
| 24 |
| 25 // Build an HTTP response generator for the given URL. |content_length| is |
| 26 // used to generate Content-Length and Content-Range headers. |
| 27 TestResponseGenerator(const GURL& gurl, int64 content_length); |
| 28 |
| 29 // Generates a WebURLError object. |
| 30 WebKit::WebURLError GenerateError(); |
| 31 |
| 32 // Generates a regular HTTP 200 response. |
| 33 WebKit::WebURLResponse Generate200(); |
| 34 |
| 35 // Generates a regular HTTP 206 response starting from |first_byte_offset| |
| 36 // until the end of the resource. |
| 37 WebKit::WebURLResponse Generate206(int64 first_byte_offset); |
| 38 |
| 39 // Generates a custom HTTP 206 response starting from |first_byte_offset| |
| 40 // until the end of the resource. You can tweak what gets included in the |
| 41 // headers via |flags|. |
| 42 WebKit::WebURLResponse Generate206(int64 first_byte_offset, Flags flags); |
| 43 |
| 44 // Generates a regular HTTP 404 response. |
| 45 WebKit::WebURLResponse Generate404(); |
| 46 |
| 47 const GURL& gurl() { return gurl_; } |
| 48 int64 content_length() { return content_length_; } |
| 49 |
| 50 private: |
| 51 GURL gurl_; |
| 52 int64 content_length_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(TestResponseGenerator); |
| 55 }; |
| 56 |
| 57 } // namespace webkit_media |
| 58 |
| 59 #endif // WEBKIT_MEDIA_TEST_RESPONSE_GENERATOR_H_ |
OLD | NEW |