Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/test/test_suite.h" | 5 #include "base/test/test_suite.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 namespace base { | 75 namespace base { |
| 76 | 76 |
| 77 class TestWatchAtExitManager : public testing::EmptyTestEventListener { | 77 class TestWatchAtExitManager : public testing::EmptyTestEventListener { |
| 78 public: | 78 public: |
| 79 TestWatchAtExitManager() { } | 79 TestWatchAtExitManager() { } |
| 80 ~TestWatchAtExitManager() { } | 80 ~TestWatchAtExitManager() { } |
| 81 | 81 |
| 82 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | 82 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { |
| 83 initial_top_manager_ = AtExitManager::current(); | 83 initial_top_manager_ = AtExitManager::current(); |
| 84 at_exit_stack_size_ = initial_top_manager_->CallbackStackSize(); | 84 at_exit_stack_size_ = initial_top_manager_->CallbackStackSize(); |
| 85 per_test_manager_.reset(new base::AtExitManager); | |
| 85 } | 86 } |
| 86 | 87 |
| 87 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | 88 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { |
| 88 AtExitManager* new_top_manager = AtExitManager::current(); | 89 AtExitManager* new_top_manager = AtExitManager::current(); |
| 90 if (per_test_manager_.get() != new_top_manager) { | |
| 91 ADD_FAILURE() << "The current AtExitManager has changed across the " | |
| 92 "test " << test_info.test_case_name() << "." << test_info.name() << | |
| 93 " most likely because one was created without being destroyed."; | |
|
Ryan Sleevi
2012/07/11 22:30:41
style nit: The << should be on the beginning of ea
| |
| 94 } | |
| 95 per_test_manager_.reset(); | |
| 96 | |
| 97 new_top_manager = AtExitManager::current(); | |
| 89 size_t new_stack_size = new_top_manager->CallbackStackSize(); | 98 size_t new_stack_size = new_top_manager->CallbackStackSize(); |
| 90 | 99 |
| 91 if (initial_top_manager_ != new_top_manager) { | 100 if (initial_top_manager_ != new_top_manager) { |
| 92 ADD_FAILURE() << "The current AtExitManager has changed across the " | 101 ADD_FAILURE() << "The current AtExitManager has changed across the " |
| 93 "test " << test_info.test_case_name() << "." << test_info.name() << | 102 "test " << test_info.test_case_name() << "." << test_info.name() << |
| 94 " most likely because one was created without being destroyed."; | 103 " most likely because one was created without being destroyed."; |
| 95 } else if (new_stack_size != at_exit_stack_size_) { | 104 } else if (new_stack_size != at_exit_stack_size_) { |
| 96 // TODO(scottbyer): clean up all the errors that result from this and | 105 ADD_FAILURE() << |
| 97 // turn this into a test failure with | |
| 98 // ADD_FAILURE(). http://crbug.com/133403 | |
| 99 LOG(WARNING) << | |
| 100 "AtExitManager: items were added to the callback list by " << | 106 "AtExitManager: items were added to the callback list by " << |
| 101 test_info.test_case_name() << "." << test_info.name() << | 107 test_info.test_case_name() << "." << test_info.name() << |
| 102 ". Global state should be cleaned up before a test exits."; | 108 ". Global state should be cleaned up before a test exits."; |
| 103 } | 109 } |
| 104 } | 110 } |
| 105 | 111 |
| 106 private: | 112 private: |
| 107 AtExitManager* initial_top_manager_; | 113 AtExitManager* initial_top_manager_; |
| 114 scoped_ptr<base::AtExitManager> per_test_manager_; | |
| 108 size_t at_exit_stack_size_; | 115 size_t at_exit_stack_size_; |
| 109 | 116 |
| 110 DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager); | 117 DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager); |
| 111 }; | 118 }; |
| 112 | 119 |
| 113 } // namespace base | 120 } // namespace base |
| 114 | 121 |
| 115 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; | 122 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; |
| 116 | 123 |
| 117 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { | 124 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 !CommandLine::ForCurrentProcess()->HasSwitch( | 350 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 344 switches::kSingleProcessChromeFlag)) { | 351 switches::kSingleProcessChromeFlag)) { |
| 345 WatchAtExitManager(); | 352 WatchAtExitManager(); |
| 346 } | 353 } |
| 347 | 354 |
| 348 TestTimeouts::Initialize(); | 355 TestTimeouts::Initialize(); |
| 349 } | 356 } |
| 350 | 357 |
| 351 void TestSuite::Shutdown() { | 358 void TestSuite::Shutdown() { |
| 352 } | 359 } |
| OLD | NEW |