summaryrefslogtreecommitdiffstats
path: root/net/test
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 21:14:14 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 21:14:14 +0000
commit8efa4ba4c13a470905289a4a1f13ecee2d62bf08 (patch)
tree9e2c9b88e8a9ea5e863232e5039bcab031ae74cd /net/test
parent183a152dabcab65621103e493b36cff3d1cb7295 (diff)
downloadchromium_src-8efa4ba4c13a470905289a4a1f13ecee2d62bf08.zip
chromium_src-8efa4ba4c13a470905289a4a1f13ecee2d62bf08.tar.gz
chromium_src-8efa4ba4c13a470905289a4a1f13ecee2d62bf08.tar.bz2
net: move test files out of net/base
BUG=70818 Review URL: https://codereview.chromium.org/12811011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188822 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test')
-rw-r--r--net/test/net_test_suite.cc67
-rw-r--r--net/test/net_test_suite.h53
-rw-r--r--net/test/run_all_unittests.cc53
3 files changed, 173 insertions, 0 deletions
diff --git a/net/test/net_test_suite.cc b/net/test/net_test_suite.cc
new file mode 100644
index 0000000..1687e84
--- /dev/null
+++ b/net/test/net_test_suite.cc
@@ -0,0 +1,67 @@
+// 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.
+
+#include "net/test/net_test_suite.h"
+
+#include "base/message_loop.h"
+#include "net/base/network_change_notifier.h"
+#include "net/http/http_stream_factory.h"
+#include "net/spdy/spdy_session.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#if defined(USE_NSS) || defined(OS_IOS)
+#include "net/ocsp/nss_ocsp.h"
+#endif
+
+class StaticReset : public ::testing::EmptyTestEventListener {
+ virtual void OnTestStart(const ::testing::TestInfo& test_info) OVERRIDE {
+ net::HttpStreamFactory::ResetStaticSettingsToInit();
+ }
+};
+
+NetTestSuite::NetTestSuite(int argc, char** argv)
+ : TestSuite(argc, argv) {
+}
+
+NetTestSuite::NetTestSuite(int argc, char** argv,
+ bool create_at_exit_manager)
+ : TestSuite(argc, argv, create_at_exit_manager) {
+}
+
+NetTestSuite::~NetTestSuite() {}
+
+void NetTestSuite::Initialize() {
+ TestSuite::Initialize();
+ ::testing::UnitTest::GetInstance()->listeners().Append(new StaticReset());
+ InitializeTestThread();
+}
+
+void NetTestSuite::Shutdown() {
+#if defined(USE_NSS) || defined(OS_IOS)
+ net::ShutdownNSSHttpIO();
+#endif
+
+ // We want to destroy this here before the TestSuite continues to tear down
+ // the environment.
+ message_loop_.reset();
+
+ TestSuite::Shutdown();
+}
+
+void NetTestSuite::InitializeTestThread() {
+ network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
+
+ InitializeTestThreadNoNetworkChangeNotifier();
+}
+
+void NetTestSuite::InitializeTestThreadNoNetworkChangeNotifier() {
+ host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL);
+ scoped_host_resolver_proc_.Init(host_resolver_proc_.get());
+ // In case any attempts are made to resolve host names, force them all to
+ // be mapped to localhost. This prevents DNS queries from being sent in
+ // the process of running these unit tests.
+ host_resolver_proc_->AddRule("*", "127.0.0.1");
+
+ message_loop_.reset(new MessageLoopForIO());
+}
diff --git a/net/test/net_test_suite.h b/net/test/net_test_suite.h
new file mode 100644
index 0000000..b2fed70
--- /dev/null
+++ b/net/test/net_test_suite.h
@@ -0,0 +1,53 @@
+// 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 NET_TEST_NET_TEST_SUITE_H_
+#define NET_TEST_NET_TEST_SUITE_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/test/test_suite.h"
+#include "build/build_config.h"
+#include "net/base/mock_host_resolver.h"
+
+class MessageLoop;
+
+namespace net {
+class NetworkChangeNotifier;
+}
+
+class NetTestSuite : public base::TestSuite {
+ public:
+ NetTestSuite(int argc, char** argv);
+ virtual ~NetTestSuite();
+
+ virtual void Initialize() OVERRIDE;
+
+ virtual void Shutdown() OVERRIDE;
+
+ protected:
+ // This constructor is only accessible to specialized net test
+ // implementations which need to control the creation of an AtExitManager
+ // instance for the duration of the test.
+ NetTestSuite(int argc, char** argv, bool create_at_exit_manager);
+
+ // Called from within Initialize(), but separate so that derived classes
+ // can initialize the NetTestSuite instance only and not
+ // TestSuite::Initialize(). TestSuite::Initialize() performs some global
+ // initialization that can only be done once.
+ void InitializeTestThread();
+
+ // Same as above, except it does not create a mock
+ // NetworkChangeNotifier. Use this if your test needs to create and
+ // manage its own mock NetworkChangeNotifier, or if your test uses
+ // the production NetworkChangeNotifier.
+ void InitializeTestThreadNoNetworkChangeNotifier();
+
+ private:
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
+ scoped_ptr<MessageLoop> message_loop_;
+ scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_;
+ net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_;
+};
+
+#endif // NET_TEST_NET_TEST_SUITE_H_
diff --git a/net/test/run_all_unittests.cc b/net/test/run_all_unittests.cc
new file mode 100644
index 0000000..d8392ff
--- /dev/null
+++ b/net/test/run_all_unittests.cc
@@ -0,0 +1,53 @@
+// 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.
+
+#include "base/metrics/statistics_recorder.h"
+#include "build/build_config.h"
+#include "crypto/nss_util.h"
+#include "net/socket/client_socket_pool_base.h"
+#include "net/socket/ssl_server_socket.h"
+#include "net/spdy/spdy_session.h"
+#include "net/test/net_test_suite.h"
+
+#if defined(OS_ANDROID)
+#include "base/android/jni_android.h"
+#include "net/android/net_jni_registrar.h"
+#endif
+
+#if !defined(OS_IOS)
+#include "net/proxy/proxy_resolver_v8.h"
+#endif
+
+using net::internal::ClientSocketPoolBaseHelper;
+using net::SpdySession;
+
+int main(int argc, char** argv) {
+ // Record histograms, so we can get histograms data in tests.
+ base::StatisticsRecorder::Initialize();
+
+#if defined(OS_ANDROID)
+ // Register JNI bindings for android. Doing it early as the test suite setup
+ // may initiate a call to Java.
+ net::android::RegisterJni(base::android::AttachCurrentThread());
+#endif
+
+ NetTestSuite test_suite(argc, argv);
+ ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
+
+#if defined(OS_WIN)
+ // We want to be sure to init NSPR on the main thread.
+ crypto::EnsureNSPRInit();
+#endif
+
+ // Enable support for SSL server sockets, which must be done while
+ // single-threaded.
+ net::EnableSSLServerSockets();
+
+#if !defined(OS_IOS)
+ // This has to be done on the main thread.
+ net::ProxyResolverV8::RememberDefaultIsolate();
+#endif
+
+ return test_suite.Run();
+}