summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxunjieli <xunjieli@chromium.org>2014-09-10 16:23:31 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-10 23:25:48 +0000
commit0332c191aa02efc6c24d0c87a1d41b7c12d3b8a8 (patch)
tree0b5ee639c7015db3dc82b42ffc5f5a32f81fbbc0
parentdb7726aee7993008dff742790337f950fb371ebf (diff)
downloadchromium_src-0332c191aa02efc6c24d0c87a1d41b7c12d3b8a8.zip
chromium_src-0332c191aa02efc6c24d0c87a1d41b7c12d3b8a8.tar.gz
chromium_src-0332c191aa02efc6c24d0c87a1d41b7c12d3b8a8.tar.bz2
Move url_request_mock_http_job to net/test/url_request/
This CL is a part of the effort to move mock URLRequestJob files from content/test/net to net/test/url_request/. The reason for this refactoring is that Cronet will need to use these classes for testing, so it will be nice if they can be in net/test, as the dependency can work out nicely. BUG= Review URL: https://codereview.chromium.org/541743002 Cr-Commit-Position: refs/heads/master@{#294255}
-rw-r--r--chrome/browser/browser_encoding_browsertest.cc8
-rw-r--r--chrome/browser/browsing_data/browsing_data_remover_browsertest.cc7
-rw-r--r--chrome/browser/captive_portal/captive_portal_browsertest.cc24
-rw-r--r--chrome/browser/content_settings/content_settings_browsertest.cc4
-rw-r--r--chrome/browser/download/download_browsertest.cc6
-rw-r--r--chrome/browser/download/save_page_browsertest.cc9
-rw-r--r--chrome/browser/errorpage_browsertest.cc23
-rw-r--r--chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest_nss.cc4
-rw-r--r--chrome/browser/lifetime/browser_close_manager_browsertest.cc4
-rw-r--r--chrome/browser/net/dns_probe_browsertest.cc11
-rw-r--r--chrome/browser/net/url_request_mock_util.cc5
-rw-r--r--chrome/browser/plugins/npapi_infobar_browsertest.cc13
-rw-r--r--chrome/browser/policy/cloud/test_request_interceptor.cc10
-rw-r--r--chrome/browser/policy/policy_browsertest.cc25
-rw-r--r--chrome/browser/prerender/prerender_browsertest.cc24
-rw-r--r--chrome/browser/prerender/prerender_tracker_unittest.cc8
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc2
-rw-r--r--chrome/browser/unload_browsertest.cc6
-rw-r--r--content/browser/database_browsertest.cc1
-rw-r--r--content/browser/download/download_browsertest.cc30
-rw-r--r--content/browser/download/drag_download_file_browsertest.cc19
-rw-r--r--content/browser/download/save_package_unittest.cc17
-rw-r--r--content/browser/loader/resource_dispatcher_host_browsertest.cc13
-rw-r--r--content/browser/plugin_browsertest.cc23
-rw-r--r--content/content_tests.gypi2
-rw-r--r--content/test/net/url_request_mock_http_job.h75
-rw-r--r--net/net.gyp2
-rw-r--r--net/test/url_request/url_request_mock_http_job.cc (renamed from content/test/net/url_request_mock_http_job.cc)128
-rw-r--r--net/test/url_request/url_request_mock_http_job.h92
29 files changed, 351 insertions, 244 deletions
diff --git a/chrome/browser/browser_encoding_browsertest.cc b/chrome/browser/browser_encoding_browsertest.cc
index 2c1e6d2..2df4850 100644
--- a/chrome/browser/browser_encoding_browsertest.cc
+++ b/chrome/browser/browser_encoding_browsertest.cc
@@ -23,7 +23,7 @@
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_navigation_observer.h"
-#include "content/test/net/url_request_mock_http_job.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
namespace {
@@ -164,7 +164,7 @@ IN_PROC_BROWSER_TEST_P(BrowserEncodingTest, TestEncodingAliasMapping) {
test_file_path = test_file_path.AppendASCII(
GetParam().file_name);
- GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_file_path);
+ GURL url = net::URLRequestMockHTTPJob::GetMockUrl(test_file_path);
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ(GetParam().encoding_name,
browser()->tab_strip_model()->GetActiveWebContents()->
@@ -185,7 +185,7 @@ IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestOverrideEncoding) {
base::FilePath test_dir_path =
base::FilePath(kTestDir).AppendASCII(kOverrideTestDir);
test_dir_path = test_dir_path.AppendASCII(kTestFileName);
- GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_dir_path);
+ GURL url = net::URLRequestMockHTTPJob::GetMockUrl(test_dir_path);
ui_test_utils::NavigateToURL(browser(), url);
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
@@ -303,7 +303,7 @@ IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, MAYBE_TestEncodingAutoDetect) {
base::FilePath test_file_path(test_dir_path);
test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name);
- GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_file_path);
+ GURL url = net::URLRequestMockHTTPJob::GetMockUrl(test_file_path);
ui_test_utils::NavigateToURL(browser(), url);
// Get the encoding used for the page, it must be the default charset we
diff --git a/chrome/browser/browsing_data/browsing_data_remover_browsertest.cc b/chrome/browser/browsing_data/browsing_data_remover_browsertest.cc
index 5d1252f..57d7f75 100644
--- a/chrome/browser/browsing_data/browsing_data_remover_browsertest.cc
+++ b/chrome/browser/browsing_data/browsing_data_remover_browsertest.cc
@@ -22,14 +22,15 @@
#include "content/public/common/content_paths.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
-#include "content/test/net/url_request_mock_http_job.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
namespace {
void SetUrlRequestMock(const base::FilePath& path) {
- content::URLRequestMockHTTPJob::AddUrlHandler(path);
+ net::URLRequestMockHTTPJob::AddUrlHandler(path,
+ BrowserThread::GetBlockingPool());
}
}
@@ -116,7 +117,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) {
// Verify can modify database after deleting it.
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Database) {
- GURL url(content::URLRequestMockHTTPJob::GetMockUrl(
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(
base::FilePath().AppendASCII("simple_database.html")));
ui_test_utils::NavigateToURL(browser(), url);
diff --git a/chrome/browser/captive_portal/captive_portal_browsertest.cc b/chrome/browser/captive_portal/captive_portal_browsertest.cc
index 11deb82..473c229 100644
--- a/chrome/browser/captive_portal/captive_portal_browsertest.cc
+++ b/chrome/browser/captive_portal/captive_portal_browsertest.cc
@@ -42,9 +42,9 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/test/net/url_request_failed_job.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_errors.h"
#include "net/http/transport_security_state.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
@@ -56,8 +56,8 @@
using captive_portal::CaptivePortalResult;
using content::BrowserThread;
using content::URLRequestFailedJob;
-using content::URLRequestMockHTTPJob;
using content::WebContents;
+using net::URLRequestMockHTTPJob;
namespace {
@@ -427,7 +427,9 @@ net::URLRequestJob* URLRequestMockCaptivePortalJobFactory::Factory(
return new URLRequestMockHTTPJob(
request,
network_delegate,
- root_http.Append(FILE_PATH_LITERAL("title2.html")));
+ root_http.Append(FILE_PATH_LITERAL("title2.html")),
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
} else if (request->url() == GURL(kMockHttpsQuickTimeoutUrl)) {
if (behind_captive_portal_)
return new URLRequestFailedJob(
@@ -437,7 +439,9 @@ net::URLRequestJob* URLRequestMockCaptivePortalJobFactory::Factory(
return new URLRequestMockHTTPJob(
request,
network_delegate,
- root_http.Append(FILE_PATH_LITERAL("title2.html")));
+ root_http.Append(FILE_PATH_LITERAL("title2.html")),
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
} else {
// The URL should be the captive portal test URL.
EXPECT_TRUE(GURL(kMockCaptivePortalTestUrl) == request->url() ||
@@ -450,19 +454,25 @@ net::URLRequestJob* URLRequestMockCaptivePortalJobFactory::Factory(
return new URLRequestMockHTTPJob(
request,
network_delegate,
- root_http.Append(FILE_PATH_LITERAL("captive_portal/page511.html")));
+ root_http.Append(FILE_PATH_LITERAL("captive_portal/page511.html")),
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
}
return new URLRequestMockHTTPJob(
request,
network_delegate,
- root_http.Append(FILE_PATH_LITERAL("captive_portal/login.html")));
+ root_http.Append(FILE_PATH_LITERAL("captive_portal/login.html")),
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
}
// After logging in to the portal, the test URLs return a 204 response.
return new URLRequestMockHTTPJob(
request,
network_delegate,
- root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html")));
+ root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html")),
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
}
}
diff --git a/chrome/browser/content_settings/content_settings_browsertest.cc b/chrome/browser/content_settings/content_settings_browsertest.cc
index 91e0c66..3ec5e39 100644
--- a/chrome/browser/content_settings/content_settings_browsertest.cc
+++ b/chrome/browser/content_settings/content_settings_browsertest.cc
@@ -32,8 +32,8 @@
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
@@ -42,7 +42,7 @@
#endif
using content::BrowserThread;
-using content::URLRequestMockHTTPJob;
+using net::URLRequestMockHTTPJob;
class ContentSettingsTest : public InProcessBrowserTest {
public:
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index c5b4001..8f986f8 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -86,12 +86,12 @@
#include "content/public/test/download_test_observer.h"
#include "content/public/test/test_file_error_injector.h"
#include "content/public/test/test_navigation_observer.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "content/test/net/url_request_slow_download_job.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/feature_switch.h"
#include "net/base/filename_util.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
@@ -100,11 +100,11 @@ using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
using content::DownloadUrlParameters;
-using content::URLRequestMockHTTPJob;
using content::URLRequestSlowDownloadJob;
using content::WebContents;
using extensions::Extension;
using extensions::FeatureSwitch;
+using net::URLRequestMockHTTPJob;
namespace {
@@ -3346,7 +3346,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_GZipWithNoContent) {
IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) {
// Make a dangerous file.
base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf"));
- GURL download_url(content::URLRequestMockHTTPJob::GetMockUrl(file));
+ GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl(file));
scoped_ptr<content::DownloadTestObserverInterrupted> observer(
new content::DownloadTestObserverInterrupted(
DownloadManagerForBrowser(browser()), 1,
diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc
index ecaa125..ca000a4 100644
--- a/chrome/browser/download/save_page_browsertest.cc
+++ b/chrome/browser/download/save_page_browsertest.cc
@@ -37,16 +37,17 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/url_constants.h"
#include "content/public/test/test_utils.h"
-#include "content/test/net/url_request_mock_http_job.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
-using content::URLRequestMockHTTPJob;
using content::WebContents;
+using net::URLRequestMockHTTPJob;
namespace {
@@ -499,8 +500,10 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveHTMLOnlyTabDestroy) {
#endif
IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) {
base::FilePath file_name(FILE_PATH_LITERAL("a.htm"));
- GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
+ GURL mock_url = URLRequestMockHTTPJob::GetMockUrl(
base::FilePath(kTestDir).Append(file_name));
+ GURL view_source_url =
+ GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec());
GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
base::FilePath(kTestDir).Append(file_name));
ui_test_utils::NavigateToURL(browser(), view_source_url);
diff --git a/chrome/browser/errorpage_browsertest.cc b/chrome/browser/errorpage_browsertest.cc
index cb1a181..52d63af 100644
--- a/chrome/browser/errorpage_browsertest.cc
+++ b/chrome/browser/errorpage_browsertest.cc
@@ -38,12 +38,12 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/test/net/url_request_failed_job.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/http/failing_http_transaction_factory.h"
#include "net/http/http_cache.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_filter.h"
@@ -215,9 +215,12 @@ class LinkDoctorInterceptor : public net::URLRequestInterceptor {
base::FilePath root_http;
PathService::Get(chrome::DIR_TEST_DATA, &root_http);
- return new content::URLRequestMockHTTPJob(
- request, network_delegate,
- root_http.AppendASCII("mock-link-doctor.json"));
+ return new net::URLRequestMockHTTPJob(
+ request,
+ network_delegate,
+ root_http.AppendASCII("mock-link-doctor.json"),
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
}
void WaitForRequests(int requests_to_wait_for) {
@@ -276,8 +279,10 @@ void InstallMockInterceptors(
// Add a mock for the search engine the error page will use.
base::FilePath root_http;
PathService::Get(chrome::DIR_TEST_DATA, &root_http);
- content::URLRequestMockHTTPJob::AddHostnameToFileHandler(
- search_url.host(), root_http.AppendASCII("title3.html"));
+ net::URLRequestMockHTTPJob::AddHostnameToFileHandler(
+ search_url.host(),
+ root_http.AppendASCII("title3.html"),
+ BrowserThread::GetBlockingPool());
}
class ErrorPageTest : public InProcessBrowserTest {
@@ -300,7 +305,7 @@ class ErrorPageTest : public InProcessBrowserTest {
void NavigateToFileURL(const base::FilePath::StringType& file_path) {
ui_test_utils::NavigateToURL(
browser(),
- content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path)));
+ net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path)));
}
// Navigates to the given URL and waits for |num_navigations| to occur, and
@@ -700,7 +705,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoClickLink) {
// navigation corrections.
IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
NavigateToURLAndWaitForTitle(
- content::URLRequestMockHTTPJob::GetMockUrl(
+ net::URLRequestMockHTTPJob::GetMockUrl(
base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
"Blah",
1);
@@ -814,7 +819,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) {
// 404 page.
IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
NavigateToURLAndWaitForTitle(
- content::URLRequestMockHTTPJob::GetMockUrl(
+ net::URLRequestMockHTTPJob::GetMockUrl(
base::FilePath(FILE_PATH_LITERAL("page404.html"))),
"SUCCESS",
1);
diff --git a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest_nss.cc b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest_nss.cc
index 6e6c006..d7682c8 100644
--- a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest_nss.cc
+++ b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest_nss.cc
@@ -19,12 +19,12 @@
#include "content/public/browser/notification_service.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/test_utils.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "crypto/nss_util_internal.h"
#include "crypto/scoped_test_system_nss_key_slot.h"
#include "extensions/browser/notification_types.h"
#include "net/base/net_errors.h"
#include "net/cert/nss_cert_database.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "policy/policy_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -253,7 +253,7 @@ class EnterprisePlatformKeysTest : public ExtensionApiTest {
base::FilePath update_manifest_path =
base::FilePath(kTestExtensionDir).Append(kUpdateManifestFileName);
GURL update_manifest_url(
- content::URLRequestMockHTTPJob::GetMockUrl(update_manifest_path));
+ net::URLRequestMockHTTPJob::GetMockUrl(update_manifest_path));
scoped_ptr<base::ListValue> forcelist(new base::ListValue);
forcelist->AppendString(base::StringPrintf(
diff --git a/chrome/browser/lifetime/browser_close_manager_browsertest.cc b/chrome/browser/lifetime/browser_close_manager_browsertest.cc
index ef424b8..fd59e2f 100644
--- a/chrome/browser/lifetime/browser_close_manager_browsertest.cc
+++ b/chrome/browser/lifetime/browser_close_manager_browsertest.cc
@@ -39,9 +39,9 @@
#include "content/public/browser/web_contents.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/test_navigation_observer.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "content/test/net/url_request_slow_download_job.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#if defined(OS_CHROMEOS)
#include "chromeos/chromeos_switches.h"
@@ -747,7 +747,7 @@ IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
// This .swf normally would be categorized as DANGEROUS_FILE, but
// TestDownloadManagerDelegate turns it into DANGEROUS_URL.
base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf"));
- GURL download_url(content::URLRequestMockHTTPJob::GetMockUrl(file));
+ GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl(file));
content::DownloadTestObserverInterrupted observer(
content::BrowserContext::GetDownloadManager(browser()->profile()),
1,
diff --git a/chrome/browser/net/dns_probe_browsertest.cc b/chrome/browser/net/dns_probe_browsertest.cc
index 5658745..f1e9e02 100644
--- a/chrome/browser/net/dns_probe_browsertest.cc
+++ b/chrome/browser/net/dns_probe_browsertest.cc
@@ -31,9 +31,9 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/test/net/url_request_failed_job.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_errors.h"
#include "net/dns/dns_test_util.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request_filter.h"
#include "net/url_request/url_request_interceptor.h"
#include "net/url_request/url_request_job.h"
@@ -48,7 +48,7 @@ using base::Unretained;
using chrome_common_net::DnsProbeStatus;
using content::BrowserThread;
using content::URLRequestFailedJob;
-using content::URLRequestMockHTTPJob;
+using net::URLRequestMockHTTPJob;
using content::WebContents;
using google_util::LinkDoctorBaseURL;
using net::MockDnsClientRule;
@@ -181,7 +181,12 @@ class DelayableURLRequestMockHTTPJob : public URLRequestMockHTTPJob,
const base::FilePath& file_path,
bool should_delay,
const DestructionCallback& destruction_callback)
- : URLRequestMockHTTPJob(request, network_delegate, file_path),
+ : URLRequestMockHTTPJob(
+ request,
+ network_delegate,
+ file_path,
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
should_delay_(should_delay),
start_delayed_(false),
destruction_callback_(destruction_callback) {}
diff --git a/chrome/browser/net/url_request_mock_util.cc b/chrome/browser/net/url_request_mock_util.cc
index 6255c60..bbe90df 100644
--- a/chrome/browser/net/url_request_mock_util.cc
+++ b/chrome/browser/net/url_request_mock_util.cc
@@ -11,8 +11,8 @@
#include "chrome/common/chrome_paths.h"
#include "content/public/browser/browser_thread.h"
#include "content/test/net/url_request_failed_job.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "content/test/net/url_request_slow_download_job.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request_filter.h"
using content::BrowserThread;
@@ -37,7 +37,8 @@ void SetUrlRequestMocksEnabled(bool enabled) {
base::FilePath root_http;
PathService::Get(chrome::DIR_TEST_DATA, &root_http);
- content::URLRequestMockHTTPJob::AddUrlHandler(root_http);
+ net::URLRequestMockHTTPJob::AddUrlHandler(root_http,
+ BrowserThread::GetBlockingPool());
} else {
// Revert to the default handlers.
net::URLRequestFilter::GetInstance()->ClearHandlers();
diff --git a/chrome/browser/plugins/npapi_infobar_browsertest.cc b/chrome/browser/plugins/npapi_infobar_browsertest.cc
index a0dd6ab..4505c55c 100644
--- a/chrome/browser/plugins/npapi_infobar_browsertest.cc
+++ b/chrome/browser/plugins/npapi_infobar_browsertest.cc
@@ -5,6 +5,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
+#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h"
#include "base/path_service.h"
#include "chrome/browser/infobars/infobar_service.h"
@@ -20,12 +21,11 @@
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
-#include "content/test/net/url_request_mock_http_job.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "url/gurl.h"
using content::BrowserThread;
-using content::URLRequestMockHTTPJob;
-
+using net::URLRequestMockHTTPJob;
namespace {
@@ -45,8 +45,11 @@ class UnauthorizedPluginInfoBarBrowserTest : public InProcessBrowserTest {
scoped_refptr<content::MessageLoopRunner> runner =
new content::MessageLoopRunner;
BrowserThread::PostTaskAndReply(
- BrowserThread::IO, FROM_HERE,
- base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http),
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(URLRequestMockHTTPJob::AddUrlHandler,
+ root_http,
+ make_scoped_refptr(BrowserThread::GetBlockingPool())),
runner->QuitClosure());
runner->Run();
}
diff --git a/chrome/browser/policy/cloud/test_request_interceptor.cc b/chrome/browser/policy/cloud/test_request_interceptor.cc
index 32f3b7d..5c98bd24 100644
--- a/chrome/browser/policy/cloud/test_request_interceptor.cc
+++ b/chrome/browser/policy/cloud/test_request_interceptor.cc
@@ -12,11 +12,12 @@
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/sequenced_task_runner.h"
-#include "content/test/net/url_request_mock_http_job.h"
+#include "content/public/browser/browser_thread.h"
#include "net/base/net_errors.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_data_stream.h"
#include "net/base/upload_element_reader.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request_error_job.h"
#include "net/url_request/url_request_filter.h"
#include "net/url_request/url_request_interceptor.h"
@@ -52,10 +53,13 @@ net::URLRequestJob* BadRequestJobCallback(
net::URLRequestJob* FileJobCallback(const base::FilePath& file_path,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) {
- return new content::URLRequestMockHTTPJob(
+ return new net::URLRequestMockHTTPJob(
request,
network_delegate,
- file_path);
+ file_path,
+ content::BrowserThread::GetBlockingPool()
+ ->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
}
// Parses the upload data in |request| into |request_msg|, and validates the
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index b56da1d..aa51831 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -123,7 +123,6 @@
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/test/net/url_request_failed_job.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
@@ -135,6 +134,7 @@
#include "net/base/net_util.h"
#include "net/base/url_util.h"
#include "net/http/http_stream_factory.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_filter.h"
#include "policy/policy_constants.h"
@@ -169,7 +169,7 @@
#endif
using content::BrowserThread;
-using content::URLRequestMockHTTPJob;
+using net::URLRequestMockHTTPJob;
using testing::Mock;
using testing::Return;
using testing::_;
@@ -224,8 +224,9 @@ void RedirectHostsToTestData(const char* const urls[], size_t size) {
for (size_t i = 0; i < size; ++i) {
const GURL url(urls[i]);
EXPECT_TRUE(url.is_valid());
- filter->AddUrlInterceptor(
- url, URLRequestMockHTTPJob::CreateInterceptor(base_path));
+ filter->AddUrlInterceptor(url,
+ URLRequestMockHTTPJob::CreateInterceptor(
+ base_path, BrowserThread::GetBlockingPool()));
}
}
@@ -618,8 +619,11 @@ class PolicyTest : public InProcessBrowserTest {
base::FilePath root_http;
PathService::Get(content::DIR_TEST_DATA, &root_http);
BrowserThread::PostTaskAndReply(
- BrowserThread::IO, FROM_HERE,
- base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http),
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(URLRequestMockHTTPJob::AddUrlHandler,
+ root_http,
+ make_scoped_refptr(BrowserThread::GetBlockingPool())),
base::MessageLoop::current()->QuitWhenIdleClosure());
content::RunMessageLoop();
}
@@ -2686,9 +2690,14 @@ class RestoreOnStartupPolicyTest
command_line->InitFromArgv(argv);
ASSERT_TRUE(std::equal(argv.begin(), argv.end(),
command_line->argv().begin()));
+ }
- // Redirect the test URLs to the test data directory.
- RedirectHostsToTestData(kRestoredURLs, arraysize(kRestoredURLs));
+ virtual void SetUpOnMainThread() OVERRIDE {
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ RedirectHostsToTestData, kRestoredURLs, arraysize(kRestoredURLs)));
}
void HomepageIsNotNTP() {
diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc
index 0b0752b..4e53ad5 100644
--- a/chrome/browser/prerender/prerender_browsertest.cc
+++ b/chrome/browser/prerender/prerender_browsertest.cc
@@ -81,7 +81,6 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "extensions/common/switches.h"
#include "extensions/test/result_catcher.h"
#include "net/base/escape.h"
@@ -89,6 +88,7 @@
#include "net/dns/mock_host_resolver.h"
#include "net/ssl/client_cert_store.h"
#include "net/ssl/ssl_cert_request_info.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_filter.h"
@@ -798,7 +798,12 @@ class HangingFirstRequestInterceptor : public net::URLRequestInterceptor {
}
return new HangingURLRequestJob(request, network_delegate);
}
- return new content::URLRequestMockHTTPJob(request, network_delegate, file_);
+ return new net::URLRequestMockHTTPJob(
+ request,
+ network_delegate,
+ file_,
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
}
private:
@@ -820,13 +825,17 @@ void CreateHangingFirstRequestInterceptorOnIO(
}
// Wrapper over URLRequestMockHTTPJob that exposes extra callbacks.
-class MockHTTPJob : public content::URLRequestMockHTTPJob {
+class MockHTTPJob : public net::URLRequestMockHTTPJob {
public:
MockHTTPJob(net::URLRequest* request,
net::NetworkDelegate* delegate,
const base::FilePath& file)
- : content::URLRequestMockHTTPJob(request, delegate, file) {
- }
+ : net::URLRequestMockHTTPJob(
+ request,
+ delegate,
+ file,
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {}
void set_start_callback(const base::Closure& start_callback) {
start_callback_ = start_callback;
@@ -835,7 +844,7 @@ class MockHTTPJob : public content::URLRequestMockHTTPJob {
virtual void Start() OVERRIDE {
if (!start_callback_.is_null())
start_callback_.Run();
- content::URLRequestMockHTTPJob::Start();
+ net::URLRequestMockHTTPJob::Start();
}
private:
@@ -925,7 +934,8 @@ void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
url,
- content::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(file));
+ net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(
+ file, BrowserThread::GetBlockingPool()));
}
// A ContentBrowserClient that cancels all prerenderers on OpenURL.
diff --git a/chrome/browser/prerender/prerender_tracker_unittest.cc b/chrome/browser/prerender/prerender_tracker_unittest.cc
index 2d20c45..5fc302b 100644
--- a/chrome/browser/prerender/prerender_tracker_unittest.cc
+++ b/chrome/browser/prerender/prerender_tracker_unittest.cc
@@ -19,9 +19,9 @@
#include "content/public/browser/resource_controller.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/test/test_browser_thread.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "ipc/ipc_message.h"
#include "net/base/request_priority.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_test_util.h"
@@ -225,7 +225,7 @@ TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectResume) {
net::TestURLRequestContext url_request_context;
DeferredRedirectDelegate delegate;
scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest(
- content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
+ net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
net::DEFAULT_PRIORITY,
&delegate,
NULL));
@@ -268,7 +268,7 @@ TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectMainFrame) {
net::TestURLRequestContext url_request_context;
DeferredRedirectDelegate delegate;
scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest(
- content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
+ net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
net::DEFAULT_PRIORITY,
&delegate,
NULL));
@@ -310,7 +310,7 @@ TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectSyncXHR) {
net::TestURLRequestContext url_request_context;
DeferredRedirectDelegate delegate;
scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest(
- content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
+ net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
net::DEFAULT_PRIORITY,
&delegate,
NULL));
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc
index f682312a..2d0d0a6 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -36,9 +36,9 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "extensions/common/constants.h"
#include "net/base/net_util.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/hit_test.h"
#include "ui/events/event_utils.h"
diff --git a/chrome/browser/unload_browsertest.cc b/chrome/browser/unload_browsertest.cc
index 5f8526d0..9b4add4 100644
--- a/chrome/browser/unload_browsertest.cc
+++ b/chrome/browser/unload_browsertest.cc
@@ -24,7 +24,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
-#include "content/test/net/url_request_mock_http_job.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request_test_util.h"
#if defined(OS_WIN)
@@ -146,7 +146,7 @@ class UnloadTest : public InProcessBrowserTest {
}
void NavigateToNolistenersFileTwice() {
- GURL url(content::URLRequestMockHTTPJob::GetMockUrl(
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(
base::FilePath(FILE_PATH_LITERAL("title2.html"))));
ui_test_utils::NavigateToURL(browser(), url);
CheckTitle("Title Of Awesomeness");
@@ -158,7 +158,7 @@ class UnloadTest : public InProcessBrowserTest {
// load is purposely async to test the case where the user loads another
// page without waiting for the first load to complete.
void NavigateToNolistenersFileTwiceAsync() {
- GURL url(content::URLRequestMockHTTPJob::GetMockUrl(
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(
base::FilePath(FILE_PATH_LITERAL("title2.html"))));
ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, 0);
ui_test_utils::NavigateToURL(browser(), url);
diff --git a/content/browser/database_browsertest.cc b/content/browser/database_browsertest.cc
index d3cc669..e38e417 100644
--- a/content/browser/database_browsertest.cc
+++ b/content/browser/database_browsertest.cc
@@ -14,7 +14,6 @@
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
diff --git a/content/browser/download/download_browsertest.cc b/content/browser/download/download_browsertest.cc
index eeacac1..bfcd746 100644
--- a/content/browser/download/download_browsertest.cc
+++ b/content/browser/download/download_browsertest.cc
@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
+#include "base/memory/ref_counted.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/platform_thread.h"
@@ -33,12 +34,12 @@
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
#include "content/shell/browser/shell_network_delegate.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "content/test/net/url_request_slow_download_job.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -588,8 +589,12 @@ class DownloadContentTest : public ContentBrowserTest {
base::Bind(&URLRequestSlowDownloadJob::AddUrlHandler));
base::FilePath mock_base(GetTestFilePath("download", ""));
BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, mock_base));
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ &net::URLRequestMockHTTPJob::AddUrlHandler,
+ mock_base,
+ make_scoped_refptr(content::BrowserThread::GetBlockingPool())));
}
TestShellDownloadManagerDelegate* GetDownloadManagerDelegate() {
@@ -801,7 +806,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, MultiDownload) {
// Start the second download and wait until it's done.
base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
- GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(file));
// Download the file and wait.
NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE);
@@ -856,7 +861,8 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadOctetStream) {
PluginServiceImpl::GetInstance()->RegisterInternalPlugin(plugin_info, false);
// The following is served with a Content-Type of application/octet-stream.
- GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kTestFilePath)));
+ GURL url(
+ net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kTestFilePath)));
NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE);
}
#endif
@@ -873,7 +879,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) {
// Create a download
base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
- NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file));
+ NavigateToURL(shell(), net::URLRequestMockHTTPJob::GetMockUrl(file));
// Wait until the first (intermediate file) rename and execute the callback.
file_factory->WaitForSomeCallback();
@@ -922,7 +928,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtRelease) {
// Create a download
base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
- NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file));
+ NavigateToURL(shell(), net::URLRequestMockHTTPJob::GetMockUrl(file));
// Wait until the first (intermediate file) rename and execute the callback.
file_factory->WaitForSomeCallback();
@@ -1032,7 +1038,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ShutdownAtRelease) {
// Create a download
base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
- NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file));
+ NavigateToURL(shell(), net::URLRequestMockHTTPJob::GetMockUrl(file));
// Wait until the first (intermediate file) rename and execute the callback.
file_factory->WaitForSomeCallback();
@@ -1339,7 +1345,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileInitError) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableDownloadResumption);
base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
- GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(file));
// Setup the error injector.
scoped_refptr<TestFileErrorInjector> injector(
@@ -1390,7 +1396,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest,
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableDownloadResumption);
base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
- GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(file));
// Setup the error injector.
scoped_refptr<TestFileErrorInjector> injector(
@@ -1442,7 +1448,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileFinalRenameError) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableDownloadResumption);
base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
- GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(file));
// Setup the error injector.
scoped_refptr<TestFileErrorInjector> injector(
@@ -1557,7 +1563,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveDownload) {
{
// Start the second download and wait until it's done.
base::FilePath file2(FILE_PATH_LITERAL("download-test.lib"));
- GURL url2(URLRequestMockHTTPJob::GetMockUrl(file2));
+ GURL url2(net::URLRequestMockHTTPJob::GetMockUrl(file2));
scoped_ptr<DownloadTestObserver> completion_observer(
CreateWaiter(shell(), 1));
DownloadItem* download(StartDownloadAndReturnItem(url2));
diff --git a/content/browser/download/drag_download_file_browsertest.cc b/content/browser/download/drag_download_file_browsertest.cc
index 136fac3..8508d8b 100644
--- a/content/browser/download/drag_download_file_browsertest.cc
+++ b/content/browser/download/drag_download_file_browsertest.cc
@@ -4,6 +4,7 @@
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
+#include "base/memory/ref_counted.h"
#include "content/browser/download/download_file_factory.h"
#include "content/browser/download/download_file_impl.h"
#include "content/browser/download/download_item_impl.h"
@@ -21,8 +22,8 @@
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "content/test/net/url_request_slow_download_job.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -73,8 +74,12 @@ class DragDownloadFileTest : public ContentBrowserTest {
void SetUpServer() {
base::FilePath mock_base(GetTestFilePath("download", ""));
BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, mock_base));
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ &net::URLRequestMockHTTPJob::AddUrlHandler,
+ mock_base,
+ make_scoped_refptr(content::BrowserThread::GetBlockingPool())));
}
const base::FilePath& downloads_directory() const {
@@ -90,8 +95,8 @@ class DragDownloadFileTest : public ContentBrowserTest {
IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_NetError) {
base::FilePath name(downloads_directory().AppendASCII(
"DragDownloadFileTest_NetError.txt"));
- GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(FILE_PATH_LITERAL(
- "download-test.lib"))));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(
+ base::FilePath(FILE_PATH_LITERAL("download-test.lib"))));
Referrer referrer;
std::string referrer_encoding;
scoped_refptr<DragDownloadFile> file(
@@ -110,8 +115,8 @@ IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_NetError) {
IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_Complete) {
base::FilePath name(downloads_directory().AppendASCII(
"DragDownloadFileTest_Complete.txt"));
- GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(FILE_PATH_LITERAL(
- "download-test.lib"))));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(
+ base::FilePath(FILE_PATH_LITERAL("download-test.lib"))));
Referrer referrer;
std::string referrer_encoding;
SetUpServer();
diff --git a/content/browser/download/save_package_unittest.cc b/content/browser/download/save_package_unittest.cc
index 123af98..9680954 100644
--- a/content/browser/download/save_package_unittest.cc
+++ b/content/browser/download/save_package_unittest.cc
@@ -10,9 +10,10 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/download/save_package.h"
-#include "content/test/net/url_request_mock_http_job.h"
+#include "content/public/common/url_constants.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -414,8 +415,8 @@ static const base::FilePath::CharType* kTestDir =
// GetUrlToBeSaved method should return correct url to be saved.
TEST_F(SavePackageTest, TestGetUrlToBeSaved) {
base::FilePath file_name(FILE_PATH_LITERAL("a.htm"));
- GURL url = URLRequestMockHTTPJob::GetMockUrl(
- base::FilePath(kTestDir).Append(file_name));
+ GURL url = net::URLRequestMockHTTPJob::GetMockUrl(
+ base::FilePath(kTestDir).Append(file_name));
NavigateAndCommit(url);
EXPECT_EQ(url, GetUrlToBeSaved());
}
@@ -426,10 +427,12 @@ TEST_F(SavePackageTest, TestGetUrlToBeSaved) {
// when user types view-source:http://www.google.com
TEST_F(SavePackageTest, TestGetUrlToBeSavedViewSource) {
base::FilePath file_name(FILE_PATH_LITERAL("a.htm"));
- GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
- base::FilePath(kTestDir).Append(file_name));
- GURL actual_url = URLRequestMockHTTPJob::GetMockUrl(
- base::FilePath(kTestDir).Append(file_name));
+ GURL mock_url = net::URLRequestMockHTTPJob::GetMockUrl(
+ base::FilePath(kTestDir).Append(file_name));
+ GURL view_source_url =
+ GURL(kViewSourceScheme + std::string(":") + mock_url.spec());
+ GURL actual_url = net::URLRequestMockHTTPJob::GetMockUrl(
+ base::FilePath(kTestDir).Append(file_name));
NavigateAndCommit(view_source_url);
EXPECT_EQ(actual_url, GetUrlToBeSaved());
EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL());
diff --git a/content/browser/loader/resource_dispatcher_host_browsertest.cc b/content/browser/loader/resource_dispatcher_host_browsertest.cc
index 0858bd6..94914b4 100644
--- a/content/browser/loader/resource_dispatcher_host_browsertest.cc
+++ b/content/browser/loader/resource_dispatcher_host_browsertest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/memory/ref_counted.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -19,11 +20,11 @@
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_network_delegate.h"
#include "content/test/net/url_request_failed_job.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_errors.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
using base::ASCIIToUTF16;
@@ -38,8 +39,12 @@ class ResourceDispatcherHostBrowserTest : public ContentBrowserTest,
virtual void SetUpOnMainThread() OVERRIDE {
base::FilePath path = GetTestFilePath("", "");
BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, path));
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ &net::URLRequestMockHTTPJob::AddUrlHandler,
+ path,
+ make_scoped_refptr(content::BrowserThread::GetBlockingPool())));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&URLRequestFailedJob::AddUrlHandler));
@@ -53,7 +58,7 @@ class ResourceDispatcherHostBrowserTest : public ContentBrowserTest,
}
GURL GetMockURL(const std::string& file) {
- return URLRequestMockHTTPJob::GetMockUrl(
+ return net::URLRequestMockHTTPJob::GetMockUrl(
base::FilePath().AppendASCII(file));
}
diff --git a/content/browser/plugin_browsertest.cc b/content/browser/plugin_browsertest.cc
index 798f6c0..f6a1f77 100644
--- a/content/browser/plugin_browsertest.cc
+++ b/content/browser/plugin_browsertest.cc
@@ -17,8 +17,8 @@
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/shell/common/shell_switches.h"
-#include "content/test/net/url_request_mock_http_job.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request.h"
#include "ui/gfx/rect.h"
@@ -39,7 +39,8 @@ namespace content {
namespace {
void SetUrlRequestMock(const base::FilePath& path) {
- URLRequestMockHTTPJob::AddUrlHandler(path);
+ net::URLRequestMockHTTPJob::AddUrlHandler(
+ path, content::BrowserThread::GetBlockingPool());
}
}
@@ -186,9 +187,9 @@ IN_PROC_BROWSER_TEST_F(PluginTest,
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE_GetURLRequest404Response) {
- GURL url(URLRequestMockHTTPJob::GetMockUrl(
- base::FilePath().AppendASCII("npapi").
- AppendASCII("plugin_url_request_404.html")));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(
+ base::FilePath().AppendASCII("npapi").AppendASCII(
+ "plugin_url_request_404.html")));
LoadAndWait(url);
}
@@ -377,9 +378,9 @@ IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(MultipleInstancesSyncCalls)) {
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(GetURLRequestFailWrite)) {
- GURL url(URLRequestMockHTTPJob::GetMockUrl(
- base::FilePath().AppendASCII("npapi").
- AppendASCII("plugin_url_request_fail_write.html")));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(
+ base::FilePath().AppendASCII("npapi").AppendASCII(
+ "plugin_url_request_fail_write.html")));
LoadAndWait(url);
}
#endif
@@ -402,9 +403,9 @@ IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(NoHangIfInitCrashes)) {
// If this flakes on Mac, use http://crbug.com/111508
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(PluginReferrerTest)) {
- GURL url(URLRequestMockHTTPJob::GetMockUrl(
- base::FilePath().AppendASCII("npapi").
- AppendASCII("plugin_url_request_referrer_test.html")));
+ GURL url(net::URLRequestMockHTTPJob::GetMockUrl(
+ base::FilePath().AppendASCII("npapi").AppendASCII(
+ "plugin_url_request_referrer_test.html")));
LoadAndWait(url);
}
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index 71c712b..c85f8ab 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -128,8 +128,6 @@
'test/net/url_request_abort_on_end_job.h',
'test/net/url_request_failed_job.cc',
'test/net/url_request_failed_job.h',
- 'test/net/url_request_mock_http_job.cc',
- 'test/net/url_request_mock_http_job.h',
'test/net/url_request_slow_download_job.cc',
'test/net/url_request_slow_download_job.h',
'test/ppapi_unittest.cc',
diff --git a/content/test/net/url_request_mock_http_job.h b/content/test/net/url_request_mock_http_job.h
deleted file mode 100644
index b6d13d8..0000000
--- a/content/test/net/url_request_mock_http_job.h
+++ /dev/null
@@ -1,75 +0,0 @@
-// 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.
-//
-// A net::URLRequestJob class that pulls the content and http headers from disk.
-
-#ifndef CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_
-#define CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_
-
-#include <string>
-
-#include "net/url_request/url_request_file_job.h"
-
-namespace base {
-class FilePath;
-}
-
-namespace net {
-class URLRequestInterceptor;
-}
-
-namespace content {
-
-class URLRequestMockHTTPJob : public net::URLRequestFileJob {
- public:
- URLRequestMockHTTPJob(net::URLRequest* request,
- net::NetworkDelegate* network_delegate,
- const base::FilePath& file_path);
-
- virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
- virtual int GetResponseCode() const OVERRIDE;
- virtual bool GetCharset(std::string* charset) OVERRIDE;
- virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE;
- virtual bool IsRedirectResponse(GURL* location,
- int* http_status_code) OVERRIDE;
-
- // Adds the testing URLs to the net::URLRequestFilter.
- static void AddUrlHandler(const base::FilePath& base_path);
-
- // Respond to all HTTP requests of |hostname| with contents of the file
- // located at |file_path|.
- static void AddHostnameToFileHandler(const std::string& hostname,
- const base::FilePath& file);
-
- // Given the path to a file relative to the path passed to AddUrlHandler(),
- // construct a mock URL.
- static GURL GetMockUrl(const base::FilePath& path);
-
- // Given the path to a file relative to the path passed to AddUrlHandler(),
- // construct a mock URL for view source.
- static GURL GetMockViewSourceUrl(const base::FilePath& path);
-
- // Returns a net::URLRequestJobFactory::ProtocolHandler that serves
- // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the
- // file path leading to the root of the directory to use as the root of the
- // HTTP server.
- static scoped_ptr<net::URLRequestInterceptor>
- CreateInterceptor(const base::FilePath& base_path);
-
- // Returns a net::URLRequestJobFactory::ProtocolHandler that serves
- // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all
- // requests with the contents of |file|.
- static scoped_ptr<net::URLRequestInterceptor>
- CreateInterceptorForSingleFile(const base::FilePath& file);
-
- protected:
- virtual ~URLRequestMockHTTPJob();
-
- private:
- void GetResponseInfoConst(net::HttpResponseInfo* info) const;
-};
-
-} // namespace content
-
-#endif // CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_
diff --git a/net/net.gyp b/net/net.gyp
index 4a1cfea..ead68e3 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -964,6 +964,8 @@
'test/spawned_test_server/spawned_test_server.h',
'test/spawned_test_server/spawner_communicator.cc',
'test/spawned_test_server/spawner_communicator.h',
+ 'test/url_request/url_request_mock_http_job.cc',
+ 'test/url_request/url_request_mock_http_job.h',
'url_request/test_url_fetcher_factory.cc',
'url_request/test_url_fetcher_factory.h',
'url_request/test_url_request_interceptor.cc',
diff --git a/content/test/net/url_request_mock_http_job.cc b/net/test/url_request/url_request_mock_http_job.cc
index 50fb1c8..afe8e49 100644
--- a/content/test/net/url_request_mock_http_job.cc
+++ b/net/test/url_request/url_request_mock_http_job.cc
@@ -2,16 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/test/net/url_request_mock_http_job.h"
+#include "net/test/url_request/url_request_mock_http_job.h"
-#include "base/files/file_util.h"
+#include "base/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/task_runner_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/thread_restrictions.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/common/url_constants.h"
#include "net/base/filename_util.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request_filter.h"
@@ -21,7 +20,7 @@ const char kMockHostname[] = "mock.http";
const base::FilePath::CharType kMockHeaderFileSuffix[] =
FILE_PATH_LITERAL(".mock-http-headers");
-namespace content {
+namespace net {
namespace {
@@ -31,18 +30,25 @@ class MockJobInterceptor : public net::URLRequestInterceptor {
// contents of the file at |base_path|. When |map_all_requests_to_base_path|
// is false, |base_path| is the file path leading to the root of the directory
// to use as the root of the HTTP server.
- MockJobInterceptor(const base::FilePath& base_path,
- bool map_all_requests_to_base_path)
+ MockJobInterceptor(
+ const base::FilePath& base_path,
+ bool map_all_requests_to_base_path,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool)
: base_path_(base_path),
- map_all_requests_to_base_path_(map_all_requests_to_base_path) {}
+ map_all_requests_to_base_path_(map_all_requests_to_base_path),
+ worker_pool_(worker_pool) {}
virtual ~MockJobInterceptor() {}
// net::URLRequestJobFactory::ProtocolHandler implementation
virtual net::URLRequestJob* MaybeInterceptRequest(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
- return new URLRequestMockHTTPJob(request, network_delegate,
- map_all_requests_to_base_path_ ? base_path_ : GetOnDiskPath(request));
+ return new URLRequestMockHTTPJob(
+ request,
+ network_delegate,
+ map_all_requests_to_base_path_ ? base_path_ : GetOnDiskPath(request),
+ worker_pool_->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
}
private:
@@ -60,27 +66,45 @@ class MockJobInterceptor : public net::URLRequestInterceptor {
const base::FilePath base_path_;
const bool map_all_requests_to_base_path_;
+ const scoped_refptr<base::SequencedWorkerPool> worker_pool_;
DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor);
};
+std::string DoFileIO(const base::FilePath& file_path) {
+ base::FilePath header_file =
+ base::FilePath(file_path.value() + kMockHeaderFileSuffix);
+
+ if (!base::PathExists(header_file)) {
+ // If there is no mock-http-headers file, fake a 200 OK.
+ return "HTTP/1.0 200 OK\n";
+ }
+
+ std::string raw_headers;
+ base::ReadFileToString(header_file, &raw_headers);
+ return raw_headers;
+}
+
} // namespace
// static
-void URLRequestMockHTTPJob::AddUrlHandler(const base::FilePath& base_path) {
+void URLRequestMockHTTPJob::AddUrlHandler(
+ const base::FilePath& base_path,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) {
// Add kMockHostname to net::URLRequestFilter.
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
filter->AddHostnameInterceptor(
- "http", kMockHostname, CreateInterceptor(base_path));
+ "http", kMockHostname, CreateInterceptor(base_path, worker_pool));
}
// static
void URLRequestMockHTTPJob::AddHostnameToFileHandler(
const std::string& hostname,
- const base::FilePath& file) {
+ const base::FilePath& file,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) {
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
filter->AddHostnameInterceptor(
- "http", hostname, CreateInterceptorForSingleFile(file));
+ "http", hostname, CreateInterceptorForSingleFile(file, worker_pool));
}
// static
@@ -95,38 +119,34 @@ GURL URLRequestMockHTTPJob::GetMockUrl(const base::FilePath& path) {
}
// static
-GURL URLRequestMockHTTPJob::GetMockViewSourceUrl(const base::FilePath& path) {
- std::string url = kViewSourceScheme;
- url.append(":");
- url.append(GetMockUrl(path).spec());
- return GURL(url);
-}
-
-// static
-scoped_ptr<net::URLRequestInterceptor>
-URLRequestMockHTTPJob::CreateInterceptor(const base::FilePath& base_path) {
+scoped_ptr<net::URLRequestInterceptor> URLRequestMockHTTPJob::CreateInterceptor(
+ const base::FilePath& base_path,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) {
return scoped_ptr<net::URLRequestInterceptor>(
- new MockJobInterceptor(base_path, false));
+ new MockJobInterceptor(base_path, false, worker_pool));
}
// static
scoped_ptr<net::URLRequestInterceptor>
URLRequestMockHTTPJob::CreateInterceptorForSingleFile(
- const base::FilePath& file) {
+ const base::FilePath& file,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) {
return scoped_ptr<net::URLRequestInterceptor>(
- new MockJobInterceptor(file, true));
+ new MockJobInterceptor(file, true, worker_pool));
}
URLRequestMockHTTPJob::URLRequestMockHTTPJob(
- net::URLRequest* request, net::NetworkDelegate* network_delegate,
- const base::FilePath& file_path)
- : net::URLRequestFileJob(
- request, network_delegate, file_path,
- content::BrowserThread::GetBlockingPool()->
- GetTaskRunnerWithShutdownBehavior(
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {}
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate,
+ const base::FilePath& file_path,
+ const scoped_refptr<base::TaskRunner>& task_runner)
+ : net::URLRequestFileJob(request, network_delegate, file_path, task_runner),
+ task_runner_(task_runner),
+ weak_ptr_factory_(this) {
+}
-URLRequestMockHTTPJob::~URLRequestMockHTTPJob() { }
+URLRequestMockHTTPJob::~URLRequestMockHTTPJob() {
+}
// Public virtual version.
void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) {
@@ -141,29 +161,29 @@ bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location,
return net::URLRequestJob::IsRedirectResponse(location, http_status_code);
}
-// Private const version.
-void URLRequestMockHTTPJob::GetResponseInfoConst(
- net::HttpResponseInfo* info) const {
- // We have to load our headers from disk, but we only use this class
- // from tests, so allow these IO operations to happen on any thread.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
-
- base::FilePath header_file =
- base::FilePath(file_path_.value() + kMockHeaderFileSuffix);
- std::string raw_headers;
- if (!base::PathExists(header_file)) {
- // If there is no mock-http-headers file, fake a 200 OK.
- raw_headers = "HTTP/1.0 200 OK\n";
- } else {
- if (!base::ReadFileToString(header_file, &raw_headers))
- return;
- }
+// Public virtual version.
+void URLRequestMockHTTPJob::Start() {
+ base::PostTaskAndReplyWithResult(
+ task_runner_.get(),
+ FROM_HERE,
+ base::Bind(&DoFileIO, file_path_),
+ base::Bind(&URLRequestMockHTTPJob::GetRawHeaders,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+void URLRequestMockHTTPJob::GetRawHeaders(std::string raw_headers) {
// Handle CRLF line-endings.
ReplaceSubstringsAfterOffset(&raw_headers, 0, "\r\n", "\n");
// ParseRawHeaders expects \0 to end each header line.
ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1));
- info->headers = new net::HttpResponseHeaders(raw_headers);
+ raw_headers_ = raw_headers;
+ URLRequestFileJob::Start();
+}
+
+// Private const version.
+void URLRequestMockHTTPJob::GetResponseInfoConst(
+ net::HttpResponseInfo* info) const {
+ info->headers = new net::HttpResponseHeaders(raw_headers_);
}
bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const {
@@ -187,4 +207,4 @@ bool URLRequestMockHTTPJob::GetCharset(std::string* charset) {
return info.headers.get() && info.headers->GetCharset(charset);
}
-} // namespace content
+} // namespace net
diff --git a/net/test/url_request/url_request_mock_http_job.h b/net/test/url_request/url_request_mock_http_job.h
new file mode 100644
index 0000000..cb93412
--- /dev/null
+++ b/net/test/url_request/url_request_mock_http_job.h
@@ -0,0 +1,92 @@
+// 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.
+//
+// A URLRequestJob class that pulls the net and http headers from disk.
+
+#ifndef NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_
+#define NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_
+
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/url_request/url_request_file_job.h"
+#include "url/gurl.h"
+
+namespace base {
+class FilePath;
+class SequencedWorkerPool;
+}
+
+namespace net {
+class URLRequestInterceptor;
+}
+
+namespace net {
+
+class URLRequestMockHTTPJob : public URLRequestFileJob {
+ public:
+ // Note that all file IO is done using |worker_pool|.
+ URLRequestMockHTTPJob(URLRequest* request,
+ NetworkDelegate* network_delegate,
+ const base::FilePath& file_path,
+ const scoped_refptr<base::TaskRunner>& task_runner);
+
+ virtual void Start() OVERRIDE;
+ virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
+ virtual int GetResponseCode() const OVERRIDE;
+ virtual bool GetCharset(std::string* charset) OVERRIDE;
+ virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE;
+ virtual bool IsRedirectResponse(GURL* location,
+ int* http_status_code) OVERRIDE;
+
+ // Adds the testing URLs to the URLRequestFilter.
+ static void AddUrlHandler(
+ const base::FilePath& base_path,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
+
+ // Respond to all HTTP requests of |hostname| with contents of the file
+ // located at |file_path|.
+ static void AddHostnameToFileHandler(
+ const std::string& hostname,
+ const base::FilePath& file,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
+
+ // Given the path to a file relative to the path passed to AddUrlHandler(),
+ // construct a mock URL.
+ static GURL GetMockUrl(const base::FilePath& path);
+
+ // Returns a URLRequestJobFactory::ProtocolHandler that serves
+ // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the
+ // file path leading to the root of the directory to use as the root of the
+ // HTTP server.
+ static scoped_ptr<URLRequestInterceptor> CreateInterceptor(
+ const base::FilePath& base_path,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
+
+ // Returns a URLRequestJobFactory::ProtocolHandler that serves
+ // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all
+ // requests with the contents of |file|.
+ static scoped_ptr<URLRequestInterceptor> CreateInterceptorForSingleFile(
+ const base::FilePath& file,
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
+
+ protected:
+ virtual ~URLRequestMockHTTPJob();
+
+ private:
+ void GetResponseInfoConst(HttpResponseInfo* info) const;
+ void GetRawHeaders(std::string raw_headers);
+ std::string raw_headers_;
+ const scoped_refptr<base::TaskRunner> task_runner_;
+
+ base::WeakPtrFactory<URLRequestMockHTTPJob> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(URLRequestMockHTTPJob);
+};
+
+} // namespace net
+
+#endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_