summaryrefslogtreecommitdiffstats
path: root/webkit/support/weburl_loader_mock.h
diff options
context:
space:
mode:
authorjcivelli@google.com <jcivelli@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-21 20:54:09 +0000
committerjcivelli@google.com <jcivelli@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-21 20:54:09 +0000
commit0fbd522d848313c647d2301990ea18973d887b69 (patch)
tree1cd783a8dacbfbf640661196edb6c92a6e7c16dd /webkit/support/weburl_loader_mock.h
parenta74f123ad667cade1aa366bd423f6b68c99a2a78 (diff)
downloadchromium_src-0fbd522d848313c647d2301990ea18973d887b69.zip
chromium_src-0fbd522d848313c647d2301990ea18973d887b69.tar.gz
chromium_src-0fbd522d848313c647d2301990ea18973d887b69.tar.bz2
Adding a way to mock WebURLLoader in webkit_support.
This was originally in a CL in Webkit (https://bugs.webkit.org/show_bug.cgi?id=39456) but seems to make more sense in webkit_support. BUG=None TEST=None (the above CL makes use of this). Review URL: http://codereview.chromium.org/2749020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50382 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/support/weburl_loader_mock.h')
-rw-r--r--webkit/support/weburl_loader_mock.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/webkit/support/weburl_loader_mock.h b/webkit/support/weburl_loader_mock.h
new file mode 100644
index 0000000..d0a690f
--- /dev/null
+++ b/webkit/support/weburl_loader_mock.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2010 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/logging.h"
+#include "base/scoped_ptr.h"
+#include "third_party/WebKit/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_