summaryrefslogtreecommitdiffstats
path: root/webkit/support/weburl_loader_mock.cc
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.cc
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.cc')
-rw-r--r--webkit/support/weburl_loader_mock.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/webkit/support/weburl_loader_mock.cc b/webkit/support/weburl_loader_mock.cc
new file mode 100644
index 0000000..18f2387
--- /dev/null
+++ b/webkit/support/weburl_loader_mock.cc
@@ -0,0 +1,73 @@
+// 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.
+
+#include "webkit/support/weburl_loader_mock.h"
+
+#include "third_party/WebKit/WebKit/chromium/public/WebData.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h"
+#include "webkit/support/weburl_loader_mock_factory.h"
+
+WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactory* factory,
+ WebKit::WebURLLoader* default_loader)
+ : factory_(factory),
+ client_(NULL),
+ default_loader_(default_loader),
+ using_default_loader_(false) {
+}
+
+WebURLLoaderMock::~WebURLLoaderMock() {
+}
+
+void WebURLLoaderMock::ServeAsynchronousRequest(
+ const WebKit::WebURLResponse& response,
+ const WebKit::WebData& data,
+ const WebKit::WebURLError& error) {
+ DCHECK(!using_default_loader_);
+ if (!client_)
+ return;
+
+ client_->didReceiveResponse(this, response);
+ client_->didReceiveData(this, data.data(), data.size());
+ client_->didFinishLoading(this);
+}
+
+void WebURLLoaderMock::loadSynchronously(const WebKit::WebURLRequest& request,
+ WebKit::WebURLResponse& response,
+ WebKit::WebURLError& error,
+ WebKit::WebData& data) {
+ if (factory_->IsMockedURL(request.url())) {
+ factory_->LoadSynchronously(request, &response, &error, &data);
+ return;
+ }
+ using_default_loader_ = true;
+ default_loader_->loadSynchronously(request, response, error, data);
+}
+
+void WebURLLoaderMock::loadAsynchronously(const WebKit::WebURLRequest& request,
+ WebKit::WebURLLoaderClient* client) {
+ if (factory_->IsMockedURL(request.url())) {
+ client_ = client;
+ factory_->LoadAsynchronouly(request, this);
+ return;
+ }
+ using_default_loader_ = true;
+ default_loader_->loadAsynchronously(request, client);
+}
+
+void WebURLLoaderMock::cancel() {
+ if (using_default_loader_) {
+ default_loader_->cancel();
+ return;
+ }
+ client_ = NULL;
+ factory_->CancelLoad(this);
+}
+
+void WebURLLoaderMock::setDefersLoading(bool deferred) {
+ if (using_default_loader_) {
+ default_loader_->setDefersLoading(deferred);
+ return;
+ }
+ NOTIMPLEMENTED();
+}