BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / net / url_request_mock_util.cc
blob7c0d96ff5396db2edf766369e5b388175ad4a394
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/net/url_request_mock_util.h"
7 #include <string>
9 #include "base/path_service.h"
10 #include "base/threading/thread_restrictions.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "net/test/url_request/url_request_failed_job.h"
14 #include "net/test/url_request/url_request_mock_http_job.h"
15 #include "net/test/url_request/url_request_slow_download_job.h"
16 #include "net/url_request/url_request_filter.h"
18 using content::BrowserThread;
20 namespace chrome_browser_net {
22 void SetUrlRequestMocksEnabled(bool enabled) {
23 // Since this involves changing the net::URLRequest ProtocolFactory, we need
24 // to run on the IO thread.
25 DCHECK_CURRENTLY_ON(BrowserThread::IO);
27 if (enabled) {
28 // We have to look around for our helper files, but we only use
29 // this from tests, so allow these IO operations to happen
30 // anywhere.
31 base::ThreadRestrictions::ScopedAllowIO allow_io;
33 net::URLRequestFilter::GetInstance()->ClearHandlers();
35 net::URLRequestFailedJob::AddUrlHandler();
36 net::URLRequestSlowDownloadJob::AddUrlHandler();
38 base::FilePath root_http;
39 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
40 net::URLRequestMockHTTPJob::AddUrlHandlers(
41 root_http, BrowserThread::GetBlockingPool());
42 } else {
43 // Revert to the default handlers.
44 net::URLRequestFilter::GetInstance()->ClearHandlers();
48 } // namespace chrome_browser_net