diff options
-rw-r--r-- | webkit/support/weburl_loader_mock.cc | 16 | ||||
-rw-r--r-- | webkit/support/weburl_loader_mock.h | 7 | ||||
-rw-r--r-- | webkit/support/weburl_loader_mock_factory.cc | 13 |
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); } } |