diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-10 21:28:05 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-10 21:28:05 +0000 |
commit | bfea4f019c41e9e9327c0b8b07526bed8b1f3e89 (patch) | |
tree | 3c351fc581f532b32e39a0b2713efe754497d856 /webkit | |
parent | 3d7c43f861956c50ff4d048601e9ebfcc139c9f7 (diff) | |
download | chromium_src-bfea4f019c41e9e9327c0b8b07526bed8b1f3e89.zip chromium_src-bfea4f019c41e9e9327c0b8b07526bed8b1f3e89.tar.gz chromium_src-bfea4f019c41e9e9327c0b8b07526bed8b1f3e89.tar.bz2 |
Add WebURLLoaderMockFactory::GetLastHandledAsynchronousRequest.
This provides a way of getting the last request that was actually (mock) served,
so that WebKit unit tests can, e.g., inspect headers that were "actually" sent
out.
BUG=http://crbug.com/134615 and https://bugs.webkit.org/show_bug.cgi?id=90893
TEST=see WebKit bug (forthcoming WebKit unit test)
Review URL: https://chromiumcodereview.appspot.com/10735037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145960 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/support/webkit_support.cc | 5 | ||||
-rw-r--r-- | webkit/support/webkit_support.h | 3 | ||||
-rw-r--r-- | webkit/support/weburl_loader_mock_factory.cc | 8 | ||||
-rw-r--r-- | webkit/support/weburl_loader_mock_factory.h | 7 |
4 files changed, 22 insertions, 1 deletions
diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc index 276541bd..3eabf4d 100644 --- a/webkit/support/webkit_support.cc +++ b/webkit/support/webkit_support.cc @@ -487,6 +487,11 @@ void ServeAsynchronousMockedRequests() { ServeAsynchronousRequests(); } +WebKit::WebURLRequest GetLastHandledAsynchronousMockedRequest() { + return test_environment->webkit_platform_support()->url_loader_factory()-> + GetLastHandledAsynchronousRequest(); +} + // Wrapper for debug_util bool BeingDebugged() { return base::debug::BeingDebugged(); diff --git a/webkit/support/webkit_support.h b/webkit/support/webkit_support.h index 130642a..7fb2640 100644 --- a/webkit/support/webkit_support.h +++ b/webkit/support/webkit_support.h @@ -129,6 +129,9 @@ void UnregisterAllMockedURLs(); // returns all the pending requests have been processed. void ServeAsynchronousMockedRequests(); +// Returns the last request that handled by |ServeAsynchronousMockedRequests()|. +WebKit::WebURLRequest GetLastHandledAsynchronousMockedRequest(); + // Wrappers to minimize dependecy. // -------- Debugging diff --git a/webkit/support/weburl_loader_mock_factory.cc b/webkit/support/weburl_loader_mock_factory.cc index ccf3891..b3d3fdd 100644 --- a/webkit/support/weburl_loader_mock_factory.cc +++ b/webkit/support/weburl_loader_mock_factory.cc @@ -61,6 +61,7 @@ void WebURLLoaderMockFactory::UnregisterAllURLs() { } void WebURLLoaderMockFactory::ServeAsynchronousRequests() { + last_handled_asynchronous_request_.reset(); // Serving a request might trigger more requests, so we cannot iterate on // pending_loaders_ as it might get modified. while (!pending_loaders_.empty()) { @@ -70,6 +71,7 @@ void WebURLLoaderMockFactory::ServeAsynchronousRequests() { WebURLResponse response; WebURLError error; WebData data; + last_handled_asynchronous_request_ = request; LoadRequest(request, &response, &error, &data); // Follow any redirects while the loader is still active. while (response.httpStatusCode() >= 300 && @@ -77,6 +79,7 @@ void WebURLLoaderMockFactory::ServeAsynchronousRequests() { WebURLRequest newRequest = loader->ServeRedirect(response); if (!IsPending(loader) || loader->isDeferred()) break; + last_handled_asynchronous_request_ = newRequest; LoadRequest(newRequest, &response, &error, &data); } // Serve the request if the loader is still active. @@ -87,6 +90,11 @@ void WebURLLoaderMockFactory::ServeAsynchronousRequests() { } } +WebKit::WebURLRequest +WebURLLoaderMockFactory::GetLastHandledAsynchronousRequest() { + return last_handled_asynchronous_request_; +} + bool WebURLLoaderMockFactory::IsMockedURL(const WebKit::WebURL& url) { return url_to_reponse_info_.find(url) != url_to_reponse_info_.end(); } diff --git a/webkit/support/weburl_loader_mock_factory.h b/webkit/support/weburl_loader_mock_factory.h index 6c9d80a..cecc030 100644 --- a/webkit/support/weburl_loader_mock_factory.h +++ b/webkit/support/weburl_loader_mock_factory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -52,6 +52,9 @@ class WebURLLoaderMockFactory { // Serves all the pending asynchronous requests. void ServeAsynchronousRequests(); + // Returns the last request handled by |ServeAsynchronousRequests()|. + WebKit::WebURLRequest GetLastHandledAsynchronousRequest(); + // Returns true if |url| was registered for being mocked. bool IsMockedURL(const WebKit::WebURL& url); @@ -91,6 +94,8 @@ class WebURLLoaderMockFactory { typedef std::map<WebKit::WebURL, ResponseInfo> URLToResponseMap; URLToResponseMap url_to_reponse_info_; + WebKit::WebURLRequest last_handled_asynchronous_request_; + DISALLOW_COPY_AND_ASSIGN(WebURLLoaderMockFactory); }; |