diff options
-rw-r--r-- | base/test/test_suite.cc | 30 | ||||
-rw-r--r-- | chromeos/network/onc/onc_certificate_importer_unittest.cc | 5 | ||||
-rw-r--r-- | crypto/nss_util.cc | 5 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_translator.cc | 11 |
4 files changed, 44 insertions, 7 deletions
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc index 07b9964..2d526927 100644 --- a/base/test/test_suite.cc +++ b/base/test/test_suite.cc @@ -76,6 +76,30 @@ class TestClientInitializer : public testing::EmptyTestEventListener { DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); }; +// This class forces the destruction of all Singletons and LazyInstances +// between tests. Deleting singletons between each test prevents state from +// being shared amongst tests, which can lead to subtle bugs in tests. +class SingletonDestructor : public testing::EmptyTestEventListener { + public: + SingletonDestructor() {} + virtual ~SingletonDestructor() {} + + // testing::EmptyTestEventListener: + virtual void OnTestStart( + const testing::TestInfo& test_info) OVERRIDE { + at_exit_manager_.reset(new base::ShadowingAtExitManager); + } + + virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { + at_exit_manager_.reset(); + } + + private: + scoped_ptr<base::ShadowingAtExitManager> at_exit_manager_; + + DISALLOW_COPY_AND_ASSIGN(SingletonDestructor); +}; + } // namespace TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { @@ -252,6 +276,12 @@ void TestSuite::Initialize() { CatchMaybeTests(); ResetCommandLine(); + // Add a listener to destroy all Singletons and LazyInstances between each + // test. See SingletonDestructor for more information. + testing::TestEventListeners& listeners = + testing::UnitTest::GetInstance()->listeners(); + listeners.Append(new SingletonDestructor); + TestTimeouts::Initialize(); } diff --git a/chromeos/network/onc/onc_certificate_importer_unittest.cc b/chromeos/network/onc/onc_certificate_importer_unittest.cc index 1fbb633..fba0871f 100644 --- a/chromeos/network/onc/onc_certificate_importer_unittest.cc +++ b/chromeos/network/onc/onc_certificate_importer_unittest.cc @@ -12,6 +12,7 @@ #include "base/logging.h" #include "base/string_number_conversions.h" +#include "base/threading/platform_thread.h" #include "base/values.h" #include "chromeos/network/onc/onc_constants.h" #include "chromeos/network/onc/onc_test_utils.h" @@ -80,6 +81,10 @@ class ONCCertificateImporterTest : public testing::Test { void AddCertificatesFromFile( std::string filename, CertificateImporter::ParseResult expected_parse_result) { + // This 1 second sleep is necessary because NSS has a caching bug. This + // can be removed once http://crbug.com/238654 is fixed. + base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); + scoped_ptr<base::DictionaryValue> onc = test_utils::ReadTestDictionary(filename); base::Value* certificates_value = NULL; diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc index 9cd0cd1..b3fe4a2 100644 --- a/crypto/nss_util.cc +++ b/crypto/nss_util.cc @@ -746,9 +746,8 @@ ScopedTestNSSDB::ScopedTestNSSDB() } ScopedTestNSSDB::~ScopedTestNSSDB() { - // TODO(mattm): Close the dababase once NSS 3.14 is required, - // which fixes https://bugzilla.mozilla.org/show_bug.cgi?id=588269 - // Resource leaks are suppressed. http://crbug.com/156433 . + if (NSS_VersionCheck("3.14")) + g_nss_singleton.Get().CloseTestNSSDB(); } base::Lock* GetNSSWriteLock() { diff --git a/gpu/command_buffer/service/shader_translator.cc b/gpu/command_buffer/service/shader_translator.cc index 3bd2a97..b70821e 100644 --- a/gpu/command_buffer/service/shader_translator.cc +++ b/gpu/command_buffer/service/shader_translator.cc @@ -16,20 +16,23 @@ namespace { using gpu::gles2::ShaderTranslator; +static bool g_shader_initalized = false; + void FinalizeShaderTranslator(void* /* dummy */) { TRACE_EVENT0("gpu", "ShFinalize"); ShFinalize(); + DCHECK(g_shader_initalized); + g_shader_initalized = false; } bool InitializeShaderTranslator() { - static bool initialized = false; - if (!initialized) { + if (!g_shader_initalized) { TRACE_EVENT0("gpu", "ShInitialize"); CHECK(ShInitialize()); base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL); - initialized = true; + g_shader_initalized = true; } - return initialized; + return g_shader_initalized; } #if !defined(ANGLE_SH_VERSION) || ANGLE_SH_VERSION < 108 |