summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-17 05:26:11 +0000
committerbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-17 05:26:11 +0000
commit6a712e7c5c5a892abb46140946fca1c0c02c6454 (patch)
tree2469c4409733ae041f805af45290151e7679af2f
parent2ebdeab416bfececab30428de5fe6e440d004a56 (diff)
downloadchromium_src-6a712e7c5c5a892abb46140946fca1c0c02c6454.zip
chromium_src-6a712e7c5c5a892abb46140946fca1c0c02c6454.tar.gz
chromium_src-6a712e7c5c5a892abb46140946fca1c0c02c6454.tar.bz2
Add the HTTP URL redirect handling to WebURLLoaderMock.
BUG=NONE TEST=src/third_party/WebKit/Source/WebKit/chromium/tests/AssociatedURLLoaderTest.cpp Review URL: http://codereview.chromium.org/8907053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114914 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/support/weburl_loader_mock.cc16
-rw-r--r--webkit/support/weburl_loader_mock.h7
-rw-r--r--webkit/support/weburl_loader_mock_factory.cc13
3 files changed, 32 insertions, 4 deletions
diff --git a/webkit/support/weburl_loader_mock.cc b/webkit/support/weburl_loader_mock.cc
index bb00729..853f11e 100644
--- a/webkit/support/weburl_loader_mock.cc
+++ b/webkit/support/weburl_loader_mock.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -14,7 +14,8 @@ WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactory* factory,
: factory_(factory),
client_(NULL),
default_loader_(default_loader),
- using_default_loader_(false) {
+ using_default_loader_(false),
+ is_deferred_(false) {
}
WebURLLoaderMock::~WebURLLoaderMock() {
@@ -33,6 +34,16 @@ void WebURLLoaderMock::ServeAsynchronousRequest(
client_->didFinishLoading(this, 0);
}
+WebKit::WebURLRequest WebURLLoaderMock::ServeRedirect(
+ const WebKit::WebURLResponse& redirectResponse) {
+ WebKit::WebURLRequest newRequest;
+ newRequest.initialize();
+ GURL redirectURL(redirectResponse.httpHeaderField("Location"));
+ newRequest.setURL(redirectURL);
+ client_->willSendRequest(this, newRequest, redirectResponse);
+ return newRequest;
+}
+
void WebURLLoaderMock::loadSynchronously(const WebKit::WebURLRequest& request,
WebKit::WebURLResponse& response,
WebKit::WebURLError& error,
@@ -66,6 +77,7 @@ void WebURLLoaderMock::cancel() {
}
void WebURLLoaderMock::setDefersLoading(bool deferred) {
+ is_deferred_ = deferred;
if (using_default_loader_) {
default_loader_->setDefersLoading(deferred);
return;
diff --git a/webkit/support/weburl_loader_mock.h b/webkit/support/weburl_loader_mock.h
index 62c4f22..94b09f7 100644
--- a/webkit/support/weburl_loader_mock.h
+++ b/webkit/support/weburl_loader_mock.h
@@ -35,6 +35,10 @@ class WebURLLoaderMock : public WebKit::WebURLLoader {
const WebKit::WebData& data,
const WebKit::WebURLError& error);
+ // Simulates the redirect being served.
+ WebKit::WebURLRequest ServeRedirect(
+ const WebKit::WebURLResponse& redirectResponse);
+
// WebURLLoader methods:
virtual void loadSynchronously(const WebKit::WebURLRequest& request,
WebKit::WebURLResponse& response,
@@ -45,11 +49,14 @@ class WebURLLoaderMock : public WebKit::WebURLLoader {
virtual void cancel();
virtual void setDefersLoading(bool defer);
+ bool isDeferred() { return is_deferred_; }
+
private:
WebURLLoaderMockFactory* factory_;
WebKit::WebURLLoaderClient* client_;
scoped_ptr<WebKit::WebURLLoader> default_loader_;
bool using_default_loader_;
+ bool is_deferred_;
DISALLOW_COPY_AND_ASSIGN(WebURLLoaderMock);
};
diff --git a/webkit/support/weburl_loader_mock_factory.cc b/webkit/support/weburl_loader_mock_factory.cc
index 20da030..385316c 100644
--- a/webkit/support/weburl_loader_mock_factory.cc
+++ b/webkit/support/weburl_loader_mock_factory.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -71,7 +71,16 @@ void WebURLLoaderMockFactory::ServeAsynchronousRequests() {
WebURLError error;
WebData data;
LoadRequest(request, &response, &error, &data);
- loader->ServeAsynchronousRequest(response, data, error);
+ // Follow any redirect chain.
+ while (response.httpStatusCode() >= 300 &&
+ response.httpStatusCode() < 400) {
+ WebURLRequest newRequest = loader->ServeRedirect(response);
+ if (loader->isDeferred())
+ break;
+ LoadRequest(newRequest, &response, &error, &data);
+ }
+ if (!loader->isDeferred())
+ loader->ServeAsynchronousRequest(response, data, error);
pending_loaders_.erase(iter);
}
}