summaryrefslogtreecommitdiffstats
path: root/webkit/media/test_response_generator.h
blob: 39744b0ab9803df8369c405d7708b9f9db405425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2012 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.

#ifndef WEBKIT_MEDIA_TEST_RESPONSE_GENERATOR_H_
#define WEBKIT_MEDIA_TEST_RESPONSE_GENERATOR_H_

#include "base/basictypes.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"

namespace webkit_media {

// Generates WebURLErrors and WebURLResponses suitable for testing purposes.
class TestResponseGenerator {
 public:
  enum Flags {
    kNormal = 0,
    kNoAcceptRanges = 1 << 0,   // Don't include Accept-Ranges in 206 response.
    kNoContentRange = 1 << 1,   // Don't include Content-Range in 206 response.
    kNoContentLength = 1 << 2,  // Don't include Content-Length in 206 response.
    kNoContentRangeInstanceSize = 1 << 3,  // Content-Range: N-M/* in 206.
  };

  // Build an HTTP response generator for the given URL. |content_length| is
  // used to generate Content-Length and Content-Range headers.
  TestResponseGenerator(const GURL& gurl, int64 content_length);

  // Generates a WebURLError object.
  WebKit::WebURLError GenerateError();

  // Generates a regular HTTP 200 response.
  WebKit::WebURLResponse Generate200();

  // Generates a regular HTTP 206 response starting from |first_byte_offset|
  // until the end of the resource.
  WebKit::WebURLResponse Generate206(int64 first_byte_offset);

  // Generates a custom HTTP 206 response starting from |first_byte_offset|
  // until the end of the resource. You can tweak what gets included in the
  // headers via |flags|.
  WebKit::WebURLResponse Generate206(int64 first_byte_offset, Flags flags);

  // Generates a regular HTTP 404 response.
  WebKit::WebURLResponse Generate404();

  // Generates a file:// response starting from |first_byte_offset| until the
  // end of the resource.
  //
  // If |first_byte_offset| is negative a response containing no content length
  // will be returned.
  WebKit::WebURLResponse GenerateFileResponse(int64 first_byte_offset);

  int64 content_length() { return content_length_; }

 private:
  GURL gurl_;
  int64 content_length_;

  DISALLOW_COPY_AND_ASSIGN(TestResponseGenerator);
};

}  // namespace webkit_media

#endif  // WEBKIT_MEDIA_TEST_RESPONSE_GENERATOR_H_