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