summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 22:56:01 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 22:56:01 +0000
commit4473860ddb85d92fb2fda427f4dabd3415c69c43 (patch)
tree7d77e45863b029707bb7b78afe2dd8e8fa5f7add
parent533e8fe4288e72f87d50479580665b5ec68a8e1b (diff)
downloadchromium_src-4473860ddb85d92fb2fda427f4dabd3415c69c43.zip
chromium_src-4473860ddb85d92fb2fda427f4dabd3415c69c43.tar.gz
chromium_src-4473860ddb85d92fb2fda427f4dabd3415c69c43.tar.bz2
Move TestURLRequestContextGetter to url_request_test_util.{h,cc}
Make everything use this instead of rolling their own. BUG=113723 TEST= Review URL: https://chromiumcodereview.appspot.com/9562037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124758 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_download_unittest.cc3
-rw-r--r--chrome/browser/component_updater/component_updater_service_unittest.cc7
-rw-r--r--chrome/browser/intents/cws_intents_registry_unittest.cc14
-rw-r--r--chrome/browser/net/http_pipelining_compatibility_client_unittest.cc12
-rw-r--r--chrome/browser/safe_browsing/malware_details_unittest.cc1
-rw-r--r--chrome/browser/sync/glue/http_bridge_unittest.cc14
-rw-r--r--chrome/browser/sync/glue/sync_backend_host_unittest.cc2
-rw-r--r--chrome/browser/sync/notifier/DEPS2
-rw-r--r--chrome/browser/sync/notifier/invalidation_notifier_unittest.cc5
-rw-r--r--chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc6
-rw-r--r--chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc6
-rw-r--r--chrome/browser/sync/tools/sync_listen_notifications.cc5
-rw-r--r--chrome/browser/sync/tools/sync_tools.gyp1
-rw-r--r--chrome/chrome_tests.gypi4
-rw-r--r--chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc26
-rw-r--r--chrome/test/base/test_url_request_context_getter.cc25
-rw-r--r--chrome/test/base/test_url_request_context_getter.h35
-rw-r--r--chrome/test/base/testing_profile.cc5
-rw-r--r--content/common/net/url_fetcher_impl_unittest.cc24
-rw-r--r--jingle/notifier/base/proxy_resolving_client_socket_unittest.cc54
-rw-r--r--jingle/notifier/base/xmpp_connection_unittest.cc32
-rw-r--r--jingle/notifier/listener/mediator_thread_unittest.cc31
-rw-r--r--net/net.gyp5
-rw-r--r--net/url_request/url_request_test_util.cc19
-rw-r--r--net/url_request/url_request_test_util.h26
25 files changed, 137 insertions, 227 deletions
diff --git a/chrome/browser/autofill/autofill_download_unittest.cc b/chrome/browser/autofill/autofill_download_unittest.cc
index dab40ce..c4f26cf 100644
--- a/chrome/browser/autofill/autofill_download_unittest.cc
+++ b/chrome/browser/autofill/autofill_download_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 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.
@@ -13,7 +13,6 @@
#include "chrome/browser/autofill/autofill_metrics.h"
#include "chrome/browser/autofill/autofill_type.h"
#include "chrome/browser/autofill/form_structure.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "content/test/test_browser_thread.h"
diff --git a/chrome/browser/component_updater/component_updater_service_unittest.cc b/chrome/browser/component_updater/component_updater_service_unittest.cc
index 89fce47..fd38931 100644
--- a/chrome/browser/component_updater/component_updater_service_unittest.cc
+++ b/chrome/browser/component_updater/component_updater_service_unittest.cc
@@ -14,16 +14,14 @@
#include "chrome/browser/component_updater/component_updater_interceptor.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_service.h"
#include "content/test/test_browser_thread.h"
#include "content/public/common/url_fetcher.h"
#include "content/test/test_notification_tracker.h"
-
#include "googleurl/src/gurl.h"
#include "libxml/globals.h"
-
+#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
@@ -65,7 +63,8 @@ class TestConfigurator : public ComponentUpdateService::Configurator {
virtual size_t UrlSizeLimit() OVERRIDE { return 256; }
virtual net::URLRequestContextGetter* RequestContext() OVERRIDE {
- return new TestURLRequestContextGetter();
+ return new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
}
// Don't use the utility process to decode files.
diff --git a/chrome/browser/intents/cws_intents_registry_unittest.cc b/chrome/browser/intents/cws_intents_registry_unittest.cc
index dcd0e0b..2c258f5 100644
--- a/chrome/browser/intents/cws_intents_registry_unittest.cc
+++ b/chrome/browser/intents/cws_intents_registry_unittest.cc
@@ -8,8 +8,8 @@
#include "base/bind_helpers.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/test/test_url_fetcher_factory.h"
+#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -91,17 +91,18 @@ class CWSIntentsRegistryTest : public testing::Test {
CWSIntentsRegistry::IntentExtensionList extensions_;
FakeURLFetcherFactory test_factory_;
- private:
+ protected:
MessageLoop ui_loop_;
};
} // namespace
TEST_F(CWSIntentsRegistryTest, ValidQuery) {
- TestURLRequestContextGetter context_getter;
+ const scoped_refptr<TestURLRequestContextGetter> context_getter(
+ new TestURLRequestContextGetter(ui_loop_.message_loop_proxy()));
test_factory_.SetFakeResponse(kCWSQueryValid, kCWSResponseValid, true);
- CWSIntentsRegistry registry(&context_getter);
+ CWSIntentsRegistry registry(context_getter);
registry.GetIntentServices(ASCIIToUTF16("http://webintents.org/edit"),
ASCIIToUTF16("*/png"),
base::Bind(&CWSIntentsRegistryTest::Callback,
@@ -117,10 +118,11 @@ TEST_F(CWSIntentsRegistryTest, ValidQuery) {
}
TEST_F(CWSIntentsRegistryTest, InvalidQuery) {
- TestURLRequestContextGetter context_getter;
+ const scoped_refptr<TestURLRequestContextGetter> context_getter(
+ new TestURLRequestContextGetter(ui_loop_.message_loop_proxy()));
test_factory_.SetFakeResponse(kCWSQueryInvalid, kCWSResponseInvalid, true);
- CWSIntentsRegistry registry(&context_getter);
+ CWSIntentsRegistry registry(context_getter);
registry.GetIntentServices(ASCIIToUTF16("foo"),
ASCIIToUTF16("foo"),
base::Bind(&CWSIntentsRegistryTest::Callback,
diff --git a/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc b/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc
index 91608c7..0585795 100644
--- a/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc
+++ b/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc
@@ -13,11 +13,11 @@
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/stringprintf.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/test/test_browser_thread.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/url_request/url_request_context_getter.h"
+#include "net/url_request/url_request_test_util.h"
#include "net/test/test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -43,6 +43,8 @@ enum HistogramField {
FIELD_STATUS,
};
+using content::BrowserThread;
+
class HttpPipeliningCompatibilityClientTest : public testing::Test {
public:
HttpPipeliningCompatibilityClientTest()
@@ -50,13 +52,14 @@ class HttpPipeliningCompatibilityClientTest : public testing::Test {
net::TestServer::TYPE_HTTP,
net::TestServer::kLocalhost,
FilePath(FILE_PATH_LITERAL("chrome/test/data/http_pipelining"))),
- io_thread_(content::BrowserThread::IO, &message_loop_) {
+ io_thread_(BrowserThread::IO, &message_loop_) {
}
protected:
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(test_server_.Start());
- context_ = new TestURLRequestContextGetter;
+ context_ = new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
context_->AddRef();
for (size_t i = 0; i < arraysize(kHistogramNames); ++i) {
@@ -69,8 +72,7 @@ class HttpPipeliningCompatibilityClientTest : public testing::Test {
}
virtual void TearDown() OVERRIDE {
- content::BrowserThread::ReleaseSoon(content::BrowserThread::IO,
- FROM_HERE, context_);
+ BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, context_);
message_loop_.RunAllPending();
}
diff --git a/chrome/browser/safe_browsing/malware_details_unittest.cc b/chrome/browser/safe_browsing/malware_details_unittest.cc
index cb665f6..dfe3b64 100644
--- a/chrome/browser/safe_browsing/malware_details_unittest.cc
+++ b/chrome/browser/safe_browsing/malware_details_unittest.cc
@@ -16,7 +16,6 @@
#include "chrome/common/render_messages.h"
#include "chrome/common/safe_browsing/safebrowsing_messages.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "chrome/test/base/testing_profile.h"
#include "content/browser/tab_contents/test_tab_contents.h"
#include "content/test/test_browser_thread.h"
diff --git a/chrome/browser/sync/glue/http_bridge_unittest.cc b/chrome/browser/sync/glue/http_bridge_unittest.cc
index 1fd9092..5329819 100644
--- a/chrome/browser/sync/glue/http_bridge_unittest.cc
+++ b/chrome/browser/sync/glue/http_bridge_unittest.cc
@@ -5,7 +5,6 @@
#include "base/message_loop_proxy.h"
#include "base/threading/thread.h"
#include "chrome/browser/sync/glue/http_bridge.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/test/test_browser_thread.h"
#include "content/test/test_url_fetcher_factory.h"
#include "net/test/test_server.h"
@@ -45,7 +44,9 @@ class SyncHttpBridgeTest : public testing::Test {
HttpBridge* BuildBridge() {
if (!fake_default_request_context_getter_) {
- fake_default_request_context_getter_ = new TestURLRequestContextGetter();
+ fake_default_request_context_getter_ =
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
fake_default_request_context_getter_->AddRef();
}
HttpBridge* bridge = new HttpBridge(
@@ -148,7 +149,8 @@ TEST_F(SyncHttpBridgeTest, TestUsesSameHttpNetworkSession) {
// Test the HttpBridge without actually making any network requests.
TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostShunted) {
scoped_refptr<net::URLRequestContextGetter> ctx_getter(
- new TestURLRequestContextGetter());
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge(
ctx_getter, this, false));
http_bridge->SetUserAgent("bob");
@@ -272,7 +274,8 @@ TEST_F(SyncHttpBridgeTest, TestResponseHeader) {
TEST_F(SyncHttpBridgeTest, Abort) {
scoped_refptr<net::URLRequestContextGetter> ctx_getter(
- new TestURLRequestContextGetter());
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge(
ctx_getter, this, true));
http_bridge->SetUserAgent("bob");
@@ -291,7 +294,8 @@ TEST_F(SyncHttpBridgeTest, Abort) {
TEST_F(SyncHttpBridgeTest, AbortLate) {
scoped_refptr<net::URLRequestContextGetter> ctx_getter(
- new TestURLRequestContextGetter());
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge(
ctx_getter, this, false));
http_bridge->SetUserAgent("bob");
diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
index 2a700ec..04e1807 100644
--- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc
+++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
@@ -14,9 +14,7 @@
#include "chrome/browser/sync/protocol/sync_protocol_error.h"
#include "chrome/browser/sync/sync_prefs.h"
#include "chrome/browser/sync/syncable/model_type.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "chrome/test/base/testing_profile.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/test/test_browser_thread.h"
#include "content/test/test_url_fetcher_factory.h"
#include "googleurl/src/gurl.h"
diff --git a/chrome/browser/sync/notifier/DEPS b/chrome/browser/sync/notifier/DEPS
index 19b4f38..7376cba 100644
--- a/chrome/browser/sync/notifier/DEPS
+++ b/chrome/browser/sync/notifier/DEPS
@@ -1,8 +1,6 @@
include_rules = [
"-chrome",
- "+chrome/test/base",
-
"+chrome/browser/sync/notifier",
"+chrome/browser/sync/syncable/model_type.h",
"+chrome/browser/sync/syncable/model_type_payload_map.h",
diff --git a/chrome/browser/sync/notifier/invalidation_notifier_unittest.cc b/chrome/browser/sync/notifier/invalidation_notifier_unittest.cc
index 93b123a..64f206c 100644
--- a/chrome/browser/sync/notifier/invalidation_notifier_unittest.cc
+++ b/chrome/browser/sync/notifier/invalidation_notifier_unittest.cc
@@ -11,12 +11,12 @@
#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/browser/sync/util/weak_handle.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/test/test_browser_thread.h"
#include "jingle/notifier/base/fake_base_task.h"
#include "jingle/notifier/base/notifier_options.h"
#include "net/base/cert_verifier.h"
#include "net/base/host_resolver.h"
+#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -37,7 +37,8 @@ class InvalidationNotifierTest : public testing::Test {
notifier::NotifierOptions notifier_options;
// Note: URLRequestContextGetters are ref-counted.
notifier_options.request_context_getter =
- new TestURLRequestContextGetter();
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
invalidation_notifier_.reset(
new InvalidationNotifier(
notifier_options,
diff --git a/chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc b/chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc
index c293bdb..a3b8f64 100644
--- a/chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc
+++ b/chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc
@@ -13,9 +13,9 @@
#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/browser/sync/util/weak_handle.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/test/test_browser_thread.h"
#include "jingle/notifier/base/fake_base_task.h"
+#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -37,7 +37,9 @@ class NonBlockingInvalidationNotifierTest : public testing::Test {
base::Thread::Options options;
options.message_loop_type = MessageLoop::TYPE_IO;
io_thread_.StartIOThread();
- request_context_getter_ = new TestURLRequestContextGetter;
+ request_context_getter_ =
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
notifier::NotifierOptions notifier_options;
notifier_options.request_context_getter = request_context_getter_;
invalidation_notifier_.reset(
diff --git a/chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc b/chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc
index 70783a5..89bf8eb 100644
--- a/chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc
+++ b/chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc
@@ -17,8 +17,8 @@
#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/test/test_browser_thread.h"
+#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -39,7 +39,9 @@ class SyncNotifierFactoryTest : public testing::Test {
virtual ~SyncNotifierFactoryTest() {}
virtual void SetUp() OVERRIDE {
- request_context_getter_ = new TestURLRequestContextGetter;
+ request_context_getter_ =
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
factory_.reset(new SyncNotifierFactory(
"fake_client_info",
request_context_getter_,
diff --git a/chrome/browser/sync/tools/sync_listen_notifications.cc b/chrome/browser/sync/tools/sync_listen_notifications.cc
index c5836ab..76f8bce 100644
--- a/chrome/browser/sync/tools/sync_listen_notifications.cc
+++ b/chrome/browser/sync/tools/sync_listen_notifications.cc
@@ -21,9 +21,9 @@
#include "chrome/browser/sync/notifier/sync_notifier_observer.h"
#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/syncable/model_type_payload_map.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/public/browser/browser_thread.h"
#include "content/test/test_browser_thread.h"
+#include "net/url_request/url_request_test_util.h"
using content::BrowserThread;
@@ -125,7 +125,8 @@ int main(int argc, char* argv[]) {
const char kClientInfo[] = "sync_listen_notifications";
scoped_refptr<TestURLRequestContextGetter> request_context_getter(
- new TestURLRequestContextGetter());
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
NullInvalidationVersionTracker null_invalidation_version_tracker;
sync_notifier::SyncNotifierFactory sync_notifier_factory(
kClientInfo, request_context_getter,
diff --git a/chrome/browser/sync/tools/sync_tools.gyp b/chrome/browser/sync/tools/sync_tools.gyp
index 226ae62..fddbd34 100644
--- a/chrome/browser/sync/tools/sync_tools.gyp
+++ b/chrome/browser/sync/tools/sync_tools.gyp
@@ -16,6 +16,7 @@
'<(DEPTH)/chrome/chrome.gyp:test_support_common',
'<(DEPTH)/content/content.gyp:content_browser',
'<(DEPTH)/net/net.gyp:net',
+ '<(DEPTH)/net/net.gyp:net_test_support',
],
},
],
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 307e865..8a50040 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -59,7 +59,6 @@
'../ipc/ipc.gyp:test_support_ipc',
'../media/media.gyp:media_test_support',
'../net/net.gyp:net',
- # 'test/base/test_url_request_context_getter.h' brings in this requirement.
'../net/net.gyp:net_test_support',
'../skia/skia.gyp:skia',
'../testing/gmock.gyp:gmock',
@@ -236,8 +235,6 @@
'test/base/test_switches.h',
'test/base/test_tab_strip_model_observer.cc',
'test/base/test_tab_strip_model_observer.h',
- 'test/base/test_url_request_context_getter.cc',
- 'test/base/test_url_request_context_getter.h',
'test/base/testing_browser_process.cc',
'test/base/testing_browser_process.h',
'test/base/testing_pref_service.cc',
@@ -3689,6 +3686,7 @@
'../base/base.gyp:test_support_base',
'../jingle/jingle.gyp:notifier_test_util',
'../net/net.gyp:net',
+ '../net/net.gyp:net_test_support',
'../skia/skia.gyp:skia',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc b/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc
index 11be40d..5103ec8 100644
--- a/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc
+++ b/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc
@@ -26,31 +26,18 @@ namespace {
const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
int g_request_context_getter_instances = 0;
-class TestURLRequestContextGetter : public net::URLRequestContextGetter {
+class TrackingTestURLRequestContextGetter
+ : public TestURLRequestContextGetter {
public:
- explicit TestURLRequestContextGetter(
+ explicit TrackingTestURLRequestContextGetter(
base::MessageLoopProxy* io_message_loop_proxy)
- : io_message_loop_proxy_(io_message_loop_proxy) {
+ : TestURLRequestContextGetter(io_message_loop_proxy) {
g_request_context_getter_instances++;
}
- virtual net::URLRequestContext* GetURLRequestContext() {
- if (!context_)
- context_ = new TestURLRequestContext();
- return context_;
- }
- virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
- return io_message_loop_proxy_;
- }
-
protected:
- scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
-
- private:
- virtual ~TestURLRequestContextGetter() {
+ virtual ~TrackingTestURLRequestContextGetter() {
g_request_context_getter_instances--;
}
-
- scoped_refptr<net::URLRequestContext> context_;
};
class TestCloudPrintURLFetcher : public CloudPrintURLFetcher {
@@ -61,7 +48,8 @@ class TestCloudPrintURLFetcher : public CloudPrintURLFetcher {
}
virtual net::URLRequestContextGetter* GetRequestContextGetter() {
- return new TestURLRequestContextGetter(io_message_loop_proxy_.get());
+ return new TrackingTestURLRequestContextGetter(
+ io_message_loop_proxy_.get());
}
private:
scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
diff --git a/chrome/test/base/test_url_request_context_getter.cc b/chrome/test/base/test_url_request_context_getter.cc
deleted file mode 100644
index 4cd0a89..0000000
--- a/chrome/test/base/test_url_request_context_getter.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2011 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/test/base/test_url_request_context_getter.h"
-
-#include "content/public/browser/browser_thread.h"
-#include "net/url_request/url_request_test_util.h"
-
-using content::BrowserThread;
-
-TestURLRequestContextGetter::TestURLRequestContextGetter() {}
-
-TestURLRequestContextGetter::~TestURLRequestContextGetter() {}
-
-net::URLRequestContext* TestURLRequestContextGetter::GetURLRequestContext() {
- if (!context_)
- context_ = new TestURLRequestContext();
- return context_.get();
-}
-
-scoped_refptr<base::MessageLoopProxy>
-TestURLRequestContextGetter::GetIOMessageLoopProxy() const {
- return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
-}
diff --git a/chrome/test/base/test_url_request_context_getter.h b/chrome/test/base/test_url_request_context_getter.h
deleted file mode 100644
index 8dd7b52..0000000
--- a/chrome/test/base/test_url_request_context_getter.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef CHROME_TEST_BASE_TEST_URL_REQUEST_CONTEXT_GETTER_H_
-#define CHROME_TEST_BASE_TEST_URL_REQUEST_CONTEXT_GETTER_H_
-#pragma once
-
-#include "base/memory/ref_counted.h"
-#include "net/url_request/url_request_context_getter.h"
-
-namespace base {
-class MessageLoopProxy;
-}
-
-// Used to return a dummy context (normally the context is on the IO thread).
-// The one here can be run on the main test thread. Note that this can lead to
-// a leak if your test does not have a BrowserThread::IO in it because
-// URLRequestContextGetter is defined as a ReferenceCounted object with a
-// special trait that deletes it on the IO thread.
-class TestURLRequestContextGetter : public net::URLRequestContextGetter {
- public:
- TestURLRequestContextGetter();
- virtual ~TestURLRequestContextGetter();
-
- // net::URLRequestContextGetter implementation.
- virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
- virtual scoped_refptr<base::MessageLoopProxy>
- GetIOMessageLoopProxy() const OVERRIDE;
-
- private:
- scoped_refptr<net::URLRequestContext> context_;
-};
-
-#endif // CHROME_TEST_BASE_TEST_URL_REQUEST_CONTEXT_GETTER_H_
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 369cfaf..5e845fc 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -44,7 +44,6 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/bookmark_load_observer.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "chrome/test/base/testing_pref_service.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/mock_resource_context.h"
@@ -595,7 +594,9 @@ net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
void TestingProfile::CreateRequestContext() {
if (!request_context_)
- request_context_ = new TestURLRequestContextGetter();
+ request_context_ =
+ new TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
}
void TestingProfile::ResetRequestContext() {
diff --git a/content/common/net/url_fetcher_impl_unittest.cc b/content/common/net/url_fetcher_impl_unittest.cc
index 909bb6f..52729b1 100644
--- a/content/common/net/url_fetcher_impl_unittest.cc
+++ b/content/common/net/url_fetcher_impl_unittest.cc
@@ -32,30 +32,6 @@ namespace {
const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
const char kTestServerFilePrefix[] = "files/";
-class TestURLRequestContextGetter : public net::URLRequestContextGetter {
- public:
- explicit TestURLRequestContextGetter(
- base::MessageLoopProxy* io_message_loop_proxy)
- : io_message_loop_proxy_(io_message_loop_proxy) {
- }
- virtual net::URLRequestContext* GetURLRequestContext() {
- if (!context_)
- context_ = new TestURLRequestContext();
- return context_;
- }
- virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
- return io_message_loop_proxy_;
- }
-
- protected:
- scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
-
- private:
- virtual ~TestURLRequestContextGetter() {}
-
- scoped_refptr<net::URLRequestContext> context_;
-};
-
} // namespace
class URLFetcherTest : public testing::Test,
diff --git a/jingle/notifier/base/proxy_resolving_client_socket_unittest.cc b/jingle/notifier/base/proxy_resolving_client_socket_unittest.cc
index ab9253b..a38b904 100644
--- a/jingle/notifier/base/proxy_resolving_client_socket_unittest.cc
+++ b/jingle/notifier/base/proxy_resolving_client_socket_unittest.cc
@@ -5,6 +5,7 @@
#include "jingle/notifier/base/proxy_resolving_client_socket.h"
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "net/base/mock_host_resolver.h"
#include "net/base/test_completion_callback.h"
@@ -14,36 +15,34 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace {
-// TODO(sanjeevr): Move this to net_test_support.
-// Used to return a dummy context.
-class TestURLRequestContextGetter : public net::URLRequestContextGetter {
+
+class ProxyTestURLRequestContextGetter : public TestURLRequestContextGetter {
public:
- TestURLRequestContextGetter()
- : message_loop_proxy_(base::MessageLoopProxy::current()) {
+ ProxyTestURLRequestContextGetter()
+ : TestURLRequestContextGetter(base::MessageLoopProxy::current()),
+ set_context_members_(false) {}
+
+ // Override GetURLRequestContext to set the host resolver and proxy
+ // service (used by the unit tests).
+ virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE {
+ TestURLRequestContext* context =
+ TestURLRequestContextGetter::GetURLRequestContext();
+ if (!set_context_members_) {
+ context->set_host_resolver(new net::MockHostResolver());
+ context->set_proxy_service(net::ProxyService::CreateFixedFromPacResult(
+ "PROXY bad:99; PROXY maybe:80; DIRECT"));
+ set_context_members_ = true;
+ }
+ return context;
}
- virtual ~TestURLRequestContextGetter() { }
- // net::URLRequestContextGetter:
- virtual net::URLRequestContext* GetURLRequestContext() {
- if (!context_)
- CreateURLRequestContext();
- return context_.get();
- }
- virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
- return message_loop_proxy_;
- }
+ protected:
+ virtual ~ProxyTestURLRequestContextGetter() {}
private:
- void CreateURLRequestContext() {
- context_ = new TestURLRequestContext();
- context_->set_host_resolver(new net::MockHostResolver());
- context_->set_proxy_service(net::ProxyService::CreateFixedFromPacResult(
- "PROXY bad:99; PROXY maybe:80; DIRECT"));
- }
-
- scoped_refptr<net::URLRequestContext> context_;
- scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
+ bool set_context_members_;
};
+
} // namespace
namespace notifier {
@@ -51,7 +50,7 @@ namespace notifier {
class ProxyResolvingClientSocketTest : public testing::Test {
protected:
ProxyResolvingClientSocketTest()
- : url_request_context_getter_(new TestURLRequestContextGetter()) {}
+ : url_request_context_getter_(new ProxyTestURLRequestContextGetter()) {}
virtual ~ProxyResolvingClientSocketTest() {}
@@ -61,9 +60,8 @@ class ProxyResolvingClientSocketTest : public testing::Test {
message_loop_.RunAllPending();
}
- // Needed by XmppConnection.
- MessageLoopForIO message_loop_;
- scoped_refptr<TestURLRequestContextGetter> url_request_context_getter_;
+ MessageLoop message_loop_;
+ scoped_refptr<ProxyTestURLRequestContextGetter> url_request_context_getter_;
};
// TODO(sanjeevr): Fix this test on Linux.
diff --git a/jingle/notifier/base/xmpp_connection_unittest.cc b/jingle/notifier/base/xmpp_connection_unittest.cc
index e2c88cd..1c37bde 100644
--- a/jingle/notifier/base/xmpp_connection_unittest.cc
+++ b/jingle/notifier/base/xmpp_connection_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 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.
@@ -8,6 +8,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "jingle/notifier/base/mock_task.h"
@@ -32,32 +33,6 @@ class SocketAddress;
class Task;
} // namespace talk_base
-namespace {
-// TODO(sanjeevr): Move this to net_test_support.
-// Used to return a dummy context.
-class TestURLRequestContextGetter : public net::URLRequestContextGetter {
- public:
- TestURLRequestContextGetter()
- : message_loop_proxy_(base::MessageLoopProxy::current()) {
- }
- virtual ~TestURLRequestContextGetter() { }
-
- // net::URLRequestContextGetter:
- virtual net::URLRequestContext* GetURLRequestContext() {
- if (!context_)
- context_ = new TestURLRequestContext();
- return context_.get();
- }
- virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
- return message_loop_proxy_;
- }
-
- private:
- scoped_refptr<net::URLRequestContext> context_;
- scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
-};
-} // namespace
-
namespace notifier {
using ::testing::_;
@@ -98,7 +73,8 @@ class XmppConnectionTest : public testing::Test {
protected:
XmppConnectionTest()
: mock_pre_xmpp_auth_(new MockPreXmppAuth()),
- url_request_context_getter_(new TestURLRequestContextGetter()) {}
+ url_request_context_getter_(new TestURLRequestContextGetter(
+ message_loop_.message_loop_proxy())) {}
virtual ~XmppConnectionTest() {}
diff --git a/jingle/notifier/listener/mediator_thread_unittest.cc b/jingle/notifier/listener/mediator_thread_unittest.cc
index 1d6767f..afb8ce1 100644
--- a/jingle/notifier/listener/mediator_thread_unittest.cc
+++ b/jingle/notifier/listener/mediator_thread_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 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.
@@ -22,30 +22,6 @@ namespace {
using ::testing::StrictMock;
-// TODO(sanjeevr): Move this to net_test_support.
-// Used to return a dummy context.
-class TestURLRequestContextGetter : public net::URLRequestContextGetter {
- public:
- TestURLRequestContextGetter()
- : message_loop_proxy_(base::MessageLoopProxy::current()) {
- }
- virtual ~TestURLRequestContextGetter() { }
-
- // net::URLRequestContextGetter:
- virtual net::URLRequestContext* GetURLRequestContext() {
- if (!context_)
- context_ = new TestURLRequestContext();
- return context_.get();
- }
- virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
- return message_loop_proxy_;
- }
-
- private:
- scoped_refptr<net::URLRequestContext> context_;
- scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
-};
-
class MockObserver : public MediatorThread::Observer {
public:
MOCK_METHOD1(OnConnectionStateChange, void(bool));
@@ -60,7 +36,7 @@ class MediatorThreadTest : public testing::Test {
protected:
MediatorThreadTest() {
notifier_options_.request_context_getter =
- new TestURLRequestContextGetter();
+ new TestURLRequestContextGetter(message_loop_.message_loop_proxy());
}
virtual ~MediatorThreadTest() {}
@@ -78,8 +54,7 @@ class MediatorThreadTest : public testing::Test {
mediator_thread_.reset();
}
- // Needed by TestURLRequestContextGetter.
- MessageLoopForIO message_loop_;
+ MessageLoop message_loop_;
NotifierOptions notifier_options_;
StrictMock<MockObserver> mock_observer_;
scoped_ptr<MediatorThreadImpl> mediator_thread_;
diff --git a/net/net.gyp b/net/net.gyp
index b2b4aad..6d911b4 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -1412,6 +1412,11 @@
'../base/base.gyp:test_support_base',
'../testing/gtest.gyp:gtest',
],
+ 'export_dependent_settings': [
+ '../base/base.gyp:base',
+ '../base/base.gyp:test_support_base',
+ '../testing/gtest.gyp:gtest',
+ ],
'sources': [
'base/cert_test_util.cc',
'base/cert_test_util.h',
diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc
index 2f3dd6e..10bb2e5 100644
--- a/net/url_request/url_request_test_util.cc
+++ b/net/url_request/url_request_test_util.cc
@@ -164,6 +164,25 @@ TestURLRequest::TestURLRequest(const GURL& url, Delegate* delegate)
TestURLRequest::~TestURLRequest() {}
+TestURLRequestContextGetter::TestURLRequestContextGetter(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy)
+ : io_message_loop_proxy_(io_message_loop_proxy) {
+ DCHECK(io_message_loop_proxy.get());
+}
+
+TestURLRequestContextGetter::~TestURLRequestContextGetter() {}
+
+TestURLRequestContext* TestURLRequestContextGetter::GetURLRequestContext() {
+ if (!context_)
+ context_ = new TestURLRequestContext();
+ return context_.get();
+}
+
+scoped_refptr<base::MessageLoopProxy>
+TestURLRequestContextGetter::GetIOMessageLoopProxy() const {
+ return io_message_loop_proxy_;
+}
+
TestDelegate::TestDelegate()
: cancel_in_rr_(false),
cancel_in_rs_(false),
diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h
index 29ecb98..258c448 100644
--- a/net/url_request/url_request_test_util.h
+++ b/net/url_request/url_request_test_util.h
@@ -13,6 +13,8 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "base/message_loop_proxy.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
@@ -35,6 +37,7 @@
#include "net/proxy/proxy_service.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"
#include "net/url_request/url_request_context_storage.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -73,6 +76,29 @@ class TestURLRequestContext : public net::URLRequestContext {
//-----------------------------------------------------------------------------
+// Used to return a dummy context, which lives on the message loop
+// given in the constructor.
+class TestURLRequestContextGetter : public net::URLRequestContextGetter {
+ public:
+ // |io_message_loop_proxy| must not be NULL.
+ explicit TestURLRequestContextGetter(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy);
+
+ // net::URLRequestContextGetter implementation.
+ virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE;
+ virtual scoped_refptr<base::MessageLoopProxy>
+ GetIOMessageLoopProxy() const OVERRIDE;
+
+ protected:
+ virtual ~TestURLRequestContextGetter();
+
+ private:
+ const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
+ scoped_refptr<TestURLRequestContext> context_;
+};
+
+//-----------------------------------------------------------------------------
+
class TestURLRequest : public net::URLRequest {
public:
TestURLRequest(const GURL& url, Delegate* delegate);