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 CONTENT_TEST_WEBURL_LOADER_MOCK_H_
6 #define CONTENT_TEST_WEBURL_LOADER_MOCK_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "third_party/WebKit/public/platform/WebURLLoader.h"
15 class WebURLLoaderClient
;
16 class WebURLLoaderTestDelegate
;
21 class WebURLLoaderMockFactory
;
23 // A simple class for mocking WebURLLoader.
24 // If the WebURLLoaderMockFactory it is associated with has been configured to
25 // mock the request it gets, it serves the mocked resource. Otherwise it just
26 // forwards it to the default loader.
27 class WebURLLoaderMock
: public blink::WebURLLoader
{
29 // This object becomes the owner of |default_loader|.
30 WebURLLoaderMock(WebURLLoaderMockFactory
* factory
,
31 blink::WebURLLoader
* default_loader
);
32 virtual ~WebURLLoaderMock();
34 // Simulates the asynchronous request being served.
35 void ServeAsynchronousRequest(blink::WebURLLoaderTestDelegate
* delegate
,
36 const blink::WebURLResponse
& response
,
37 const blink::WebData
& data
,
38 const blink::WebURLError
& error
);
40 // Simulates the redirect being served.
41 blink::WebURLRequest
ServeRedirect(
42 const blink::WebURLResponse
& redirectResponse
);
44 // WebURLLoader methods:
45 virtual void loadSynchronously(const blink::WebURLRequest
& request
,
46 blink::WebURLResponse
& response
,
47 blink::WebURLError
& error
,
48 blink::WebData
& data
);
49 virtual void loadAsynchronously(const blink::WebURLRequest
& request
,
50 blink::WebURLLoaderClient
* client
);
51 virtual void cancel();
52 virtual void setDefersLoading(bool defer
);
54 bool isDeferred() { return is_deferred_
; }
57 WebURLLoaderMockFactory
* factory_
;
58 blink::WebURLLoaderClient
* client_
;
59 scoped_ptr
<blink::WebURLLoader
> default_loader_
;
60 bool using_default_loader_
;
64 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderMock
);
67 #endif // CONTENT_TEST_WEBURL_LOADER_MOCK_H_