summaryrefslogtreecommitdiffstats
path: root/jingle/notifier
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 /jingle/notifier
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
Diffstat (limited to 'jingle/notifier')
-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
3 files changed, 33 insertions, 84 deletions
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_;