diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 20:03:08 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 20:03:08 +0000 |
commit | aed0ae17565a5af8b534ea3ec6a587725d028720 (patch) | |
tree | f0886521fd00c484b768b2340fba475155a75d13 | |
parent | 8dc1bfe262b87f61e9bc611caedb22a794f85254 (diff) | |
download | chromium_src-aed0ae17565a5af8b534ea3ec6a587725d028720.zip chromium_src-aed0ae17565a5af8b534ea3ec6a587725d028720.tar.gz chromium_src-aed0ae17565a5af8b534ea3ec6a587725d028720.tar.bz2 |
Reset static HttpStreamFactory settings before each test in a NetTestSuite.
This improves test isolation.
BUG=
TEST=./net_unittests --gtest_shuffle=1 --gtest_random_seed=56044
More specifically:
TEST=./net_unittests --gtest_shuffle=1 --gtest_random_seed=56044 --gtest_filter=Spdy/SpdyNetworkTransactionTest.ThreeGets/1:HttpStreamFactoryTest.PreconnectHttpProxy
Review URL: http://codereview.chromium.org/8295009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106106 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/base/net_test_suite.cc | 9 | ||||
-rw-r--r-- | net/http/http_stream_factory.cc | 19 | ||||
-rw-r--r-- | net/http/http_stream_factory.h | 4 |
3 files changed, 32 insertions, 0 deletions
diff --git a/net/base/net_test_suite.cc b/net/base/net_test_suite.cc index a37bc5b..451a8aaa 100644 --- a/net/base/net_test_suite.cc +++ b/net/base/net_test_suite.cc @@ -5,9 +5,17 @@ #include "net/base/net_test_suite.h" #include "base/message_loop.h" +#include "net/http/http_stream_factory.h" #if defined(USE_NSS) #include "net/ocsp/nss_ocsp.h" #endif +#include "testing/gtest/include/gtest/gtest.h" + +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) { @@ -17,6 +25,7 @@ NetTestSuite::~NetTestSuite() {} void NetTestSuite::Initialize() { TestSuite::Initialize(); + ::testing::UnitTest::GetInstance()->listeners().Append(new StaticReset()); InitializeTestThread(); } diff --git a/net/http/http_stream_factory.cc b/net/http/http_stream_factory.cc index bcbd8d3..70a4940 100644 --- a/net/http/http_stream_factory.cc +++ b/net/http/http_stream_factory.cc @@ -14,6 +14,9 @@ namespace net { +// WARNING: If you modify or add any static flags, you must keep them in sync +// with |ResetStaticSettingsToInit|. This is critical for unit test isolation. + // static const HostMappingRules* HttpStreamFactory::host_mapping_rules_ = NULL; // static @@ -33,6 +36,22 @@ bool HttpStreamFactory::ignore_certificate_errors_ = false; HttpStreamFactory::~HttpStreamFactory() {} +// static +void HttpStreamFactory::ResetStaticSettingsToInit() { + // WARNING: These must match the initializers above. + delete host_mapping_rules_; + delete next_protos_; + delete forced_spdy_exclusions_; + host_mapping_rules_ = NULL; + next_protos_ = NULL; + spdy_enabled_ = true; + use_alternate_protocols_ = false; + force_spdy_over_ssl_ = true; + force_spdy_always_ = false; + forced_spdy_exclusions_ = NULL; + ignore_certificate_errors_ = false; +} + void HttpStreamFactory::ProcessAlternateProtocol( HttpServerProperties* http_server_properties, const std::string& alternate_protocol_str, diff --git a/net/http/http_stream_factory.h b/net/http/http_stream_factory.h index f92c11e..3cbad96 100644 --- a/net/http/http_stream_factory.h +++ b/net/http/http_stream_factory.h @@ -176,6 +176,10 @@ class NET_EXPORT HttpStreamFactory { virtual bool IsTLSIntolerantServer(const HostPortPair& server) const = 0; // Static settings + + // Reset all static settings to initialized values. Used to init test suite. + static void ResetStaticSettingsToInit(); + static GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); // Turns spdy on or off. |