summaryrefslogtreecommitdiffstats
path: root/webkit/support/weburl_loader_mock.h
blob: 74d5ddb9eb5762353167218df8101d6461c2abc2 (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
// Copyright (c) 2011 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_SUPPORT_WEBURL_LOADER_MOCK_H_
#define WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_H_

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h"

namespace WebKit {
class WebData;
struct WebURLError;
class WebURLLoaderClient;
class WebURLRequest;
class WebURLResponse;
}

class WebURLLoaderMockFactory;

// A simple class for mocking WebURLLoader.
// If the WebURLLoaderMockFactory it is associated with has been configured to
// mock the request it gets, it serves the mocked resource.  Otherwise it just
// forwards it to the default loader.
class WebURLLoaderMock : public WebKit::WebURLLoader {
 public:
  // This object becomes the owner of |default_loader|.
  WebURLLoaderMock(WebURLLoaderMockFactory* factory,
                   WebKit::WebURLLoader* default_loader);
  virtual ~WebURLLoaderMock();

  // Simulates the asynchronous request being served.
  void ServeAsynchronousRequest(const WebKit::WebURLResponse& response,
                                const WebKit::WebData& data,
                                const WebKit::WebURLError& error);

  // WebURLLoader methods:
  virtual void loadSynchronously(const WebKit::WebURLRequest& request,
                                 WebKit::WebURLResponse& response,
                                 WebKit::WebURLError& error,
                                 WebKit::WebData& data);
  virtual void loadAsynchronously(const WebKit::WebURLRequest& request,
                                  WebKit::WebURLLoaderClient* client);
  virtual void cancel();
  virtual void setDefersLoading(bool defer);

 private:
  WebURLLoaderMockFactory* factory_;
  WebKit::WebURLLoaderClient* client_;
  scoped_ptr<WebKit::WebURLLoader> default_loader_;
  bool using_default_loader_;

  DISALLOW_COPY_AND_ASSIGN(WebURLLoaderMock);
};

#endif  // WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_H_