diff options
Diffstat (limited to 'net')
-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. |