summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/url_request_mock_util.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-30 15:48:53 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-30 15:48:53 +0000
commitf732c1e252e6b9f4311671c994a1207658090f20 (patch)
tree98b71691f8ee9f39f732c7b521fc011123b71c9e /chrome/browser/net/url_request_mock_util.cc
parent9a7f317d31d4478fb129b1c422f7f2a2d326658d (diff)
downloadchromium_src-f732c1e252e6b9f4311671c994a1207658090f20.zip
chromium_src-f732c1e252e6b9f4311671c994a1207658090f20.tar.gz
chromium_src-f732c1e252e6b9f4311671c994a1207658090f20.tar.bz2
Move mock url request classes to a location when browser tests will be able to use them too.
TEST=none BUG=none Review URL: http://codereview.chromium.org/160366 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22056 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/url_request_mock_util.cc')
-rw-r--r--chrome/browser/net/url_request_mock_util.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/chrome/browser/net/url_request_mock_util.cc b/chrome/browser/net/url_request_mock_util.cc
new file mode 100644
index 0000000..ad0ed09
--- /dev/null
+++ b/chrome/browser/net/url_request_mock_util.cc
@@ -0,0 +1,64 @@
+// 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_util.h"
+
+#include <string>
+
+#include "base/message_loop.h"
+#include "base/path_service.h"
+#include "base/task.h"
+#include "base/thread.h"
+#include "chrome/browser/browser_process.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_slow_download_job.h"
+#include "chrome/browser/net/url_request_slow_http_job.h"
+#include "chrome/common/chrome_paths.h"
+#include "net/url_request/url_request_filter.h"
+
+namespace {
+
+// Helper class for making changes to the URLRequest ProtocolFactory on the
+// IO thread.
+class SetUrlRequestMocksEnabledTask : public Task {
+ public:
+ explicit SetUrlRequestMocksEnabledTask(bool enabled) : enabled_(enabled) {
+ }
+
+ virtual void Run() {
+ if (enabled_) {
+ URLRequestFilter::GetInstance()->ClearHandlers();
+
+ URLRequestFailedDnsJob::AddUrlHandler();
+ URLRequestSlowDownloadJob::AddUrlHandler();
+
+ std::wstring root_http;
+ PathService::Get(chrome::DIR_TEST_DATA, &root_http);
+ URLRequestMockHTTPJob::AddUrlHandler(root_http);
+ URLRequestSlowHTTPJob::AddUrlHandler(root_http);
+ } else {
+ // Revert to the default handlers.
+ URLRequestFilter::GetInstance()->ClearHandlers();
+ }
+ }
+
+ private:
+ bool enabled_;
+
+ DISALLOW_COPY_AND_ASSIGN(SetUrlRequestMocksEnabledTask);
+};
+
+} // namespace
+
+namespace chrome_browser_net {
+
+void SetUrlRequestMocksEnabled(bool enabled) {
+ // Since this involves changing the URLRequest ProtocolFactory, we want to
+ // run on the IO thread.
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ new SetUrlRequestMocksEnabledTask(enabled));
+}
+
+} // namespace chrome_browser_net