diff options
Diffstat (limited to 'chrome/browser/net')
-rw-r--r-- | chrome/browser/net/url_request_mock_link_doctor_job.cc | 40 | ||||
-rw-r--r-- | chrome/browser/net/url_request_mock_link_doctor_job.h | 23 | ||||
-rw-r--r-- | chrome/browser/net/url_request_mock_util.cc | 2 |
3 files changed, 65 insertions, 0 deletions
diff --git a/chrome/browser/net/url_request_mock_link_doctor_job.cc b/chrome/browser/net/url_request_mock_link_doctor_job.cc new file mode 100644 index 0000000..88ef438 --- /dev/null +++ b/chrome/browser/net/url_request_mock_link_doctor_job.cc @@ -0,0 +1,40 @@ +// Copyright (c) 2009 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 "chrome/browser/net/url_request_mock_link_doctor_job.h" + +#include "base/path_service.h" +#include "chrome/browser/google_util.h" +#include "chrome/common/chrome_paths.h" +#include "googleurl/src/gurl.h" +#include "net/url_request/url_request_filter.h" + +namespace { + +FilePath GetMockFilePath() { + FilePath test_dir; + bool success = PathService::Get(chrome::DIR_TEST_DATA, &test_dir); + DCHECK(success); + return test_dir.AppendASCII("mock-link-doctor.html"); +} + +} // namespace + +/* static */ +URLRequestJob* URLRequestMockLinkDoctorJob::Factory(URLRequest* request, + const std::string& scheme) { + return new URLRequestMockLinkDoctorJob(request); +} + +/* static */ +void URLRequestMockLinkDoctorJob::AddUrlHandler() { + URLRequestFilter* filter = URLRequestFilter::GetInstance(); + filter->AddHostnameHandler("http", + GURL(google_util::kLinkDoctorBaseURL).host(), + URLRequestMockLinkDoctorJob::Factory); +} + +URLRequestMockLinkDoctorJob::URLRequestMockLinkDoctorJob(URLRequest* request) + : URLRequestMockHTTPJob(request, GetMockFilePath()) { +} diff --git a/chrome/browser/net/url_request_mock_link_doctor_job.h b/chrome/browser/net/url_request_mock_link_doctor_job.h new file mode 100644 index 0000000..74fd00e --- /dev/null +++ b/chrome/browser/net/url_request_mock_link_doctor_job.h @@ -0,0 +1,23 @@ +// Copyright (c) 2009 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 substitutes LinkDoctor requests. + +#ifndef CHROME_BROWSER_NET_URL_REQUEST_MOCK_LINK_DOCTOR_JOB_H_ +#define CHROME_BROWSER_NET_URL_REQUEST_MOCK_LINK_DOCTOR_JOB_H_ + +#include "chrome/browser/net/url_request_mock_http_job.h" + +class URLRequestMockLinkDoctorJob : public URLRequestMockHTTPJob { + public: + URLRequestMockLinkDoctorJob(URLRequest* request); + virtual ~URLRequestMockLinkDoctorJob() { } + + static URLRequest::ProtocolFactory Factory; + + // Adds the testing URLs to the URLRequestFilter. + static void AddUrlHandler(); +}; + +# endif // CHROME_BROWSER_NET_URL_REQUEST_MOCK_LINK_DOCTOR_JOB_H_ diff --git a/chrome/browser/net/url_request_mock_util.cc b/chrome/browser/net/url_request_mock_util.cc index 9a559b1..680ed1d 100644 --- a/chrome/browser/net/url_request_mock_util.cc +++ b/chrome/browser/net/url_request_mock_util.cc @@ -10,6 +10,7 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/browser/net/url_request_failed_dns_job.h" #include "chrome/browser/net/url_request_mock_http_job.h" +#include "chrome/browser/net/url_request_mock_link_doctor_job.h" #include "chrome/browser/net/url_request_slow_download_job.h" #include "chrome/browser/net/url_request_slow_http_job.h" #include "chrome/common/chrome_paths.h" @@ -26,6 +27,7 @@ void SetUrlRequestMocksEnabled(bool enabled) { URLRequestFilter::GetInstance()->ClearHandlers(); URLRequestFailedDnsJob::AddUrlHandler(); + URLRequestMockLinkDoctorJob::AddUrlHandler(); URLRequestSlowDownloadJob::AddUrlHandler(); std::wstring root_http; |